Transformers { public byte[] transformAsBytes(Source input, Format format) throws TransformerException { return transformAsBytes(input, format, Collections.<String, Object>emptyMap()); }  Source transform(Source input, Format format); Source transform(Source input, Format format, Map<String, Object> params); byte[] transformAsBytes(Source input, Format format); byte[] transformAsBytes(Source input, Format format, Map<String, Object> params); Source toSource(byte[] buffer); Source dump(Source source, StringBuilder dump); Source dump2Temp(Source source, String filename);  }
@Test public void testMarcAsMods() throws Exception { XMLUnit.setNormalizeWhitespace(true); InputStream goldenIS = TransformersTest.class.getResourceAsStream("alephXServerDetailResponseAsMods.xml"); assertNotNull(goldenIS); InputStream xmlIS = TransformersTest.class.getResourceAsStream("alephXServerDetailResponseAsMarcXml.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3); assertNotNull(contents); XMLAssert.assertXMLEqual(new InputSource(goldenIS), new InputSource(new ByteArrayInputStream(contents))); } finally { close(xmlIS); close(goldenIS); } }
@Test public void testMarcAsMods_Issue32() throws Exception { InputStream xmlIS = TransformersTest.class.getResourceAsStream("marc.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3); assertNotNull(contents); String xmlResult = new String(contents, "UTF-8"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{ put("m", ModsConstants.NS); }})); XMLAssert.assertXpathEvaluatesTo("HKA001", "/m:mods/m:location/m:physicalLocation[1]", xmlResult); XMLAssert.assertXpathEvaluatesTo("test sigla", "/m:mods/m:location/m:physicalLocation[2]", xmlResult); XMLAssert.assertXpathEvaluatesTo("2", "count(/m:mods/m:location/m:physicalLocation)", xmlResult); XMLAssert.assertXpathEvaluatesTo("54 487", "/m:mods/m:location/m:shelfLocator[1]", xmlResult); XMLAssert.assertXpathEvaluatesTo("test signatura", "/m:mods/m:location/m:shelfLocator[2]", xmlResult); XMLAssert.assertXpathEvaluatesTo("2", "count(/m:mods/m:location/m:shelfLocator)", xmlResult); validateMods(new StreamSource(new ByteArrayInputStream(contents))); } finally { close(xmlIS); } }
@Test public void testMarcAsMods_FrequencyAuthority_Issue181() throws Exception { InputStream xmlIS = TransformersTest.class.getResourceAsStream("frequencyAuthority.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3); assertNotNull(contents); String xmlResult = new String(contents, "UTF-8"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{ put("m", ModsConstants.NS); }})); XMLAssert.assertXpathNotExists("/m:mods/m:originInfo/m:frequency[1]/@authority", xmlResult); XMLAssert.assertXpathEvaluatesTo("2x ročně", "/m:mods/m:originInfo/m:frequency[1]", xmlResult); XMLAssert.assertXpathEvaluatesTo("marcfrequency", "/m:mods/m:originInfo/m:frequency[2]/@authority", xmlResult); XMLAssert.assertXpathEvaluatesTo("Semiannual", "/m:mods/m:originInfo/m:frequency[2]", xmlResult); validateMods(new StreamSource(new ByteArrayInputStream(contents))); } finally { close(xmlIS); } }
@Test public void testMarcAsMods_SubjectAuthority_Issue182() throws Exception { InputStream xmlIS = TransformersTest.class.getResourceAsStream("marc_subject_65X_X9.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3); assertNotNull(contents); String xmlResult = new String(contents, "UTF-8"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{ put("m", ModsConstants.NS); }})); XMLAssert.assertXpathExists("/m:mods/m:subject[@authority='czenas']/m:name[@type='personal']/m:namePart[text()='Novák, A. Jiří']", xmlResult); XMLAssert.assertXpathExists("/m:mods/m:subject[@authority='czenas']/m:topic[text()='daňové delikty']", xmlResult); XMLAssert.assertXpathExists("/m:mods/m:subject[@authority='eczenas']/m:topic[text()='tax delinquency']", xmlResult); XMLAssert.assertXpathExists("/m:mods/m:subject[@authority='czenas']/m:geographic[text()='Česko']", xmlResult); XMLAssert.assertXpathExists("/m:mods/m:subject[@authority='eczenas']/m:geographic[text()='Czechia']", xmlResult); validateMods(new StreamSource(new ByteArrayInputStream(contents))); } finally { close(xmlIS); } }
@Test public void testMarcAsMods_SubjectTopic_Issue185_Issue433() throws Exception { InputStream xmlIS = TransformersTest.class.getResourceAsStream("marc_subject_65X_X9.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3); assertNotNull(contents); String xmlResult = new String(contents, "UTF-8"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{ put("m", ModsConstants.NS); }})); XMLAssert.assertXpathExists("/m:mods/m:subject[not(@authority)]/m:topic[text()='kočky' and @lang='cze']", xmlResult); XMLAssert.assertXpathExists("/m:mods/m:subject[not(@authority)]/m:topic[text()='cats' and @lang='eng']", xmlResult); XMLAssert.assertXpathNotExists("/m:mods/m:subject/m:name/m:namePart[text()='kočky']", xmlResult); XMLAssert.assertXpathNotExists("/m:mods/m:subject/m:name/m:namePart[text()='cats']", xmlResult); validateMods(new StreamSource(new ByteArrayInputStream(contents))); } finally { close(xmlIS); } }
@Test public void testMarcAsMods_Conspectus_Issue303() throws Exception { InputStream xmlIS = TransformersTest.class.getResourceAsStream("marc.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3); assertNotNull(contents); String xmlResult = new String(contents, "UTF-8"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{ put("m", ModsConstants.NS); }})); XMLAssert.assertXpathEvaluatesTo("Umění", "/m:mods/m:subject[@authority='Konspekt']/m:topic", xmlResult); XMLAssert.assertXpathEvaluatesTo("7.01/.09", "/m:mods/m:classification[@authority='udc' and @edition='Konspekt']", xmlResult); XMLAssert.assertXpathEvaluatesTo("21", "/m:mods/m:classification[@authority='Konspekt']", xmlResult); validateMods(new StreamSource(new ByteArrayInputStream(contents))); } finally { close(xmlIS); } }
@Test public void testMarcAsMods_AuthorityId_Issue305() throws Exception { InputStream xmlIS = TransformersTest.class.getResourceAsStream("marc_subject_65X_X9.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3); assertNotNull(contents); String xmlResult = new String(contents, "UTF-8"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{ put("m", ModsConstants.NS); }})); XMLAssert.assertXpathExists("/m:mods/m:name[@type='personal'" + " and @authorityURI='http: + " and @valueURI='http: + "/m:namePart[@type='family' and text()='Kocina']" + "/../m:namePart[@type='given' and text()='Jan']" + "/../m:namePart[@type='date' and text()='1960-']" + "/../m:role/m:roleTerm[text()='aut']", xmlResult); XMLAssert.assertXpathExists("/m:mods/m:name[@type='personal'" + " and @authorityURI='http: + " and @valueURI='http: + "/m:namePart[@type='family' and text()='Honzík']" + "/../m:namePart[@type='given' and text()='Bohumil']" + "/../m:namePart[@type='date' and text()='1972-']" + "/../m:role/m:roleTerm[text()='aut']", xmlResult); XMLAssert.assertXpathExists("/m:mods/m:name[@type='personal'" + " and not(@authorityURI)" + " and not(@valueURI)]" + "/m:namePart[text()='Test Without AuthorityId']" + "/../m:namePart[@type='date' and text()='1972-']" + "/../m:role/m:roleTerm[text()='aut']", xmlResult); validateMods(new StreamSource(new ByteArrayInputStream(contents))); } finally { close(xmlIS); } }
@Test public void testMarcAsMods_RelatedItemPartDetailNumber_Issue306() throws Exception { InputStream xmlIS = TransformersTest.class.getResourceAsStream("marc_subject_65X_X9.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3); assertNotNull(contents); String xmlResult = new String(contents, "UTF-8"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{ put("m", ModsConstants.NS); }})); XMLAssert.assertXpathExists("/m:mods/m:relatedItem[@type='isReferencedBy']" + "/m:titleInfo/m:title[text()='Knihopis 1']", xmlResult); XMLAssert.assertXpathEvaluatesTo("K01416", "/m:mods/m:relatedItem[@type='isReferencedBy']" + "/m:titleInfo/m:title[text()='Knihopis 1']/../../m:part/m:detail[@type='part']/m:number", xmlResult); XMLAssert.assertXpathExists("/m:mods/m:relatedItem[@type='isReferencedBy']" + "/m:titleInfo/m:title[text()='Knihopis 2']", xmlResult); XMLAssert.assertXpathNotExists("/m:mods/m:relatedItem[@type='isReferencedBy']" + "/m:titleInfo/m:title[text()='Knihopis 2']/../../m:part", xmlResult); validateMods(new StreamSource(new ByteArrayInputStream(contents))); } finally { close(xmlIS); } }
@Test public void testMarcAsMods_RelatedItem_Issue313() throws Exception { InputStream xmlIS = TransformersTest.class.getResourceAsStream("marc_relatedItem_787.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3); assertNotNull(contents); String xmlResult = new String(contents, "UTF-8"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{ put("m", ModsConstants.NS); }})); XMLAssert.assertXpathEvaluatesTo( "Jak jsme zachraňovali svět aneb Půl století ve službách ochrany přírody", "/m:mods/m:relatedItem[not(@type) and @displayLabel='Recenze na:']" + "/m:titleInfo/m:title/text()", xmlResult); XMLAssert.assertXpathEvaluatesTo( "Čeřovský, Jan", "/m:mods/m:relatedItem[not(@type) and @displayLabel='Recenze na:']" + "/m:name/m:namePart/text()", xmlResult); XMLAssert.assertXpathEvaluatesTo( "Praha : Nakladatelství Academia, 2014", "/m:mods/m:relatedItem[not(@type) and @displayLabel='Recenze na:']" + "/m:originInfo/m:publisher/text()", xmlResult); validateMods(new StreamSource(new ByteArrayInputStream(contents))); } finally { close(xmlIS); } }
@Test public void testMarcAsMods_AbstractLang_Issue434() throws Exception { InputStream xmlIS = TransformersTest.class.getResourceAsStream("marc_subject_65X_X9.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3); assertNotNull(contents); String xmlResult = new String(contents, "UTF-8"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{ put("m", ModsConstants.NS); }})); XMLAssert.assertXpathExists("/m:mods/m:abstract[@lang='cze' and @type='Abstract' and text()='Text cze']", xmlResult); XMLAssert.assertXpathExists("/m:mods/m:abstract[@lang='eng' and @type='Abstract' and text()='Text eng']", xmlResult); XMLAssert.assertXpathExists("/m:mods/m:abstract[not(@lang) and @type='Abstract' and text()='Text no lang']", xmlResult); validateMods(new StreamSource(new ByteArrayInputStream(contents))); } finally { close(xmlIS); } }
@Test public void testMarcAsMods_Mapping264_ind4_Issue298() throws Exception{ InputStream xmlIS = TransformersTest.class.getResourceAsStream("marc_originInfo_264_ind4.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3); assertNotNull(contents); String xmlResult = new String(contents, "UTF-8"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{ put("m", ModsConstants.NS); }})); XMLAssert.assertXpathExists("/m:mods/m:originInfo[@eventType='copyright']", xmlResult); XMLAssert.assertXpathEvaluatesTo("Praha","/m:mods/m:originInfo[@eventType='copyright']/m:place/m:placeTerm", xmlResult); XMLAssert.assertXpathEvaluatesTo("Albatros","/m:mods/m:originInfo[@eventType='copyright']/m:publisher", xmlResult); XMLAssert.assertXpathEvaluatesTo("2015", "/m:mods/m:originInfo[@eventType='copyright']/m:copyrightDate", xmlResult); validateMods(new StreamSource(new ByteArrayInputStream(contents))); } finally { close(xmlIS); } }
@Test public void testOaiMarcAsMarc() throws Exception { InputStream goldenIS = TransformersTest.class.getResourceAsStream("alephXServerDetailResponseAsMarcXml.xml"); assertNotNull(goldenIS); InputStream xmlIS = TransformersTest.class.getResourceAsStream("alephXServerDetailResponseAsOaiMarc.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.OaimarcAsMarc21slim); assertNotNull(contents); XMLAssert.assertXMLEqual(new InputSource(goldenIS), new InputSource(new ByteArrayInputStream(contents))); } finally { close(xmlIS); close(goldenIS); } }
@Test public void testAlephXServerDetailNamespaceFix() throws Exception { InputStream goldenIS = TransformersTest.class.getResourceAsStream("alephXServerDetailResponseFixed.xml"); assertNotNull(goldenIS); InputStream xmlIS = TransformersTest.class.getResourceAsStream("../catalog/alephXServerDetailResponse.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.AlephOaiMarcFix); assertNotNull(contents); XMLAssert.assertXMLEqual(new InputSource(goldenIS), new InputSource(new ByteArrayInputStream(contents))); } finally { close(xmlIS); close(goldenIS); } }
@Test public void testModsAsHtml() throws Exception { InputStream xmlIS = TransformersTest.class.getResourceAsStream("alephXServerDetailResponseAsMods.xml"); assertNotNull(xmlIS); StreamSource streamSource = new StreamSource(xmlIS); Transformers mt = new Transformers(); Map<String, Object> params = ModsUtils.modsAsHtmlParameters(Locale.ENGLISH); try { byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.ModsAsHtml, params); assertNotNull(contents); } finally { close(xmlIS); } }