package StaxJaxBStreamParserImpl; import java.io.InputStream; import java.util.Iterator; import java.util.List; import org.apache.commons.collections.IteratorUtils; import org.fest.assertions.Assertions; import org.junit.BeforeClass; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.oxm.jaxb.Jaxb2Marshaller; import org.testng.annotations.Test; import pl.edu.icm.synat.logic.authors.orcid.parser.StaxJaxBStreamParserImpl; import pl.edu.icm.synat.logic.services.auhtors.orcid.model.OrcidProfile; import pl.edu.icm.synat.logic.services.auhtors.orcid.model.OrcidType; @Test public class StaxJaxBStreamParserTest { private static StaxJaxBStreamParserImpl parser = new StaxJaxBStreamParserImpl(); private static Resource simpleFile = new ClassPathResource("pl/edu/icm/synat/logic/services/authors/orcid/parser/simple.xml"); private static Resource complexFile = new ClassPathResource("pl/edu/icm/synat/logic/services/authors/orcid/parser/complex.xml"); @BeforeClass public static void initializeMarshaller() throws Exception{ Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); marshaller.setPackagesToScan(new String[]{"pl.edu.icm.synat.logic.services.auhtors.orcid.model"}); marshaller.afterPropertiesSet(); parser.setUnmarshaller(marshaller); } @SuppressWarnings("unchecked") public void shouldMultiProfileText() throws Throwable{ try(InputStream stream = simpleFile.getInputStream()){ Iterator profileIt = parser.parseProfiles(stream); List profiles = IteratorUtils.toList(profileIt); Assertions.assertThat(profiles).hasSize(4); } } @SuppressWarnings("unchecked") public void shouldParseComplexProfile() throws Throwable{ try(InputStream stream = complexFile.getInputStream()){ Iterator profileIt = parser.parseProfiles(stream); List profiles = IteratorUtils.toList(profileIt); Assertions.assertThat(profiles).hasSize(1); OrcidProfile profile = profiles.get(0); Assertions.assertThat(profile.getType()).isEqualTo(OrcidType.USER); Assertions.assertThat(profile.getOrcidBio().getPersonalDetails().getCreditName().getValue()).isEqualTo("M. Chichorro"); return; } } }