GetRecords { public static String createRequest(Filter filter) { if (filter == null) { throw new ServiceRuntimeException("Filter is required"); } final StringWriter writer = new StringWriter(); XMLStreamWriter xsw = getXMLWriter(writer); startDocument(xsw); writeRawXMLUnsafe(xsw, writer, getFilterAsString(filter)); endDocument(xsw); return writer.toString(); } private  GetRecords(); static String createRequest(Filter filter);  }
@Test(expected = ServiceRuntimeException.class) public void testWithNoFilter() { org.oskari.csw.request.GetRecords.createRequest(null); fail("Should have thrown exception"); }
@Test public void testSimpleFilter() throws IOException, SAXException { Filter filter = createEqualsFilter("my value", "myprop"); String request = org.oskari.csw.request.GetRecords.createRequest(filter); String expected = IOHelper.readString(getClass().getResourceAsStream("GetRecords-simple.xml")); Diff xmlDiff = new Diff(request, expected); assertTrue("Should get expected simple request" + xmlDiff, xmlDiff.similar()); }
@Test public void testMultiFilter() throws IOException, SAXException { Filter equalfilter = createEqualsFilter("my value", "myprop"); Filter likefilter = createLikeFilter("input*", "query"); String request = org.oskari.csw.request.GetRecords.createRequest(filterFactory.and(equalfilter, likefilter)); String expected = IOHelper.readString(getClass().getResourceAsStream("GetRecords-multi.xml")); Diff xmlDiff = new Diff(request, expected); assertTrue("Should get expected and-filter request" + xmlDiff, xmlDiff.similar()); }
@Test public void testCoverageFilter() throws IOException, SAXException { String input = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[292864,6845440],[292864,6781952],[393216,6781952],[393216,6845440],[292864,6845440]]]},\"properties\":{\"area\":\"Alue ei saa muodostaa silmukkaa. Piirrä risteämätön alue nähdäksesi mittaustuloksen.\"},\"id\":\"drawFeature3\"}],\"crs\":\"EPSG:3067\"}"; Filter filter = createGeometryFilter(input); String request = org.oskari.csw.request.GetRecords.createRequest(filter); String expected = IOHelper.readString(getClass().getResourceAsStream("GetRecords-coverage.xml")); Diff xmlDiff = new Diff(request, expected); DetailedDiff detailXmlDiff = new DetailedDiff(xmlDiff); List<Difference> differences = detailXmlDiff.getAllDifferences(); boolean isJava11 = System.getProperty("java.version").startsWith("11."); if (isJava11 && differences.size() == 1) { final String coordinatesPath = "/GetRecords[1]/Query[1]/Constraint[1]/Filter[1]/Intersects[1]/Polygon[1]/outerBoundaryIs[1]/LinearRing[1]/coordinates[1]/text()[1]"; assertEquals("Something else than coordinates transform differ in expected and result", coordinatesPath, differences.get(0).getTestNodeDetail().getXpathLocation()); } else { assertTrue("Should get expected coverage request" + xmlDiff, xmlDiff.similar()); } }