org.custommonkey.xmlunit.SimpleNamespaceContext Java Examples
The following examples show how to use
org.custommonkey.xmlunit.SimpleNamespaceContext.
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 |
@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: ResourceExtensionsTest.java From java-client-api with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeClass() throws IOException { Common.connectAdmin(); resourceServices = Common.testFileToString(XQUERY_FILE); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalize(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); Map<String,String> namespaces = new HashMap<>(); namespaces.put("rapi", "http://marklogic.com/rest-api"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces); xpather = XMLUnit.newXpathEngine(); xpather.setNamespaceContext(namespaceContext); }
Example #3
Source File: BufferableHandleTest.java From java-client-api with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeClass() { Common.connect(); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalize(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); Map<String,String> namespaces = new HashMap<>(); namespaces.put("rapi", "http://marklogic.com/rest-api"); namespaces.put("prop", "http://marklogic.com/xdmp/property"); namespaces.put("xs", "http://www.w3.org/2001/XMLSchema"); namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces); xpather = XMLUnit.newXpathEngine(); xpather.setNamespaceContext(namespaceContext); }
Example #4
Source File: StructuredQueryBuilderTest.java From java-client-api with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeClass() { XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalize(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); Map<String,String> namespaces = new HashMap<>(); namespaces.put("rapi", "http://marklogic.com/rest-api"); namespaces.put("prop", "http://marklogic.com/xdmp/property"); namespaces.put("xs", "http://www.w3.org/2001/XMLSchema"); namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); namespaces.put("search", "http://marklogic.com/appservices/search"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces); xpather = XMLUnit.newXpathEngine(); xpather.setNamespaceContext(namespaceContext); }
Example #5
Source File: HttpExceptionResponseTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@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 #6
Source File: HttpExceptionResponseTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void test404HttpNotFound() throws Exception { when(processor.readEntity(any(GetEntityUriInfo.class), any(String.class))).thenThrow( new ODataNotFoundException(ODataNotFoundException.ENTITY)); final HttpResponse response = executeGetRequest("Managers('199')"); assertEquals(HttpStatusCodes.NOT_FOUND.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); assertXpathValuesEqual("\"" + MessageService.getMessage(Locale.ENGLISH, ODataNotFoundException.ENTITY).getText() + "\"", "/a:error/a:message", content); }
Example #7
Source File: AtomServiceDocumentProducerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Before public void before() throws ODataException { Map<String, String> prefixMap = new HashMap<String, String>(); prefixMap.put("atom", Edm.NAMESPACE_ATOM_2005); prefixMap.put("a", Edm.NAMESPACE_APP_2007); prefixMap.put("xml", Edm.NAMESPACE_XML_1998); prefixMap.put("custom", "http://localhost"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap)); schemas = new ArrayList<Schema>(); EdmProvider edmProvider = mock(EdmProvider.class); when(edmProvider.getSchemas()).thenReturn(schemas); EdmServiceMetadata edmServiceMetadata = new EdmServiceMetadataImplProv(edmProvider); edm = mock(Edm.class); when(edm.getServiceMetadata()).thenReturn(edmServiceMetadata); }
Example #8
Source File: AtomEntryProducerTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@Test public void noneSyndicationKeepInContentFalseMustNotShowInProperties() throws Exception { //prepare Mock EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); EdmCustomizableFeedMappings employeeCustomPropertyMapping = mock(EdmCustomizableFeedMappings.class); when(employeeCustomPropertyMapping.isFcKeepInContent()).thenReturn(Boolean.FALSE); 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); assertXpathNotExists("/a:entry/m:properties/d:EmployeeName", xmlString); }
Example #9
Source File: Kramerius4ExportTest.java From proarc with GNU General Public License v3.0 | 6 votes |
@Before public void setUp() throws Exception { config = AppConfigurationFactory.getInstance().create(new HashMap<String, String>() {{ put(AppConfiguration.PROPERTY_APP_HOME, temp.getRoot().getPath()); }}); fedora = new FedoraTestSupport(); fedora.cleanUp(); MetaModelRepository.setInstance(config.getPlugins()); DigitalObjectManager.setDefault(new DigitalObjectManager( config, EasyMock.createNiceMock(ImportBatchManager.class), fedora.getRemoteStorage(), MetaModelRepository.getInstance(), EasyMock.createNiceMock(UserManager.class))); // check datastreams with xpath HashMap<String, String> namespaces = new HashMap<>(); namespaces.put("dc", DcConstants.NS_PURL); namespaces.put("f", "info:fedora/fedora-system:def/foxml#"); namespaces.put("kramerius", Kramerius4Export.KRAMERIUS_RELATION_NS); namespaces.put("mods", ModsStreamEditor.DATASTREAM_FORMAT_URI); namespaces.put("oai", Kramerius4Export.OAI_NS); namespaces.put("proarc-rels", Relations.PROARC_RELS_NS); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces)); }
Example #10
Source File: TransformersTest.java From proarc with GNU General Public License v3.0 | 6 votes |
/** * 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 #11
Source File: TransformersTest.java From proarc with GNU General Public License v3.0 | 6 votes |
/** * 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 #12
Source File: HttpExceptionResponseTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@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 #13
Source File: AtomServiceDocumentProducerTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@Before public void before() throws ODataException { Map<String, String> prefixMap = new HashMap<String, String>(); prefixMap.put("atom", Edm.NAMESPACE_ATOM_2005); prefixMap.put("a", Edm.NAMESPACE_APP_2007); prefixMap.put("xml", Edm.NAMESPACE_XML_1998); prefixMap.put("custom", "http://localhost"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap)); schemas = new ArrayList<Schema>(); EdmProvider edmProvider = mock(EdmProvider.class); when(edmProvider.getSchemas()).thenReturn(schemas); EdmServiceMetadata edmServiceMetadata = new EdmServiceMetadataImplProv(edmProvider); edm = mock(Edm.class); when(edm.getServiceMetadata()).thenReturn(edmServiceMetadata); }
Example #14
Source File: TransformersTest.java From proarc with GNU General Public License v3.0 | 6 votes |
/** * 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 #15
Source File: AtomEntryProducerTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@Test public void syndicationWithComplexProperty() 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 employeeLocationProperty = employeesSet.getEntityType().getProperty("Location"); when(((EdmProperty) employeeLocationProperty).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); assertXpathNotExists("/a:entry/customPre:Location", xmlString); assertXpathExists("/a:entry/m:properties/d:Location", xmlString); }
Example #16
Source File: TransformersTest.java From proarc with GNU General Public License v3.0 | 6 votes |
/** * Test mapping of 072#7 $x to {@code subject/topic} and $a/$9 to {@code classification}. * See issue 303. */ @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"); // System.out.println(xmlResult); 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); } }
Example #17
Source File: AtomEntryProducerTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@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 #18
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@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 #19
Source File: ServiceJsonTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void serviceDocumentAcceptHeaderInvalidCharset() throws Exception { final HttpResponse response = callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML + "; charset=iso-latin-1", HttpStatusCodes.NOT_ACCEPTABLE); final String body = getBody(response); Map<String, String> prefixMap = new HashMap<String, String>(); prefixMap.put("a", Edm.NAMESPACE_M_2007_08); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap)); assertXpathExists("/a:error", body); assertXpathExists("/a:error/a:code", body); assertXpathExists("/a:error/a:message", body); }
Example #20
Source File: AbstractRefXmlTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Before public void setXmlNamespacePrefixes() { Map<String, String> prefixMap = new HashMap<String, String>(); prefixMap.put(Edm.PREFIX_ATOM, Edm.NAMESPACE_ATOM_2005); prefixMap.put(Edm.PREFIX_APP, Edm.NAMESPACE_APP_2007); prefixMap.put(Edm.PREFIX_D, Edm.NAMESPACE_D_2007_08); prefixMap.put(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08); prefixMap.put(Edm.PREFIX_EDM, Edm.NAMESPACE_EDM_2008_09); prefixMap.put(Edm.PREFIX_EDMX, Edm.NAMESPACE_EDMX_2007_06); prefixMap.put(Edm.PREFIX_XML, Edm.NAMESPACE_XML_1998); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap)); }
Example #21
Source File: ExceptionsTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void exceptionBasicTest() throws Exception { final HttpResponse response = executeGetRequest("NoContainer.NoEntitySet()"); assertEquals(HttpStatusCodes.NOT_FOUND.getStatusCode(), response.getStatusLine().getStatusCode()); final String payload = 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", payload); assertXpathExists("/a:error/a:code", payload); assertXpathExists("/a:error/a:message[@xml:lang=\"en\"]", payload); }
Example #22
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void syndicationWithComplexProperty() 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 employeeLocationProperty = employeesSet.getEntityType().getProperty("Location"); when(((EdmProperty) employeeLocationProperty).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); assertXpathNotExists("/a:entry/customPre:Location", xmlString); assertXpathExists("/a:entry/m:properties/d:Location", xmlString); }
Example #23
Source File: ExceptionsTest.java From cloud-odata-java with Apache License 2.0 | 5 votes |
@Test public void exceptionBasicTest() throws Exception { final HttpResponse response = executeGetRequest("NoContainer.NoEntitySet()"); assertEquals(HttpStatusCodes.NOT_FOUND.getStatusCode(), response.getStatusLine().getStatusCode()); final String payload = 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", payload); assertXpathExists("/a:error/a:code", payload); assertXpathExists("/a:error/a:message[@xml:lang=\"en\"]", payload); }
Example #24
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void noneSyndicationWithNullUri() 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"); 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 #25
Source File: BasicProviderTest.java From cloud-odata-java with Apache License 2.0 | 5 votes |
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 #26
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@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 #27
Source File: AtomEntryProducerTest.java From cloud-odata-java with Apache License 2.0 | 5 votes |
@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(EntityProviderException.class, EntityProviderException.INVALID_NAMESPACE.getKey(), e); thrown = true; } if (!thrown) { fail("Exception should have been thrown"); } }
Example #28
Source File: AtomEntryProducerTest.java From cloud-odata-java with Apache License 2.0 | 5 votes |
@Test public void noneSyndicationWithNullUri() 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"); 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(EntityProviderException.class, EntityProviderException.INVALID_NAMESPACE.getKey(), e); thrown = true; } if (!thrown) { fail("Exception should have been thrown"); } }
Example #29
Source File: AbstractRefXmlTest.java From cloud-odata-java with Apache License 2.0 | 5 votes |
@Before public void setXmlNamespacePrefixes() { Map<String, String> prefixMap = new HashMap<String, String>(); prefixMap.put(Edm.PREFIX_ATOM, Edm.NAMESPACE_ATOM_2005); prefixMap.put(Edm.PREFIX_APP, Edm.NAMESPACE_APP_2007); prefixMap.put(Edm.PREFIX_D, Edm.NAMESPACE_D_2007_08); prefixMap.put(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08); prefixMap.put(Edm.PREFIX_EDM, Edm.NAMESPACE_EDM_2008_09); prefixMap.put(Edm.PREFIX_EDMX, Edm.NAMESPACE_EDMX_2007_06); prefixMap.put(Edm.PREFIX_XML, Edm.NAMESPACE_XML_1998); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap)); }
Example #30
Source File: HttpExceptionResponseTest.java From cloud-odata-java with Apache License 2.0 | 5 votes |
@Test public void test404HttpNotFound() throws Exception { when(processor.readEntity(any(GetEntityUriInfo.class), any(String.class))).thenThrow(new ODataNotFoundException(ODataNotFoundException.ENTITY)); final HttpResponse response = executeGetRequest("Managers('199')"); assertEquals(HttpStatusCodes.NOT_FOUND.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); assertXpathValuesEqual("\"" + MessageService.getMessage(Locale.ENGLISH, ODataNotFoundException.ENTITY).getText() + "\"", "/a:error/a:message", content); }