Java Code Examples for org.custommonkey.xmlunit.XMLUnit#setXpathNamespaceContext()

The following examples show how to use org.custommonkey.xmlunit.XMLUnit#setXpathNamespaceContext() . 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 fields 310a and 008/18 to {@code frequency@authority}.
     * See issue 118 and 181.
     */
    @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");
//            System.out.println(xmlResult);
            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);
        }
    }
 
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 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 4
Source File: HttpExceptionResponseTest.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
@Test
public void genericHttpExceptions() throws Exception {
  disableLogging();

  final List<ODataHttpException> toTestExceptions = getHttpExceptionsForTest();

  int firstKey = 1;
  for (final ODataHttpException oDataException : toTestExceptions) {
    final String key = String.valueOf(firstKey++);
    final Matcher<GetEntityUriInfo> match = new EntityKeyMatcher(key);
    when(processor.readEntity(Matchers.argThat(match), any(String.class))).thenThrow(oDataException);

    final HttpResponse response = executeGetRequest("Managers('" + key + "')");

    assertEquals("Expected status code does not match for exception type '" + oDataException.getClass().getSimpleName() + "'.",
        oDataException.getHttpStatus().getStatusCode(), response.getStatusLine().getStatusCode());

    final String content = StringHelper.inputStreamToString(response.getEntity().getContent());
    Map<String, String> prefixMap = new HashMap<String, String>();
    prefixMap.put("a", Edm.NAMESPACE_M_2007_08);
    XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));
    assertXpathExists("/a:error/a:code", content);
  }

}
 
Example 5
Source File: AtomEntryProducerTest.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
@Test
public void noneSyndicationKeepInContentTrueMustShowInProperties() throws Exception {
  //prepare Mock
  EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  EdmCustomizableFeedMappings employeeCustomPropertyMapping = mock(EdmCustomizableFeedMappings.class);
  when(employeeCustomPropertyMapping.isFcKeepInContent()).thenReturn(Boolean.TRUE);
  when(employeeCustomPropertyMapping.getFcNsPrefix()).thenReturn("customPre");
  when(employeeCustomPropertyMapping.getFcNsUri()).thenReturn("http://customUri.com");
  EdmTyped employeeEntryDateProperty = employeesSet.getEntityType().getProperty("EmployeeName");
  when(((EdmProperty) employeeEntryDateProperty).getCustomizableFeedMappings()).thenReturn(employeeCustomPropertyMapping);

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("a", Edm.NAMESPACE_ATOM_2005);
  prefixMap.put("d", Edm.NAMESPACE_D_2007_08);
  prefixMap.put("m", Edm.NAMESPACE_M_2007_08);
  prefixMap.put("xml", Edm.NAMESPACE_XML_1998);
  prefixMap.put("customPre", "http://customUri.com");
  XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));

  AtomEntityProvider ser = createAtomEntityProvider();
  ODataResponse response = ser.writeEntry(employeesSet, employeeData, DEFAULT_PROPERTIES);
  String xmlString = verifyResponse(response);

  assertXpathExists("/a:entry/customPre:EmployeeName", xmlString);
  assertXpathExists("/a:entry/m:properties/d:EmployeeName", xmlString);
}
 
Example 6
Source File: EdmServiceMetadataImplProvTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {
  EdmImplProv edmImplProv = new EdmImplProv(new EdmTestProvider());
  EdmServiceMetadata serviceMetadata = edmImplProv.getServiceMetadata();
  metadata = StringHelper.inputStreamToString(serviceMetadata.getMetadata());
  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("a", Edm.NAMESPACE_EDM_2008_09);
  prefixMap.put("edmx", Edm.NAMESPACE_EDMX_2007_06);
  prefixMap.put("m", Edm.NAMESPACE_M_2007_08);
  prefixMap.put("annoPrefix", "http://annoNamespace");

  XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));
}
 
Example 7
Source File: XmlMetadataProducerTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
@Test
public void writeValidMetadata3() throws Exception {
  List<Schema> schemas = new ArrayList<Schema>();

  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  annotationElements.add(new AnnotationElement().setName("test").setText("hallo)"));
  Schema schema = new Schema().setAnnotationElements(annotationElements);
  schema.setNamespace("http://namespace.com");
  schemas.add(schema);

  List<PropertyRef> keys = new ArrayList<PropertyRef>();
  keys.add(new PropertyRef().setName("Id"));
  Key key = new Key().setKeys(keys);
  List<Property> properties = new ArrayList<Property>();
  properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.String));
  EntityType entityType = new EntityType().setName("testType").setKey(key).setProperties(properties);
  List<EntityType> entityTypes = new ArrayList<EntityType>();
  entityTypes.add(entityType);
  schema.setEntityTypes(entityTypes);

  DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
  OutputStreamWriter writer = null;
  CircleStreamBuffer csb = new CircleStreamBuffer();
  writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
  XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
  XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
  prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");

  NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
  XMLUnit.setXpathNamespaceContext(ctx);

  String metadata = StringHelper.inputStreamToString(csb.getInputStream());
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:test", metadata);
}
 
Example 8
Source File: XmlMetadataProducerTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
@Test
public void writeValidMetadata4() throws Exception {

  List<Schema> schemas = new ArrayList<Schema>();

  List<AnnotationAttribute> attributesElement1 = new ArrayList<AnnotationAttribute>();
  attributesElement1.add(new AnnotationAttribute().setName("rel").setText("self"));
  attributesElement1.add(new AnnotationAttribute().setName("href").setText("link"));

  List<AnnotationElement> schemaElements = new ArrayList<AnnotationElement>();
  schemaElements.add(new AnnotationElement().setName("schemaElementTest1").setPrefix("atom").setNamespace("http://www.w3.org/2005/Atom").setAttributes(attributesElement1));
  schemaElements.add(new AnnotationElement().setName("schemaElementTest2").setPrefix("atom").setNamespace("http://www.w3.org/2005/Atom").setAttributes(attributesElement1));

  Schema schema = new Schema().setAnnotationElements(schemaElements);
  schema.setNamespace("http://namespace.com");
  schemas.add(schema);

  DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
  OutputStreamWriter writer = null;
  CircleStreamBuffer csb = new CircleStreamBuffer();
  writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
  XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
  XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);
  String metadata = StringHelper.inputStreamToString(csb.getInputStream());

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
  prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
  prefixMap.put("atom", "http://www.w3.org/2005/Atom");

  NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
  XMLUnit.setXpathNamespaceContext(ctx);

  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest1", metadata);
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest2", metadata);
}
 
Example 9
Source File: AtomEntryProducerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void noneSyndicationWithNullPrefix() throws Exception {
  // prepare Mock
  EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  EdmCustomizableFeedMappings employeeCustomPropertyMapping = mock(EdmCustomizableFeedMappings.class);
  when(employeeCustomPropertyMapping.isFcKeepInContent()).thenReturn(Boolean.TRUE);
  when(employeeCustomPropertyMapping.getFcNsUri()).thenReturn("http://customUri.com");
  EdmTyped employeeEntryDateProperty = employeesSet.getEntityType().getProperty("EmployeeName");
  when(((EdmProperty) employeeEntryDateProperty).getCustomizableFeedMappings()).thenReturn(
      employeeCustomPropertyMapping);

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("a", Edm.NAMESPACE_ATOM_2005);
  prefixMap.put("d", Edm.NAMESPACE_D_2007_08);
  prefixMap.put("m", Edm.NAMESPACE_M_2007_08);
  prefixMap.put("xml", Edm.NAMESPACE_XML_1998);
  prefixMap.put("customPre", "http://customUri.com");
  XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));

  AtomEntityProvider ser = createAtomEntityProvider();
  boolean thrown = false;
  try {
    ser.writeEntry(employeesSet, employeeData, DEFAULT_PROPERTIES);
  } catch (EntityProviderException e) {
    verifyRootCause(EntityProviderProducerException.class, EntityProviderException.INVALID_NAMESPACE.getKey(), e);
    thrown = true;
  }
  if (!thrown) {
    fail("Exception should have been thrown");
  }
}
 
Example 10
Source File: LanguageNegotiationTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
@Before
public void before() {
  super.before();

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("m", Edm.NAMESPACE_M_2007_08);
  XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));

  disableLogging();
}
 
Example 11
Source File: AtomEntrySerializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void noneSyndicationWithNullUriAndNullPrefix() throws Exception {
  // prepare Mock
  EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  EdmCustomizableFeedMappings employeeCustomPropertyMapping = mock(EdmCustomizableFeedMappings.class);
  when(employeeCustomPropertyMapping.isFcKeepInContent()).thenReturn(Boolean.TRUE);
  EdmTyped employeeEntryDateProperty = employeesSet.getEntityType().getProperty("EmployeeName");
  when(((EdmProperty) employeeEntryDateProperty).getCustomizableFeedMappings()).thenReturn(
      employeeCustomPropertyMapping);

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("a", Edm.NAMESPACE_ATOM_2005);
  prefixMap.put("d", Edm.NAMESPACE_D_2007_08);
  prefixMap.put("m", Edm.NAMESPACE_M_2007_08);
  prefixMap.put("xml", Edm.NAMESPACE_XML_1998);
  prefixMap.put("f", "http://customUri.com");
  XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));

  AtomSerializerDeserializer ser = createAtomEntityProvider();
  employeeData.setWriteProperties(DEFAULT_PROPERTIES);
  boolean thrown = false;
  try {
    ser.writeEntry(employeesSet, employeeData);
  } catch (EntityProviderException e) {
    verifyRootCause(EntityProviderProducerException.class, EntityProviderException.INVALID_NAMESPACE.getKey(), e);
    thrown = true;
  }
  if (!thrown) {
    fail("Exception should have been thrown");
  }
}
 
Example 12
Source File: BasicProviderTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
private void setNamespaces() {
  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("edmx", Edm.NAMESPACE_EDMX_2007_06);
  prefixMap.put("m", Edm.NAMESPACE_M_2007_08);
  prefixMap.put("a", Edm.NAMESPACE_EDM_2008_09);
  prefixMap.put("annoPrefix", "http://annoNamespace");
  prefixMap.put("prefix", "namespace");
  prefixMap.put("b", "RefScenario");
  prefixMap.put("pre", "namespaceForAnno");
  XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));
}
 
Example 13
Source File: AtomEntrySerializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void noneSyndicationWithNullPrefix() throws Exception {
  // prepare Mock
  EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  EdmCustomizableFeedMappings employeeCustomPropertyMapping = mock(EdmCustomizableFeedMappings.class);
  when(employeeCustomPropertyMapping.isFcKeepInContent()).thenReturn(Boolean.TRUE);
  when(employeeCustomPropertyMapping.getFcNsUri()).thenReturn("http://customUri.com");
  EdmTyped employeeEntryDateProperty = employeesSet.getEntityType().getProperty("EmployeeName");
  when(((EdmProperty) employeeEntryDateProperty).getCustomizableFeedMappings()).thenReturn(
      employeeCustomPropertyMapping);

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("a", Edm.NAMESPACE_ATOM_2005);
  prefixMap.put("d", Edm.NAMESPACE_D_2007_08);
  prefixMap.put("m", Edm.NAMESPACE_M_2007_08);
  prefixMap.put("xml", Edm.NAMESPACE_XML_1998);
  prefixMap.put("customPre", "http://customUri.com");
  XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));

  AtomSerializerDeserializer ser = createAtomEntityProvider();
  employeeData.setWriteProperties(DEFAULT_PROPERTIES);
  boolean thrown = false;
  try {
    ser.writeEntry(employeesSet, employeeData);
  } catch (EntityProviderException e) {
    verifyRootCause(EntityProviderProducerException.class, EntityProviderException.INVALID_NAMESPACE.getKey(), e);
    thrown = true;
  }
  if (!thrown) {
    fail("Exception should have been thrown");
  }
}
 
Example 14
Source File: AtomEntrySerializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void noneSyndicationKeepInContentTrueMustShowInProperties() throws Exception {
  // prepare Mock
  EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  EdmCustomizableFeedMappings employeeCustomPropertyMapping = mock(EdmCustomizableFeedMappings.class);
  when(employeeCustomPropertyMapping.isFcKeepInContent()).thenReturn(Boolean.TRUE);
  when(employeeCustomPropertyMapping.getFcNsPrefix()).thenReturn("customPre");
  when(employeeCustomPropertyMapping.getFcNsUri()).thenReturn("http://customUri.com");
  EdmTyped employeeEntryDateProperty = employeesSet.getEntityType().getProperty("EmployeeName");
  when(((EdmProperty) employeeEntryDateProperty).getCustomizableFeedMappings()).thenReturn(
      employeeCustomPropertyMapping);

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("a", Edm.NAMESPACE_ATOM_2005);
  prefixMap.put("d", Edm.NAMESPACE_D_2007_08);
  prefixMap.put("m", Edm.NAMESPACE_M_2007_08);
  prefixMap.put("xml", Edm.NAMESPACE_XML_1998);
  prefixMap.put("customPre", "http://customUri.com");
  XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));
  employeeData.setWriteProperties(DEFAULT_PROPERTIES);

  AtomSerializerDeserializer ser = createAtomEntityProvider();
  ODataResponse response = ser.writeEntry(employeesSet, employeeData);
  String xmlString = verifyResponse(response);

  assertXpathExists("/a:entry/customPre:EmployeeName", xmlString);
  assertXpathExists("/a:entry/m:properties/d:EmployeeName", xmlString);
}
 
Example 15
Source File: AbstractProviderTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
@Before
public void setXmlNamespacePrefixes() throws Exception {
  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("a", Edm.NAMESPACE_ATOM_2005);
  prefixMap.put("d", Edm.NAMESPACE_D_2007_08);
  prefixMap.put("m", Edm.NAMESPACE_M_2007_08);
  prefixMap.put("xml", Edm.NAMESPACE_XML_1998);
  prefixMap.put("ру", "http://localhost");
  prefixMap.put("custom", "http://localhost");
  prefixMap.put("at", TombstoneCallback.NAMESPACE_TOMBSTONE);
  XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));
}
 
Example 16
Source File: TestUtils.java    From OpenESPI-Common-java with Apache License 2.0 4 votes vote down vote up
public static void setupXMLUnit() {

		XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(
				namespaces()));
	}
 
Example 17
Source File: XmlMetadataProducerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void writeValidMetadata6() throws Exception {

  List<Schema> schemas = new ArrayList<Schema>();

  List<AnnotationAttribute> attributesElement1 = new ArrayList<AnnotationAttribute>();
  attributesElement1.add(new AnnotationAttribute().setName("rel").setText("self").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom"));
  attributesElement1.add(new AnnotationAttribute().setName("href").setText("link").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom"));

  List<AnnotationElement> elementElements = new ArrayList<AnnotationElement>();
  elementElements.add(new AnnotationElement().setName("schemaElementTest2").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom").setAttributes(attributesElement1));
  elementElements.add(new AnnotationElement().setName("schemaElementTest3").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom").setAttributes(attributesElement1));

  List<AnnotationElement> schemaElements = new ArrayList<AnnotationElement>();
  schemaElements.add(new AnnotationElement().setName("schemaElementTest1").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom").setAttributes(attributesElement1).setChildElements(elementElements));

  Schema schema = new Schema().setAnnotationElements(schemaElements);
  schema.setNamespace("http://namespace.com");
  schemas.add(schema);

  DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
  OutputStreamWriter writer = null;
  CircleStreamBuffer csb = new CircleStreamBuffer();
  writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
  XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
  XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);
  String metadata = StringHelper.inputStreamToString(csb.getInputStream());

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
  prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
  prefixMap.put("atom", "http://www.w3.org/2005/Atom");

  NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
  XMLUnit.setXpathNamespaceContext(ctx);

  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest1", metadata);
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest1/atom:schemaElementTest2",
      metadata);
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest1/atom:schemaElementTest3",
      metadata);
}
 
Example 18
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 19
Source File: ODataExceptionMapperImplTest.java    From cloud-odata-java with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {
  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("a", Edm.NAMESPACE_M_2007_08);
  XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));
}
 
Example 20
Source File: XmlMetadataProducerTest.java    From cloud-odata-java with Apache License 2.0 4 votes vote down vote up
@Test
public void writeValidMetadata2() throws Exception {
  List<Schema> schemas = new ArrayList<Schema>();

  List<AnnotationElement> childElements = new ArrayList<AnnotationElement>();
  childElements.add(new AnnotationElement().setName("schemaElementTest2").setText("text2").setNamespace("namespace1"));

  List<AnnotationAttribute> elementAttributes = new ArrayList<AnnotationAttribute>();
  elementAttributes.add(new AnnotationAttribute().setName("rel").setText("self"));
  elementAttributes.add(new AnnotationAttribute().setName("href").setText("http://google.com").setPrefix("pre").setNamespace("namespaceForAnno"));

  List<AnnotationElement> element3List = new ArrayList<AnnotationElement>();
  element3List.add(new AnnotationElement().setName("schemaElementTest4").setText("text4").setAttributes(elementAttributes));
  childElements.add(new AnnotationElement().setName("schemaElementTest3").setText("text3").setPrefix("prefix").setNamespace("namespace2").setChildElements(element3List));

  List<AnnotationElement> schemaElements = new ArrayList<AnnotationElement>();
  schemaElements.add(new AnnotationElement().setName("schemaElementTest1").setText("text1").setChildElements(childElements));

  schemaElements.add(new AnnotationElement().setName("test"));
  Schema schema = new Schema().setAnnotationElements(schemaElements);
  schema.setNamespace("http://namespace.com");
  schemas.add(schema);

  DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
  OutputStreamWriter writer = null;
  CircleStreamBuffer csb = new CircleStreamBuffer();
  writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
  XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
  XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
  prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
  prefixMap.put("b", "namespace1");
  prefixMap.put("prefix", "namespace2");
  prefixMap.put("pre", "namespaceForAnno");

  NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
  XMLUnit.setXpathNamespaceContext(ctx);

  String metadata = StringHelper.inputStreamToString(csb.getInputStream());
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:test", metadata);
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:schemaElementTest1", metadata);
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:schemaElementTest1/b:schemaElementTest2", metadata);
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:schemaElementTest1/prefix:schemaElementTest3", metadata);
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:schemaElementTest1/prefix:schemaElementTest3/a:schemaElementTest4[@rel=\"self\" and @pre:href=\"http://google.com\"]", metadata);

}