Java Code Examples for org.custommonkey.xmlunit.XMLAssert#assertXpathExists()

The following examples show how to use org.custommonkey.xmlunit.XMLAssert#assertXpathExists() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DcStreamEditorTest.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testWriteMods() throws Exception {
    LocalStorage storage = new LocalStorage();
    LocalStorage.LocalObject local = storage.create();
    ModsStreamEditor modsEditor = new ModsStreamEditor(local);
    ModsDefinition mods = modsEditor.createPage(local.getPid(), "1", "[1]", "pageType");
    String model = "model:page";
    long timestamp = 0L;
    DcStreamEditor instance = new DcStreamEditor(local);
    instance.write(mods, model, timestamp, null);
    local.flush();

    DublinCoreRecord result = instance.read();
    assertNotNull(result);
    assertNotNull(result.getDc());
    assertEquals(local.getPid(), result.getPid());

    HashMap<String, String> namespaces = new HashMap<String, String>();
    namespaces.put("oai_dc", DcStreamEditor.DATASTREAM_FORMAT_URI);
    namespaces.put("dc", "http://purl.org/dc/elements/1.1/");
    XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
    String toXml = DcUtils.toXml(result.getDc(), true);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:title[text()='[1]']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='" + local.getPid() +"']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:type[text()='" + model +"']", toXml);
}
 
Example 2
Source File: TransformersTest.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
/**
     * Tests mapping of field 653 indicator_9 $a to {@code subject/topic@lang}.
     * See issue 185.
     * See issue 433.
     */
    @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");
//            System.out.println(xmlResult);
            XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{
                put("m", ModsConstants.NS);
            }}));
            // 653
            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);
        }
    }
 
Example 3
Source File: TransformersTest.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
/**
     * Tests mapping of field 520 and subfield $9 to {@code abstract@lang}.
     * See issue 434.
     */
    @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");
//            System.out.println(xmlResult);
            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);
        }
    }
 
Example 4
Source File: TransformersTest.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
/**
     * Tests mapping of field 264_4 to {@code originInfo}.
     * See issue 298.
     */
    @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");
//            System.out.println(xmlResult);
            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);
        }
    }
 
Example 5
Source File: DcStreamEditorTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testTransformation() throws Exception {
    ModsDefinition mods = ModsUtils.unmarshalModsType(new StreamSource(DcStreamEditorTest.class.getResource("periodical.xml").toExternalForm()));
    Transformer t = DcUtils.modsTransformer("model:periodical");
    JAXBSource jaxbSource = new JAXBSource(ModsUtils.defaultMarshaller(false),
            new ObjectFactory().createMods(mods));
    StringWriter dump = new StringWriter();
    t.transform(jaxbSource, new StreamResult(dump));
    String toXml = dump.toString();
    System.out.println(toXml);

    HashMap<String, String> namespaces = new HashMap<String, String>();
    namespaces.put("oai_dc", DcStreamEditor.DATASTREAM_FORMAT_URI);
    namespaces.put("dc", "http://purl.org/dc/elements/1.1/");
    XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:title[text()='main']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:title[text()='key']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:title[text()='alternative']", toXml);
    XMLAssert.assertXpathEvaluatesTo("3", "count(/oai_dc:dc/dc:title)", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:creator[text()='Boleslav']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:description[text()='poznámka']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='uuid:40d13cb2-811f-468c-a6d3-1ad6b01f06f7']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='isbn:0eaa6730']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='issn-l:idIssn-l']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='idWitEmptyType']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='idWithoutType']", toXml);
    // XXX needs more test
}
 
Example 6
Source File: OaiCatalogTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testOaiResponseTransformation() throws Exception {
    OaiCatalog c = new OaiCatalog("", "");
    String srcUrl = OaiCatalogTest.class.getResource("oaiResponse.xml").toExternalForm();
    StreamResult result = c.transformOaiResponse(new StreamSource(srcUrl), new StreamResult(new StringWriter()));
    assertNotNull(result);

    HashMap<String, String> namespaces = new HashMap<String, String>();
    namespaces.put("marc", "http://www.loc.gov/MARC21/slim");
    XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
    String marc = result.getWriter().toString();
    XMLAssert.assertXpathExists("/marc:record", marc);
}
 
Example 7
Source File: TransformersTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
/**
     * Tests mapping of fields 600, 610, 611, 630, 648, 650, 651 indicator_9 $2 to {@code subject@authority}.
     * See issue 182.
     */
    @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");
//            System.out.println(xmlResult);
            XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{
                put("m", ModsConstants.NS);
            }}));
            // 600
            XMLAssert.assertXpathExists("/m:mods/m:subject[@authority='czenas']/m:name[@type='personal']/m:namePart[text()='Novák, A. Jiří']", xmlResult);
            // 650
            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);
            // 651
            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);
        }
    }
 
Example 8
Source File: TransformersTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
/**
     * Tests mapping of field 510 $c to {@code part/detail/number}.
     * See issue 306.
     */
    @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");
//            System.out.println(xmlResult);
            XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{
                put("m", ModsConstants.NS);
            }}));
            // test 510 4# $a Knihopis 1 $c K01416
            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);

            // test 510 0# $a Knihopis 2
            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);
        }
    }
 
Example 9
Source File: EntryXmlReadOnlyTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void entryMediaResource() throws Exception {
  HttpResponse response = callUri("Employees('2')/$value");
  checkMediaType(response, IMAGE_JPEG);
  assertNotNull(getBody(response));

  response = callUri("Employees('2')/$value?$format=xml", HttpStatusCodes.BAD_REQUEST);
  String body = getBody(response);
  XMLAssert.assertXpathExists("/m:error/m:message", body);
}
 
Example 10
Source File: EntryXmlReadOnlyTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
@Test
public void entryMediaResource() throws Exception {
  HttpResponse response = callUri("Employees('2')/$value");
  checkMediaType(response, IMAGE_JPEG);
  assertNotNull(getBody(response));

  response = callUri("Employees('2')/$value?$format=xml", HttpStatusCodes.BAD_REQUEST);
  String body = getBody(response);
  XMLAssert.assertXpathExists("/m:error/m:message", body);
}
 
Example 11
Source File: TransformersTest.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
/**
     * Tests mapping of field 100,700 $7 to {@code name@authorityURI} and {@code name@valueURI}.
     * See issue 305.
     */
    @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");
//            System.out.println(xmlResult);
            XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{
                put("m", ModsConstants.NS);
            }}));
            // test 100 1# $a Kocina, Jan, $d 1960- $4 aut $7 xx0113245
            XMLAssert.assertXpathExists("/m:mods/m:name[@type='personal'"
                        + " and @authorityURI='http://aut.nkp.cz'"
                        + " and @valueURI='http://aut.nkp.cz/xx0113245']"
                    + "/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);
            // test 700 1# $a Honzík, Bohumil, $d 1972- $4 aut $7 jn20020422016
            XMLAssert.assertXpathExists("/m:mods/m:name[@type='personal'"
                        + " and @authorityURI='http://aut.nkp.cz'"
                        + " and @valueURI='http://aut.nkp.cz/jn20020422016']"
                    + "/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);
            // test 700 1# $a Test Without AuthorityId $d 1972- $4 aut
            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);
        }
    }
 
Example 12
Source File: Kramerius4ExportTest.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
/**
 * integration test
 */
@Test
public void testExport() throws Exception {
    fedora.ingest(Kramerius4ExportTest.class.getResource("Kramerius4ExportTestPage.xml"));
    File output = temp.getRoot();
    boolean hierarchy = true;
    String[] pids = {"uuid:f74f3cf3-f3be-4cac-95da-8e50331414a2"};
    RemoteStorage storage = fedora.getRemoteStorage();
    Kramerius4Export instance = new Kramerius4Export(storage, config);
    File target = instance.export(output, hierarchy, "export status", pids);
    assertNotNull(target);

    // check datastreams with xpath
    File foxml = ExportUtils.pidAsXmlFile(target, pids[0]);
    String foxmlSystemId = foxml.toURI().toASCIIString();
    XMLAssert.assertXpathExists(streamXPath(ModsStreamEditor.DATASTREAM_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(DcStreamEditor.DATASTREAM_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(StringEditor.OCR_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(RelationEditor.DATASTREAM_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath("IMG_FULL"), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath("IMG_PREVIEW"), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath("IMG_THUMB"), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathNotExists(streamXPath(BinaryEditor.RAW_ID), new InputSource(foxmlSystemId));

    // check OAI ID
    XMLAssert.assertXpathExists("//oai:itemID", new InputSource(foxmlSystemId));
    // check kramerius:file
    XMLAssert.assertXpathExists("//kramerius:file", new InputSource(foxmlSystemId));
    // check exclusion of proarc-rels:hasDevice
    XMLAssert.assertXpathNotExists("//proarc-rels:hasDevice", new InputSource(foxmlSystemId));
    // check MODS starts with modsCollection
    XMLAssert.assertXpathExists(streamXPath(ModsStreamEditor.DATASTREAM_ID) + "//f:xmlContent/mods:modsCollection/mods:mods", new InputSource(foxmlSystemId));
    // check policy
    XMLAssert.assertXpathEvaluatesTo("policy:private", streamXPath(DcStreamEditor.DATASTREAM_ID) + "//dc:rights", new InputSource(foxmlSystemId));
    XMLAssert.assertXpathEvaluatesTo("policy:private", streamXPath(RelationEditor.DATASTREAM_ID) + "//kramerius:policy", new InputSource(foxmlSystemId));

    // test export status
    RelationEditor relationEditor = new RelationEditor(storage.find(pids[0]));
    assertNotNull(relationEditor.getExportResult());

    // test ingest of exported object
    fedora.cleanUp();
    fedora.ingest(foxml.toURI().toURL());
}
 
Example 13
Source File: TiffImporterTest.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testConsume() throws Exception {
    temp.setDeleteOnExit(true);
    File targetFolder = ImportProcess.createTargetFolder(temp.getRoot(), config.getImportConfiguration());
    assertTrue(targetFolder.exists());

    String mimetype = ImportProcess.findMimeType(tiff1);
    assertNotNull(mimetype);

    ImportOptions ctx = new ImportOptions(tiff1.getParentFile(),
            "scanner:scanner1", true, junit, config.getImportConfiguration());
    ctx.setTargetFolder(targetFolder);
    Batch batch = new Batch();
    batch.setId(1);
    batch.setFolder(ibm.relativizeBatchFile(tiff1.getParentFile()));
    ctx.setBatch(batch);
    FileSet fileSet = ImportFileScanner.getFileSets(Arrays.asList(tiff1, ocr1, alto1, ac1, uc1)).get(0);
    ctx.setJhoveContext(jhoveContext);

    TiffImporter instance = new TiffImporter(ibm);
    BatchItemObject result = instance.consume(fileSet, ctx);
    String pid = result.getPid();
    assertTrue(pid.startsWith("uuid"));

    assertEquals(ObjectState.LOADED, result.getState());
    
    File foxml = result.getFile();
    assertTrue(foxml.toString(), foxml.exists());

    File rootFoxml = new File(foxml.getParent(), ImportBatchManager.ROOT_ITEM_FILENAME);
    assertTrue(rootFoxml.toString(), rootFoxml.exists());

    File raw1 = new File(targetFolder, "img1.full.jpg");
    assertTrue(raw1.exists() && raw1.length() > 0);

    File preview1 = new File(targetFolder, "img1.preview.jpg");
    assertTrue(preview1.exists() && preview1.length() > 0);

    File thumb1 = new File(targetFolder, "img1.thumb.jpg");
    assertTrue(thumb1.exists() && thumb1.length() > 0);

    // validate FOXML
    SchemaFactory sfactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    URL foxmlXsdUrl = ObjectFactory.class.getResource("/xsd/foxml/foxml1-1.xsd");
    assertNotNull(foxmlXsdUrl);
    Schema foxmlXsd = sfactory.newSchema(foxmlXsdUrl);
    foxmlXsd.newValidator().validate(new StreamSource(foxml));

    // check datastreams with xpath
    HashMap<String, String> namespaces = new HashMap<String, String>();
    namespaces.put("f", "info:fedora/fedora-system:def/foxml#");
    XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
    String foxmlSystemId = foxml.toURI().toASCIIString();
    XMLAssert.assertXpathExists(streamXPath(ModsStreamEditor.DATASTREAM_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(DcStreamEditor.DATASTREAM_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(StringEditor.OCR_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(AltoDatastream.ALTO_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(RelationEditor.DATASTREAM_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(BinaryEditor.FULL_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(BinaryEditor.PREVIEW_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(BinaryEditor.THUMB_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(BinaryEditor.RAW_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(MixEditor.RAW_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(BinaryEditor.NDK_ARCHIVAL_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(BinaryEditor.NDK_USER_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(MixEditor.NDK_ARCHIVAL_ID), new InputSource(foxmlSystemId));

    String rootSystemId = rootFoxml.toURI().toASCIIString();
    XMLAssert.assertXpathExists(streamXPath(RelationEditor.DATASTREAM_ID), new InputSource(rootSystemId));
    EasyMock.verify(toVerify.toArray());
}
 
Example 14
Source File: WaveImporterTest.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
@Test
    public void testConsume() throws IOException, SAXException, XpathException {
        temp.setDeleteOnExit(true);
        File targetFolder = ImportProcess.createTargetFolder(temp.getRoot(), config.getImportConfiguration());
        assertTrue(targetFolder.exists());

        String mimetype = ImportProcess.findMimeType(ac1);
        assertNotNull(mimetype);

        ImportOptions ctx = new ImportOptions(ac1.getParentFile(), "scanner:scanner1",
                true, junit, config.getImportConfiguration());
        ctx.setTargetFolder(targetFolder);
        Batch batch = new Batch();
        batch.setId(1);
        batch.setFolder(ibm.relativizeBatchFile(ac1.getParentFile()));
        ctx.setBatch(batch);
        assertNotNull(ac1);

        FileSet fileSet = ImportFileScanner.getFileSets(Arrays.asList(ac1, uc1)).get(0);
        ctx.setJhoveContext(jhoveContext);

        WaveImporter waveImporter = new WaveImporter(ibm);
        BatchItemObject result = waveImporter.consume(fileSet, ctx);

        String pid = result.getPid();
        assertTrue(pid.startsWith("uuid"));

        assertEquals(ObjectState.LOADED, result.getState());

        File foxml = result.getFile();
        assertTrue(foxml.toString(), foxml.exists());

        File rootFoxml = new File(foxml.getParent(), ImportBatchManager.ROOT_ITEM_FILENAME);
        assertTrue(rootFoxml.toString(), rootFoxml.exists());
/*
        File preview1 = new File(targetFolder, "audio1.preview.jpg");
        assertTrue(preview1.exists() && preview1.length() > 0);

        File thumb = new File(targetFolder, "audio1.thumb.jpg");
        assertTrue(thumb.exists() && thumb.length() > 0);

        File raw = new File(targetFolder, "audio1.full.jpg");
        assertTrue(raw.exists() && raw.length() > 0);
*/
        SchemaFactory sfactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        URL foxmlXsdUrl = ObjectFactory.class.getResource("/xsd/foxml/foxml1-1.xsd");
        assertNotNull(foxmlXsdUrl);
        Schema foxmlXsd = sfactory.newSchema(foxmlXsdUrl);
        foxmlXsd.newValidator().validate(new StreamSource(foxml));

        // check datastreams with xpath
        HashMap<String, String> namespaces = new HashMap<String, String>();
        namespaces.put("f", "info:fedora/fedora-system:def/foxml#");
        XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
        String foxmlSystemId = foxml.toURI().toASCIIString();
        XMLAssert.assertXpathExists(streamXPath(ModsStreamEditor.DATASTREAM_ID), new InputSource(foxmlSystemId));
        XMLAssert.assertXpathExists(streamXPath(DcStreamEditor.DATASTREAM_ID), new InputSource(foxmlSystemId));
        XMLAssert.assertXpathExists(streamXPath(RelationEditor.DATASTREAM_ID), new InputSource(foxmlSystemId));
        XMLAssert.assertXpathExists(streamXPath(BinaryEditor.FULL_ID), new InputSource(foxmlSystemId));
        //XMLAssert.assertXpathExists(streamXPath(BinaryEditor.PREVIEW_ID), new InputSource(foxmlSystemId));
        //MLAssert.assertXpathExists(streamXPath(BinaryEditor.THUMB_ID), new InputSource(foxmlSystemId));
        XMLAssert.assertXpathExists(streamXPath(BinaryEditor.RAW_AUDIO_ID), new InputSource(foxmlSystemId));
        //XMLAssert.assertXpathExists(streamXPath(Aes57Editor.RAW_ID), new InputSource(foxmlSystemId));
        XMLAssert.assertXpathExists(streamXPath(BinaryEditor.NDK_AUDIO_ARCHIVAL_ID), new InputSource(foxmlSystemId));
        XMLAssert.assertXpathExists(streamXPath(BinaryEditor.NDK_AUDIO_USER_ID), new InputSource(foxmlSystemId));
        //XMLAssert.assertXpathExists(streamXPath(Aes57Editor.NDK_ARCHIVAL_ID), new InputSource(foxmlSystemId));

        String rootSystemId = rootFoxml.toURI().toASCIIString();
        XMLAssert.assertXpathExists(streamXPath(RelationEditor.DATASTREAM_ID), new InputSource(rootSystemId));
        EasyMock.verify(toVerify.toArray());
    }
 
Example 15
Source File: EspiMarshallerTests.java    From OpenESPI-Common-java with Apache License 2.0 4 votes vote down vote up
@Test
public void marshal_with_marshallableObject_returnsValidXml()
		throws Exception {
	XMLAssert.assertXpathExists("espi:UsagePoint",
			EspiMarshaller.marshal(newUsagePoint()));
}