org.custommonkey.xmlunit.exceptions.XpathException Java Examples
The following examples show how to use
org.custommonkey.xmlunit.exceptions.XpathException.
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: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeWithValueEncoding() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { photoData.addProperty("Type", "< Ö >"); photoData.setWriteProperties(DEFAULT_PROPERTIES); AtomSerializerDeserializer ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getEntityContainer("Container2").getEntitySet("Photos"), photoData); String xmlString = verifyResponse(response); assertXpathExists("/a:entry", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString); assertXpathExists("/a:entry/a:id", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString() + "Container2.Photos(Id=1,Type='%3C%20%C3%96%20%3E')", "/a:entry/a:id/text()", xmlString); assertXpathEvaluatesTo("Container2.Photos(Id=1,Type='%3C%20%C3%96%20%3E')", "/a:entry/a:link/@href", xmlString); }
Example #2
Source File: AtomEntryProducerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeAtomEntry() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { final EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).build(); AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), roomData, properties); String xmlString = verifyResponse(response); assertXpathExists("/a:entry", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString); assertXpathExists("/a:entry/a:content", xmlString); assertXpathEvaluatesTo(ContentType.APPLICATION_XML.toString(), "/a:entry/a:content/@type", xmlString); assertXpathExists("/a:entry/a:content/m:properties", xmlString); }
Example #3
Source File: AtomEntryProducerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
/** * Test serialization of empty syndication title property. EmployeeName is set to NULL after the update (which is * allowed because EmployeeName has default Nullable behavior which is true). * Write of an empty atom title tag is allowed within RFC4287 (http://tools.ietf.org/html/rfc4287#section-4.2.14). */ @Test public void serializeEmployeeWithNullSyndicationTitleProperty() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomEntityProvider ser = createAtomEntityProvider(); EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).build(); employeeData.put("EmployeeName", null); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"), employeeData, properties); String xmlString = verifyResponse(response); assertXpathExists("/a:entry/a:title", xmlString); assertXpathEvaluatesTo("", "/a:entry/a:title", xmlString); assertXpathExists("/a:entry", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString); assertXpathExists("/a:entry/a:content", xmlString); assertXpathEvaluatesTo("Employees('1')/$value", "/a:entry/a:content/@src", xmlString); assertXpathExists("/a:entry/m:properties", xmlString); }
Example #4
Source File: TestDoublePrecisionGeoOps.java From java-client-api with Apache License 2.0 | 6 votes |
@Test public void testLinestringCrossesBox() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testLinestringCrossesBox"); QueryManager queryMgr = client.newQueryManager(); // create query def StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/linestring"), CoordinateSystem.WGS84DOUBLE), GeospatialOperator.CROSSES, qb.box(-5.45, -76.35643, 5.35, -54.636) ); // create handle JacksonHandle resultsHandle = new JacksonHandle(); queryMgr.search(t, resultsHandle); // get the result JsonNode resultNode = resultsHandle.get(); // Should have 2 nodes returned. assertEquals("Two nodes not returned from testPolygonCoversBox method ", 2, resultNode.path("total").asInt()); }
Example #5
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeAtomEntryWithEmptyEntity() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { final EntitySerializerProperties properties = EntitySerializerProperties.serviceRoot(BASE_URI).includeMetadata(false).build(); AtomSerializerDeserializer ser = createAtomEntityProvider(); Entity entity = new Entity(); entity.setWriteProperties(properties); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), entity); String xmlString = verifyResponse(response); assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString); assertXpathExists("/a:entry/a:content", xmlString); assertXpathEvaluatesTo(ContentType.APPLICATION_XML.toString(), "/a:entry/a:content/@type", xmlString); }
Example #6
Source File: XmlSelectProducerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private void verifySingleProperties(final String xmlString, final boolean employeeName, final boolean age, final boolean entryDate, final boolean imageUrl) throws IOException, SAXException, XpathException { if (employeeName) { assertXpathExists("/a:entry/m:properties/d:EmployeeName", xmlString); } else { assertXpathNotExists("/a:entry/m:properties/d:EmployeeName", xmlString); } if (age) { assertXpathExists("/a:entry/m:properties/d:Age", xmlString); } else { assertXpathNotExists("/a:entry/m:properties/d:Age", xmlString); } if (entryDate) { assertXpathExists("/a:entry/m:properties/d:EntryDate", xmlString); } else { assertXpathNotExists("/a:entry/m:properties/d:EntryDate", xmlString); } if (imageUrl) { assertXpathExists("/a:entry/m:properties/d:ImageUrl", xmlString); } else { assertXpathNotExists("/a:entry/m:properties/d:ImageUrl", xmlString); } }
Example #7
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeCustomMapping() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomSerializerDeserializer ser = createAtomEntityProvider(); photoData.setWriteProperties(DEFAULT_PROPERTIES); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getEntityContainer("Container2").getEntitySet("Photos"), photoData); String xmlString = verifyResponse(response); assertXpathExists("/a:entry", xmlString); assertXpathExists("/a:entry/custom:CustomProperty", xmlString); //assertXpathExists("/a:entry/ру:Содержание", xmlString); //TODO //assertXpathEvaluatesTo((String) photoData.getProperty("Содержание"), //"/a:entry/ру:Содержание/text()", xmlString); verifyTagOrdering(xmlString, "category", "Содержание", "content", "properties"); }
Example #8
Source File: AtomEntryProducerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test(expected = EntityProviderException.class) public void serializeAtomEntryWithEmptyHashMap() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { final EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).build(); AtomEntityProvider ser = createAtomEntityProvider(); ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), new HashMap<String, Object>(), properties); }
Example #9
Source File: TestBug18736.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testBug19389() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testBug19389"); DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // set error format to JSON ServerConfigurationManager srvMgr = client.newServerConfigManager(); // depricated // srvMgr.setErrorFormat(Format.JSON); srvMgr.writeConfiguration(); // create query options manager QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager(); // read non-existent query option StringHandle readHandle = new StringHandle(); readHandle.setFormat(Format.XML); String expectedException = "com.marklogic.client.ResourceNotFoundException: Could not get /config/query/NonExistentOpt"; String exception = ""; try { optionsMgr.readOptions("NonExistentOpt", readHandle); } catch (Exception e) { exception = e.toString(); } System.out.println(exception); assertTrue("Exception is not thrown", exception.contains(expectedException)); // release client client.release(); }
Example #10
Source File: TestBug18736.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testBug19140() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testBug19140"); DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // create query options manager QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager(); // create query options handle String xmlOptions = "<search:options xmlns:search='http://marklogic.com/appservices/search'>" + "<search:transform-results apply='raw'/>" + "</search:options>"; StringHandle handle = new StringHandle(xmlOptions); // write query options optionsMgr.writeOptions("RawResultsOpt", handle); // read query option StringHandle readHandle = new StringHandle(); readHandle.setFormat(Format.XML); optionsMgr.readOptions("RawResultsOpt", readHandle); String output = readHandle.get(); System.out.println(output); assertTrue("transform-results is incorrect", output.contains("transform-results apply=\"raw\"/")); assertFalse("preferred-elements is exist", output.contains("preferred-elements/")); // release client client.release(); }
Example #11
Source File: TestRawCombinedQueryGeo.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testRawCombinedQueryGeoPointAndWord() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testRawCombinedQueryGeoPointAndWord"); DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // write docs for (int i = 1; i <= 9; i++) { writeDocumentUsingInputStreamHandle(client, "geo-constraint" + i + ".xml", "/geo-constraint/", "XML"); } // get the combined query File file = new File("src/test/java/com/marklogic/client/functionaltest/combined/combinedQueryOptionGeoPointAndWord.xml"); // create a handle for the search criteria FileHandle rawHandle = new FileHandle(file); // bug 21107 QueryManager queryMgr = client.newQueryManager(); // create a search definition based on the handle RawCombinedQueryDefinition querydef = queryMgr.newRawCombinedQueryDefinition(rawHandle); // create result handle DOMHandle resultsHandle = new DOMHandle(); queryMgr.search(querydef, resultsHandle); // get the result Document resultDoc = resultsHandle.get(); System.out.println(convertXMLDocumentToString(resultDoc)); assertXpathEvaluatesTo("1", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc); assertXpathEvaluatesTo("/geo-constraint/geo-constraint8.xml", "string(//*[local-name()='result']//@*[local-name()='uri'])", resultDoc); // release client client.release(); }
Example #12
Source File: TestDocumentFormat.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testBinaryFormatOnBinary() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testBinaryFormatOnBinary"); String filename = "Pandakarlino.jpg"; String uri = "/bin-format-bin-file/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setFormat(Format.BINARY); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // release the client client.release(); }
Example #13
Source File: TestSearchMultibyte.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testSearchStringWithBucketAndWord() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testSearchStringWithBucketAndWord"); String[] filenames = { "multibyte1.xml", "multibyte2.xml", "multibyte3.xml" }; String queryOptionName = "multibyteSearchOpt.xml"; DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // write docs for (String filename : filenames) { writeDocumentUsingInputStreamHandle(client, filename, "/multibyte-search/", "XML"); } setQueryOption(client, queryOptionName); QueryManager queryMgr = client.newQueryManager(); // create query def StringQueryDefinition querydef = queryMgr.newStringDefinition(queryOptionName); querydef.setCriteria("mult-pop:medium AND mult-title:上海"); // create handle DOMHandle resultsHandle = new DOMHandle(); queryMgr.search(querydef, resultsHandle); // get the result Document resultDoc = resultsHandle.get(); assertXpathEvaluatesTo("1", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc); assertXpathEvaluatesTo("/multibyte-search/multibyte2.xml", "string(//*[local-name()='result']//@*[local-name()='uri'])", resultDoc); // release client client.release(); }
Example #14
Source File: TestBug18736.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testBug19046() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testBug19046"); DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // create query options manager QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager(); // read non-existent query option StringHandle readHandle = new StringHandle(); readHandle.setFormat(Format.XML); String expectedException = "com.marklogic.client.ResourceNotFoundException: Could not get /config/query/NonExistentOpt"; String exception = ""; try { optionsMgr.readOptions("NonExistentOpt", readHandle); } catch (Exception e) { exception = e.toString(); } System.out.println(exception); assertTrue("Exception is not thrown", exception.contains(expectedException)); // release client client.release(); }
Example #15
Source File: TestSearchMultibyte.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testSearchString() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testSearchString"); String[] filenames = { "multibyte1.xml", "multibyte2.xml", "multibyte3.xml" }; String queryOptionName = "multibyteSearchOpt.xml"; DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // write docs for (String filename : filenames) { writeDocumentUsingInputStreamHandle(client, filename, "/multibyte-search/", "XML"); } setQueryOption(client, queryOptionName); QueryManager queryMgr = client.newQueryManager(); // create query def StringQueryDefinition querydef = queryMgr.newStringDefinition(queryOptionName); querydef.setCriteria("mult-title:万里长城"); // create handle DOMHandle resultsHandle = new DOMHandle(); queryMgr.search(querydef, resultsHandle); // get the result Document resultDoc = resultsHandle.get(); assertXpathEvaluatesTo("1", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc); assertXpathEvaluatesTo("/multibyte-search/multibyte1.xml", "string(//*[local-name()='result']//@*[local-name()='uri'])", resultDoc); // release client client.release(); }
Example #16
Source File: AtomEntryProducerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void serializeIds() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getEntityContainer("Container2").getEntitySet("Photos"), photoData, DEFAULT_PROPERTIES); String xmlString = verifyResponse(response); assertXpathExists("/a:entry", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString); assertXpathExists("/a:entry/a:id", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString() + "Container2.Photos(Id=1,Type='image%2Fpng')", "/a:entry/a:id/text()", xmlString); }
Example #17
Source File: TestAppServicesGeoElementChildConstraint.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testBoxAndWord() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testPointAndWord"); String queryOptionName = "geoConstraintOpt.xml"; DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // write docs loadGeoData(); setQueryOption(client, queryOptionName); QueryManager queryMgr = client.newQueryManager(); // create query def StringQueryDefinition querydef = queryMgr.newStringDefinition(queryOptionName); querydef.setCriteria("geo-elem-child:\"[-12,-5,-11,-4]\" AND karl_kara"); // create handle DOMHandle resultsHandle = new DOMHandle(); queryMgr.search(querydef, resultsHandle); // get the result Document resultDoc = resultsHandle.get(); assertXpathEvaluatesTo("1", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc); assertXpathEvaluatesTo("/geo-constraint/geo-constraint2.xml", "string(//*[local-name()='result']//@*[local-name()='uri'])", resultDoc); // release client client.release(); }
Example #18
Source File: TestDoublePrecisionGeoOps.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testPolygonDisjointPolygon() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testPolygonDisjointPolygon"); QueryManager queryMgr = client.newQueryManager(); queryMgr.setPageLength(50); // create query def StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/polygon"), CoordinateSystem.WGS84), GeospatialOperator.DISJOINT, qb.polygon( qb.point(-90, 131), qb.point(-85, 133), qb.point(-87, 134), qb.point(-88, 135), qb.point(-90, 131)) ); // create handle JacksonHandle resultsHandlejh = new JacksonHandle(); queryMgr.search(t, resultsHandlejh); // get the result JsonNode resultNodejh = resultsHandlejh.get(); // Should have 20 nodes returned. assertEquals("Twenty nodes not returned from testPolygonCoversBox method ", 20, resultNodejh.path("total").asInt()); }
Example #19
Source File: TestAppServicesGeoAttrPairConstraint.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testCirclePositiveLatNegativeLang() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("testCirclePositiveLatNegativeLang"); String queryOptionName = "geoConstraintOpt.xml"; DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // write docs loadGeoData(); setQueryOption(client, queryOptionName); QueryManager queryMgr = client.newQueryManager(); // create query def StringQueryDefinition querydef = queryMgr.newStringDefinition(queryOptionName); querydef.setCriteria("geo-elem-child:\"@70 12,-5\""); // create handle DOMHandle resultsHandle = new DOMHandle(); queryMgr.search(querydef, resultsHandle); // get the result Document resultDoc = resultsHandle.get(); assertXpathEvaluatesTo("5", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc); assertXpathEvaluatesTo("karl_kara 12,-5 12,-5 12 -5", "string(//*[local-name()='result'][1]//*[local-name()='match'])", resultDoc); assertXpathEvaluatesTo("jack_kara 11,-5 11,-5 11 -5", "string(//*[local-name()='result'][2]//*[local-name()='match'])", resultDoc); assertXpathEvaluatesTo("karl_jill 12,-4 12,-4 12 -4", "string(//*[local-name()='result'][3]//*[local-name()='match'])", resultDoc); assertXpathEvaluatesTo("bill_kara 13,-5 13,-5 13 -5", "string(//*[local-name()='result'][4]//*[local-name()='match'])", resultDoc); assertXpathEvaluatesTo("karl_gale 12,-6 12,-6 12 -6", "string(//*[local-name()='result'][5]//*[local-name()='match'])", resultDoc); // release client client.release(); }
Example #20
Source File: TestQueryByExample.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testQueryByExampleXMLPermission() throws KeyManagementException, NoSuchAlgorithmException, IOException, TransformerException, XpathException { System.out.println("Running testQueryByExampleXMLPermission"); String[] filenames = { "constraint1.xml", "constraint2.xml", "constraint3.xml", "constraint4.xml", "constraint5.xml" }; DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // write docs for (String filename : filenames) { writeDocumentUsingInputStreamHandle(client, filename, "/qbe/", "XML"); } // get the combined query try { File file = new File("src/test/java/com/marklogic/client/functionaltest/qbe/qbe2.xml"); FileHandle fileHandle = new FileHandle(file); QueryManager queryMgr = client.newQueryManager(); RawQueryByExampleDefinition rw = queryMgr.newRawQueryByExampleDefinition(fileHandle.withFormat(Format.XML)); SearchHandle results = queryMgr.search(rw, new SearchHandle()); for (MatchDocumentSummary result : results.getMatchResults()) { System.out.println(result.getUri() + ": Uri"); assertEquals("Wrong Document Searched", result.getUri(), "/qbe/constraint1.xml"); } } catch (Exception e) { System.out.println("Negative Test Passed of executing nonreadable file"); } // release client client.release(); }
Example #21
Source File: XMLTestCase.java From xmlunit with Apache License 2.0 | 5 votes |
/** * Assert that the evaluation of two Xpaths in two documents are * NOT equal * @param controlXpath * @param testXpath * @param controlDocument * @param testDocument */ public void assertXpathValuesNotEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument) throws XpathException { XMLAssert.assertXpathValuesNotEqual(controlXpath, controlDocument, testXpath, testDocument); }
Example #22
Source File: XPathRegexAssert.java From xmlunit with Apache License 2.0 | 5 votes |
public static void assertXPathMatches(String message, String regex, String xpath, Document doc) throws XpathException { XpathEngine engine = XMLUnit.newXpathEngine(); String value = engine.evaluate(xpath, doc); Assert.assertTrue(message, value.matches(regex)); }
Example #23
Source File: TestAppServicesGeoElementConstraint.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testBoxPositiveLangLat() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("testBoxPositiveLangLat"); String queryOptionName = "geoConstraintOpt.xml"; DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // write docs for (int i = 1; i <= 7; i++) { writeDocumentUsingInputStreamHandle(client, "geo-constraint" + i + ".xml", "/geo-constraint/", "XML"); } setQueryOption(client, queryOptionName); QueryManager queryMgr = client.newQueryManager(); // create query def StringQueryDefinition querydef = queryMgr.newStringDefinition(queryOptionName); querydef.setCriteria("geo-elem:\"[11,4,12,5]\""); // create handle DOMHandle resultsHandle = new DOMHandle(); queryMgr.search(querydef, resultsHandle); // get the result Document resultDoc = resultsHandle.get(); assertXpathEvaluatesTo("4", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc); assertXpathEvaluatesTo("12,5", "string(//*[local-name()='result'][1]//*[local-name()='match'])", resultDoc); assertXpathEvaluatesTo("11,4", "string(//*[local-name()='result'][2]//*[local-name()='match'])", resultDoc); assertXpathEvaluatesTo("11,5", "string(//*[local-name()='result'][3]//*[local-name()='match'])", resultDoc); assertXpathEvaluatesTo("12,4", "string(//*[local-name()='result'][4]//*[local-name()='match'])", resultDoc); // release client client.release(); }
Example #24
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void serializeEmployeeAndCheckKeepInContentFalse() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomSerializerDeserializer ser = createAtomEntityProvider(); EntitySerializerProperties properties = EntitySerializerProperties.serviceRoot(BASE_URI).includeMetadata(true).build(); EdmEntitySet employeeEntitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); // set "keepInContent" to false for EntryDate EdmCustomizableFeedMappings employeeUpdatedMappings = mock(EdmCustomizableFeedMappings.class); when(employeeUpdatedMappings.getFcTargetPath()).thenReturn(EdmTargetPath.SYNDICATION_UPDATED); when(employeeUpdatedMappings.isFcKeepInContent()).thenReturn(Boolean.FALSE); EdmTyped employeeEntryDateProperty = employeeEntitySet.getEntityType().getProperty("EntryDate"); when(((EdmProperty) employeeEntryDateProperty).getCustomizableFeedMappings()).thenReturn(employeeUpdatedMappings); employeeData.setWriteProperties(properties); ODataResponse response = ser.writeEntry(employeeEntitySet, employeeData); String xmlString = verifyResponse(response); assertXpathExists("/a:entry", xmlString); assertXpathExists("/a:entry/a:content", xmlString); // verify properties assertXpathExists("/a:entry/m:properties", xmlString); assertXpathEvaluatesTo("7", "count(/a:entry/m:properties/*)", xmlString); // assertXpathNotExists("/a:entry/m:properties/d:EntryDate", xmlString); // verify order of tags List<String> expectedPropertyNamesFromEdm = new ArrayList<String>(employeeEntitySet.getEntityType().getPropertyNames()); expectedPropertyNamesFromEdm.remove(String.valueOf("EntryDate")); expectedPropertyNamesFromEdm.remove(String.valueOf("ImageUrl")); verifyTagOrdering(xmlString, expectedPropertyNamesFromEdm.toArray(new String[0])); }
Example #25
Source File: TestDoublePrecisionGeoOps.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testCircleContainsCircle() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testCircleContainsCircle"); QueryManager queryMgr = client.newQueryManager(); // create query def StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/circle"), CoordinateSystem.WGS84DOUBLE), GeospatialOperator.CONTAINS, qb.circle(qb.point(0, -66.09375), 6.897)); // create handle JacksonHandle resultsHandle = new JacksonHandle(); queryMgr.search(t, resultsHandle); // get the result JsonNode resultNode = resultsHandle.get(); JsonNode jsonPointNodes = resultNode.path("results"); // Should have 2 nodes returned. assertEquals("Two nodes not returned from testCircleContainsCircle method ", 2, resultNode.path("total").asInt()); assertTrue("URI returned from testCircleContainsCircle method is incorrect", jsonPointNodes.get(0).path("uri").asText().contains("/Equator-json.json") || jsonPointNodes.get(1).path("uri").asText().contains("/Equator-json.json")); assertTrue("URI returned from testCircleContainsCircle method is incorrect", jsonPointNodes.get(0).path("uri").asText().contains("/Equator.xml") || jsonPointNodes.get(1).path("uri").asText().contains("/Equator.xml")); }
Example #26
Source File: TestBug18736.java From java-client-api with Apache License 2.0 | 5 votes |
@Test public void testBug22037() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testBug22037"); String[] filenames = { "constraint1.xml", "constraint2.xml", "constraint3.xml", "constraint4.xml", "constraint5.xml" }; String queryOptionName = "rangeConstraintIntOpt.xml"; DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // write docs for (String filename : filenames) { writeDocumentUsingInputStreamHandle(client, filename, "/range-constraint/", "XML"); } setQueryOption(client, queryOptionName); QueryManager queryMgr = client.newQueryManager(); StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(queryOptionName); StructuredQueryDefinition rangeQuery = qb.range(qb.element("popularity"), "xs:int", Operator.GE, 4); // create handle DOMHandle resultsHandle = new DOMHandle(); queryMgr.search(rangeQuery, resultsHandle); // get the result Document resultDoc = resultsHandle.get(); // System.out.println(convertXMLDocumentToString(resultDoc)); assertXpathEvaluatesTo("4", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc); // release client client.release(); }
Example #27
Source File: TestRawCombinedQuery.java From java-client-api with Apache License 2.0 | 4 votes |
@Test public void test11RawCombinedQueryComboJSON() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testRawCombinedQueryComboJSON"); String filename1 = "constraint1.xml"; String filename2 = "constraint2.xml"; String filename3 = "constraint3.xml"; String filename4 = "constraint4.xml"; String filename5 = "constraint5.xml"; DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // create and initialize a handle on the metadata DocumentMetadataHandle metadataHandle1 = new DocumentMetadataHandle(); DocumentMetadataHandle metadataHandle2 = new DocumentMetadataHandle(); DocumentMetadataHandle metadataHandle3 = new DocumentMetadataHandle(); DocumentMetadataHandle metadataHandle4 = new DocumentMetadataHandle(); DocumentMetadataHandle metadataHandle5 = new DocumentMetadataHandle(); // set the metadata metadataHandle1.getCollections().addAll("http://test.com/set1"); metadataHandle1.getCollections().addAll("http://test.com/set5"); metadataHandle2.getCollections().addAll("http://test.com/set1"); metadataHandle3.getCollections().addAll("http://test.com/set3"); metadataHandle4.getCollections().addAll("http://test.com/set3/set3-1"); metadataHandle5.getCollections().addAll("http://test.com/set1"); metadataHandle5.getCollections().addAll("http://test.com/set5"); // write docs writeDocumentUsingInputStreamHandle(client, filename1, "/collection-constraint/", metadataHandle1, "XML"); writeDocumentUsingInputStreamHandle(client, filename2, "/collection-constraint/", metadataHandle2, "XML"); writeDocumentUsingInputStreamHandle(client, filename3, "/collection-constraint/", metadataHandle3, "XML"); writeDocumentUsingInputStreamHandle(client, filename4, "/collection-constraint/", metadataHandle4, "XML"); writeDocumentUsingInputStreamHandle(client, filename5, "/collection-constraint/", metadataHandle5, "XML"); // set query option validation to true ServerConfigurationManager srvMgr = client.newServerConfigManager(); srvMgr.readConfiguration(); srvMgr.setQueryOptionValidation(true); srvMgr.setQueryValidation(false); srvMgr.writeConfiguration(); // get the combined query File file = new File("src/test/java/com/marklogic/client/functionaltest/combined/combinedQueryOptionComboJSON.json"); String combinedQuery = convertFileToString(file); // create a handle for the search criteria StringHandle rawHandle = new StringHandle(combinedQuery); rawHandle.setFormat(Format.JSON); QueryManager queryMgr = client.newQueryManager(); // create a search definition based on the handle RawCombinedQueryDefinition querydef = queryMgr.newRawCombinedQueryDefinition(rawHandle); // create result handle StringHandle resultsHandle = new StringHandle(); queryMgr.search(querydef, resultsHandle); // get the result String resultDoc = resultsHandle.get(); System.out.println(resultDoc); assertTrue( "Returned result is not correct", resultDoc .contains("<search:result index=\"1\" uri=\"/collection-constraint/constraint1.xml\" path=\"fn:doc("/collection-constraint/constraint1.xml")\" score=\"28672\" confidence=\"0.6951694\" fitness=\"0.9213213\" href=\"/v1/documents?uri=%2Fcollection-constraint%2Fconstraint1.xml\" mimetype=\"application/xml\" format=\"xml\">")); // release client client.release(); }
Example #28
Source File: TestAggregates.java From java-client-api with Apache License 2.0 | 4 votes |
@Test public void testTuplesAggregates() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testTuplesAggregates"); String[] filenames = { "aggr1.xml", "aggr2.xml", "aggr3.xml", "aggr4.xml", "aggr5.xml" }; String queryOptionName = "aggregatesOpt.xml"; DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // write docs for (String filename : filenames) { writeDocumentUsingInputStreamHandle(client, filename, "/tuples-aggr/", "XML"); } setQueryOption(client, queryOptionName); QueryManager queryMgr = client.newQueryManager(); // create query def ValuesDefinition queryDef = queryMgr.newValuesDefinition("popularity", "aggregatesOpt.xml"); queryDef.setAggregate("correlation", "covariance"); queryDef.setName("pop-rate-tups"); // create handle TuplesHandle tuplesHandle = new TuplesHandle(); queryMgr.tuples(queryDef, tuplesHandle); AggregateResult[] agg = tuplesHandle.getAggregates(); System.out.println(agg.length); assertEquals("Invalid length", 2, agg.length); double correlation = agg[0].get("xs:double", Double.class); double covariance = agg[1].get("xs:double", Double.class); DecimalFormat df = new DecimalFormat("###.##"); String roundedCorrelation = df.format(correlation); String roundedCovariance = df.format(covariance); System.out.println(roundedCorrelation); System.out.println(roundedCovariance); assertEquals("Invalid correlation", "0.26", roundedCorrelation); assertEquals("Invalid covariance", "0.35", roundedCovariance); // release client client.release(); }
Example #29
Source File: TestSandBox.java From java-client-api with Apache License 2.0 | 4 votes |
@Test public void testQueryByExampleXML() throws KeyManagementException, NoSuchAlgorithmException, IOException, TransformerException, XpathException { System.out.println("Running testQueryByExampleXML"); String[] filenames = { "constraint1.xml", "constraint2.xml", "constraint3.xml", "constraint4.xml", "constraint5.xml" }; DatabaseClient client = null; try { client = getDatabaseClient("rest-writer", "x", getConnType()); // write docs for (String filename : filenames) { writeDocumentUsingInputStreamHandle(client, filename, "/qbe/", "XML"); } // get the combined query File file = new File("src/test/java/com/marklogic/client/functionaltest/qbe/qbe1.xml"); String qbeQuery = convertFileToString(file); StringHandle qbeHandle = new StringHandle(qbeQuery); qbeHandle.setFormat(Format.XML); QueryManager queryMgr = client.newQueryManager(); RawQueryByExampleDefinition qbyex = queryMgr.newRawQueryByExampleDefinition(qbeHandle); Document resultDoc = queryMgr.search(qbyex, new DOMHandle()).get(); System.out.println("XML Result" + convertXMLDocumentToString(resultDoc)); assertXpathEvaluatesTo("1", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc); assertXpathEvaluatesTo("0011", "string(//*[local-name()='result'][1]//*[local-name()='id'])", resultDoc); } catch(Exception ex) { System.out.println("Exceptions" + ex.getStackTrace()); } finally { client.release(); } }
Example #30
Source File: TestSearchOnJSON.java From java-client-api with Apache License 2.0 | 4 votes |
@Test public void testRoundtrippingQueryOption() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testRoundtrippingQueryOption"); String queryOptionName = "valueConstraintWildCardOpt.xml"; DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // create a manager for writing query options QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager(); // create handle ReaderHandle handle = new ReaderHandle(); // write the files BufferedReader docStream = new BufferedReader(new FileReader("src/test/java/com/marklogic/client/functionaltest/queryoptions/" + queryOptionName)); handle.set(docStream); // write the query options to the database optionsMgr.writeOptions(queryOptionName, handle); System.out.println("Write " + queryOptionName + " to database"); // read query option StringHandle readHandle = new StringHandle(); readHandle.setFormat(Format.JSON); optionsMgr.readOptions(queryOptionName, readHandle); String output = readHandle.get(); System.out.println(output); String expectedOutput = "{\"options\":{\"return-metrics\":false, \"return-qtext\":false, \"debug\":true, \"transform-results\":{\"apply\":\"raw\"}, \"constraint\":[{\"name\":\"id\", \"value\":{\"element\":{\"ns\":\"\", \"name\":\"id\"}}}]}}"; assertEquals("query option in JSON is difference", expectedOutput, output.trim()); // create handle to write back option in json String queryOptionNameJson = queryOptionName.replaceAll(".xml", ".json"); StringHandle writeHandle = new StringHandle(); writeHandle.set(output); writeHandle.setFormat(Format.JSON); optionsMgr.writeOptions(queryOptionNameJson, writeHandle); System.out.println("Write " + queryOptionNameJson + " to database"); // release client client.release(); }