@Test public void testValidatePost() throws Exception { String request = getResourceAsString("GetRecordsValidate.xml"); Document d = postAsDOM("csw", request); checkValidationErrors(d, new CSWConfiguration()); // print(d); XpathEngine xpath = XMLUnit.newXpathEngine(); String timeStamp = xpath.evaluate("/csw:Acknowledgement/@timeStamp", d); assertGMLTimestamp(timeStamp); assertXpathEvaluatesTo("*lorem*", "/csw:Acknowledgement/csw:EchoedRequest/csw:GetRecords/csw:Query/" + "csw:Constraint/ogc:Filter/ogc:PropertyIsLike/ogc:Literal", d); }
@Test public void testTitleFilter() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&resultType=results&elementSetName=brief&constraint=dc:title like '%25ipsum%25'"; Document d = getAsDOM(request); print(d); assertIpsumRecords(d); }
/** * From CITE compliance, throw an error if a non spatial property is used in a spatial filter * @throws Exception */ @Test public void testSpatialFilterNonGeomProperty() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&resultType=results" + "&elementName=dc:identifier,ows:BoundingBox&constraint=BBOX(dct:spatial, 47.0, -4.5, 52.0, 1.0)"; Document d = getAsDOM(request); // print(d); checkOws10Exception(d); }
@Test public void testUnqualifiedTitleFilter() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&resultType=results&elementSetName=brief&constraint=title like '%25ipsum%25'"; Document d = getAsDOM(request); // print(d); assertIpsumRecords(d); }
@Test public void testEmptyResult() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&resultType=results&constraint=dc:title = 'foo'"; Document d = getAsDOM(request); checkValidationErrors(d, new CSWConfiguration()); // print(d); assertXpathEvaluatesTo("summary", "//csw:SearchResults/@elementSet", d); assertXpathEvaluatesTo("0", "//csw:SearchResults/@numberOfRecordsMatched", d); assertXpathEvaluatesTo("0", "//csw:SearchResults/@numberOfRecordsReturned", d); assertXpathEvaluatesTo("0", "//csw:SearchResults/@nextRecord", d); }
@Test public void testValidateGet() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&resultType=validate"; Document d = getAsDOM(request); checkValidationErrors(d, new CSWConfiguration()); // print(d); XpathEngine xpath = XMLUnit.newXpathEngine(); assertXpathEvaluatesTo("http://localhost:8080/geoserver/" + request, "/csw:Acknowledgement/csw:EchoedRequest/ows:Get/@xlink:href", d); String timeStamp = xpath.evaluate("/csw:Acknowledgement/@timeStamp", d); assertGMLTimestamp(timeStamp); }
@Test public void testFilterBBox() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&resultType=results" + "&elementName=dc:identifier,ows:BoundingBox&constraint=BBOX(ows:BoundingBox, 47.0, -4.5, 52.0, 1.0)"; Document d = getAsDOM(request); checkValidationErrors(d, new CSWConfiguration()); print(d); // basic checks assertXpathEvaluatesTo("full", "//csw:SearchResults/@elementSet", d); assertXpathEvaluatesTo("2", "//csw:SearchResults/@numberOfRecordsMatched", d); assertXpathEvaluatesTo("2", "//csw:SearchResults/@numberOfRecordsReturned", d); assertXpathEvaluatesTo("0", "//csw:SearchResults/@nextRecord", d); assertXpathEvaluatesTo("2", "count(//csw:SearchResults/*)", d); // verify we got the expected records assertXpathEvaluatesTo("1", "count(//csw:Record[dc:identifier='urn:uuid:9a669547-b69b-469f-a11f-2d875366bbdc'])", d); assertXpathEvaluatesTo("1", "count(//csw:Record[dc:identifier='urn:uuid:94bc9c83-97f6-4b40-9eb8-a8e8787a5c63'])", d); }
reader.setApplicationContext(applicationContext); Object request = reader.createRequest(); GetRecordsType gr = (GetRecordsType) reader.read(request, parseKvp(raw), raw);
@Test public void testXMLReaderParameter() throws Exception { CSWXmlReader reader = new CSWXmlReader("GetRecords", "2.0.2", new CSWConfiguration()); GetRecordsType gr = (GetRecordsType) reader.read(null, getResourceAsReader("GetRecordsBrief.xml"), (Map) null); // check the attributes assertEquals("application/xml", gr.getOutputFormat()); assertEquals("urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0", gr.getOutputSchema()); // the query QueryType query = (QueryType) gr.getQuery(); List<QName> expected = new ArrayList<QName>(); String rimNamespace = "urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0"; expected.add(new QName(rimNamespace, "Service")); expected.add(new QName(rimNamespace, "Classification")); expected.add(new QName(rimNamespace, "Association")); assertEquals(expected, query.getTypeNames()); // the element set name ElementSetNameType esn = query.getElementSetName(); expected.clear(); expected.add(new QName(rimNamespace, "Service")); assertEquals(expected, esn.getTypeNames()); assertEquals(ElementSetType.BRIEF, esn.getValue()); }
private void assertIpsumRecords(Document d) throws Exception { checkValidationErrors(d, new CSWConfiguration()); // basic checks assertXpathEvaluatesTo("brief", "//csw:SearchResults/@elementSet", d); assertXpathEvaluatesTo("2", "//csw:SearchResults/@numberOfRecordsMatched", d); assertXpathEvaluatesTo("2", "//csw:SearchResults/@numberOfRecordsReturned", d); assertXpathEvaluatesTo("0", "//csw:SearchResults/@nextRecord", d); assertXpathEvaluatesTo("2", "count(//csw:SearchResults/*)", d); // verify we got the records we expected assertXpathEvaluatesTo("1", "count(//csw:BriefRecord[dc:identifier='urn:uuid:19887a8a-f6b0-4a63-ae56-7fba0e17801f'])", d); assertXpathEvaluatesTo("1", "count(//csw:BriefRecord[dc:identifier='urn:uuid:a06af396-3105-442d-8b40-22b57a90d2f2'])", d); }
@Test public void testAllRecordsBrief() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&resultType=results&elementSetName=brief"; Document d = getAsDOM(request, "ISO-8859-1"); checkValidationErrors(d, new CSWConfiguration()); // check we have the expected results assertXpathEvaluatesTo("brief", "//csw:SearchResults/@elementSet", d); assertXpathEvaluatesTo("12", "//csw:SearchResults/@numberOfRecordsMatched", d); assertXpathEvaluatesTo("10", "//csw:SearchResults/@numberOfRecordsReturned", d); assertXpathEvaluatesTo("11", "//csw:SearchResults/@nextRecord", d); // check we 10 summary records (max records defaults to 10) assertXpathEvaluatesTo("10", "count(//csw:SearchResults/csw:BriefRecord)", d); }
@Test public void testHitRequest() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record"; Document d = getAsDOM(request); checkValidationErrors(d, new CSWConfiguration()); // print(d); // we have the right kind of document assertXpathEvaluatesTo("1", "count(/csw:GetRecordsResponse)", d); XpathEngine xpath = XMLUnit.newXpathEngine(); // check we have a timestamp that is a valid XML date, and it's GMT (we don't // test parts of the date since we are bound to fail even the year if the test is run // across midnight of String timestampPath = "/csw:GetRecordsResponse/csw:SearchStatus/@timestamp"; String timeStamp = xpath.evaluate(timestampPath, d); assertGMLTimestamp(timeStamp); // check we have the expected results assertXpathEvaluatesTo("summary", "//csw:SearchResults/@elementSet", d); assertXpathEvaluatesTo("12", "//csw:SearchResults/@numberOfRecordsMatched", d); assertXpathEvaluatesTo("0", "//csw:SearchResults/@numberOfRecordsReturned", d); assertXpathEvaluatesTo("11", "//csw:SearchResults/@nextRecord", d); // check we have no results assertXpathEvaluatesTo("0", "count(//csw:SearchResults/*)", d); }
reader.setApplicationContext(applicationContext); Object request = reader.createRequest(); GetRecordsType gr = (GetRecordsType) reader.read(request, parseKvp(raw), raw);
@Test public void testAllRecordsFull() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&resultType=results&elementSetName=full"; Document d = getAsDOM(request, "ISO-8859-1"); checkValidationErrors(d, new CSWConfiguration()); // check we have the expected results assertXpathEvaluatesTo("full", "//csw:SearchResults/@elementSet", d); assertXpathEvaluatesTo("12", "//csw:SearchResults/@numberOfRecordsMatched", d); assertXpathEvaluatesTo("10", "//csw:SearchResults/@numberOfRecordsReturned", d); assertXpathEvaluatesTo("11", "//csw:SearchResults/@nextRecord", d); // check we 10 summary records (max records defaults to 10) assertXpathEvaluatesTo("10", "count(//csw:SearchResults/csw:Record)", d); }
@Test public void testInvalidOutputSchema() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&outputSchema=http://www.geoserver.org"; Document d = getAsDOM(request); // print(d); checkOws10Exception(d, ServiceException.INVALID_PARAMETER_VALUE, "outputSchema"); }
@Test public void testAllRecordsDefaultElementSet() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&resultType=results"; Document d = getAsDOM(request, "ISO-8859-1"); // print(d); checkValidationErrors(d, new CSWConfiguration()); // check we have the expected results assertXpathEvaluatesTo("summary", "//csw:SearchResults/@elementSet", d); assertXpathEvaluatesTo("12", "//csw:SearchResults/@numberOfRecordsMatched", d); assertXpathEvaluatesTo("10", "//csw:SearchResults/@numberOfRecordsReturned", d); assertXpathEvaluatesTo("11", "//csw:SearchResults/@nextRecord", d); // check we 10 summary records (max records defaults to 10) assertXpathEvaluatesTo("10", "count(//csw:SearchResults/csw:SummaryRecord)", d); }
/** * From CITE compliance, throw an error the output format is not supported * @throws Exception */ @Test public void testUnsupportedOutputFormat() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&outputFormat=application/xhtml+xml"; Document d = getAsDOM(request); // print(d); checkOws10Exception(d, ServiceException.INVALID_PARAMETER_VALUE, "outputFormat"); }
@Test public void testSortByDateSelectElements() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&resultType=results" + "&elementName=dc:identifier,dc:type,dc:date&sortBy=dc:date:A"; Document d = getAsDOM(request); checkValidationErrors(d, new CSWConfiguration()); // print(d); // basic checks assertXpathEvaluatesTo("full", "//csw:SearchResults/@elementSet", d); assertXpathEvaluatesTo("12", "//csw:SearchResults/@numberOfRecordsMatched", d); assertXpathEvaluatesTo("10", "//csw:SearchResults/@numberOfRecordsReturned", d); assertXpathEvaluatesTo("11", "//csw:SearchResults/@nextRecord", d); assertXpathEvaluatesTo("10", "count(//csw:SearchResults/*)", d); // extract the identifiers and verify they are sorted List<String> dates = new ArrayList<String>(); XpathEngine xpath = XMLUnit.newXpathEngine(); for (int i = 1; i < 11; i++) { String id = xpath.evaluate("//csw:Record[" + i + "]/dc:date", d); dates.add(id); } List<String> sorted = new ArrayList<String>(dates); Collections.sort(sorted); assertEquals(sorted, dates); }
@Test public void testInvalidStartPosition() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&startPosition=0"; Document d = getAsDOM(request); // print(d); checkOws10Exception(d, ServiceException.INVALID_PARAMETER_VALUE, "startPosition"); }
@Test public void testSortByIdentifier() throws Exception { String request = "csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=csw:Record&resultType=results&elementSetName=brief&sortBy=dc:identifier:A"; Document d = getAsDOM(request, "ISO-8859-1"); checkValidationErrors(d, new CSWConfiguration()); // print(d); // basic checks assertXpathEvaluatesTo("brief", "//csw:SearchResults/@elementSet", d); assertXpathEvaluatesTo("12", "//csw:SearchResults/@numberOfRecordsMatched", d); assertXpathEvaluatesTo("10", "//csw:SearchResults/@numberOfRecordsReturned", d); assertXpathEvaluatesTo("11", "//csw:SearchResults/@nextRecord", d); assertXpathEvaluatesTo("10", "count(//csw:SearchResults/*)", d); // extract the identifiers and verify they are sorted List<String> identifiers = new ArrayList<String>(); XpathEngine xpath = XMLUnit.newXpathEngine(); for (int i = 1; i < 11; i++) { String id = xpath.evaluate("//csw:SummaryRecord[" + i + "]/dc:identifier", d); identifiers.add(id); } List<String> sorted = new ArrayList<String>(identifiers); Collections.sort(sorted); assertEquals(sorted, identifiers); }