/** @see {@link KMLReflector#organizeFormatOptionsParams(Map, Map)} */
  @Test
  public void testKmlFormatOptionsAsKVP() throws Exception {
    final String layerName =
        MockData.BASIC_POLYGONS.getPrefix() + ":" + MockData.BASIC_POLYGONS.getLocalPart();

    final String baseUrl = "wms/kml?layers=" + layerName + "&styles=&mode=superoverlay";
    final String requestUrl =
        baseUrl + "&kmltitle=myCustomLayerTitle&kmscore=10&legend=true&kmattr=true";
    Document dom = getAsDOM(requestUrl);
    XpathEngine xpath = XMLUnit.newXpathEngine();

    // print(dom);
    // all the kvp parameters (which should be set as format_options now are correctly parsed)
    String result = xpath.evaluate("//kml:NetworkLink/kml:Link/kml:href", dom);
    Map<String, Object> kvp = KvpUtils.parseQueryString(result);
    List<String> formatOptions = Arrays.asList(((String) kvp.get("format_options")).split(";"));
    assertEquals(9, formatOptions.size());
    assertTrue(formatOptions.contains("LEGEND:true"));
    assertTrue(formatOptions.contains("SUPEROVERLAY:true"));
    assertTrue(formatOptions.contains("AUTOFIT:true"));
    assertTrue(formatOptions.contains("KMPLACEMARK:false"));
    assertTrue(formatOptions.contains("OVERLAYMODE:auto"));
    assertTrue(formatOptions.contains("KMSCORE:10"));
    assertTrue(formatOptions.contains("MODE:superoverlay"));
    assertTrue(formatOptions.contains("KMATTR:true"));
    assertTrue(formatOptions.contains("KMLTITLE:myCustomLayerTitle"));
  }
Beispiel #2
0
 public void testContentDisposition() throws Exception {
   MockHttpServletResponse resp =
       getAsServletResponse(
           "wms?request=getmap&service=wms&version=1.1.1"
               + "&format="
               + KMZMapOutputFormat.MIME_TYPE
               + "&layers="
               + MockData.BASIC_POLYGONS.getPrefix()
               + ":"
               + MockData.BASIC_POLYGONS.getLocalPart()
               + "&styles="
               + MockData.BASIC_POLYGONS.getLocalPart()
               + "&height=1024&width=1024&bbox=-180,-90,180,90&srs=EPSG:4326");
   assertEquals(
       "attachment; filename=cite-BasicPolygons.kmz", resp.getHeader("Content-Disposition"));
 }
  /**
   * Verify that NetworkLink's generated by the reflector do not include a BBOX parameter, since
   * that would override the BBOX provided by Google Earth.
   *
   * @see <a href="https://osgeo-org.atlassian.net/browse/GEOS-2185">GEOS-2185</a>
   */
  @Test
  public void testNoBBOXInHREF() throws Exception {
    final String layerName = MockData.BASIC_POLYGONS.getLocalPart();
    final XpathEngine xpath = XMLUnit.newXpathEngine();
    String requestURL = "wms/kml?mode=refresh&layers=" + layerName;
    Document dom = getAsDOM(requestURL);
    print(dom);
    assertXpathEvaluatesTo("1", "count(kml:kml/kml:Document)", dom);
    assertXpathEvaluatesTo("1", "count(kml:kml/kml:Document/kml:NetworkLink)", dom);
    assertXpathEvaluatesTo("1", "count(kml:kml/kml:Document/kml:LookAt)", dom);

    assertXpathEvaluatesTo(layerName, "kml:kml/kml:Document/kml:NetworkLink[1]/kml:name", dom);
    assertXpathEvaluatesTo("1", "kml:kml/kml:Document/kml:NetworkLink[1]/kml:open", dom);
    assertXpathEvaluatesTo("1", "kml:kml/kml:Document/kml:NetworkLink[1]/kml:visibility", dom);

    assertXpathEvaluatesTo(
        "onStop", "kml:kml/kml:Document/kml:NetworkLink[1]/kml:Url/kml:viewRefreshMode", dom);
    assertXpathEvaluatesTo(
        "1.0", "kml:kml/kml:Document/kml:NetworkLink[1]/kml:Url/kml:viewRefreshTime", dom);
    assertXpathEvaluatesTo(
        "1.0", "kml:kml/kml:Document/kml:NetworkLink[1]/kml:Url/kml:viewBoundScale", dom);
    Map<String, Object> expectedKVP =
        KvpUtils.parseQueryString(
            "http://localhost:80/geoserver/wms?format_options=MODE%3Arefresh%3Bautofit%3Atrue%3BKMPLACEMARK%3Afalse%3BKMATTR%3Atrue%3BKMSCORE%3A40%3BSUPEROVERLAY%3Afalse&service=wms&srs=EPSG%3A4326&width=2048&styles=BasicPolygons&height=2048&transparent=false&request=GetMap&layers=cite%3ABasicPolygons&format=application%2Fvnd.google-earth.kml+xml&version=1.1.1");
    Map<String, Object> resultedKVP =
        KvpUtils.parseQueryString(
            xpath.evaluate("kml:kml/kml:Document/kml:NetworkLink[1]/kml:Url/kml:href", dom));

    assertMapsEqual(expectedKVP, resultedKVP);

    String href = xpath.evaluate("kml:kml/kml:Document/kml:NetworkLink/kml:Link/kml:href", dom);
    Pattern badPattern = Pattern.compile("&bbox=", Pattern.CASE_INSENSITIVE);
    assertFalse(badPattern.matcher(href).matches());
  }
Beispiel #4
0
  public void testVectorWithFeatureId() throws Exception {
    Document doc =
        getAsDOM(
            "wms?request=getmap&service=wms&version=1.1.1"
                + "&format="
                + KMLMapOutputFormat.MIME_TYPE
                + "&layers="
                + MockData.BASIC_POLYGONS.getPrefix()
                + ":"
                + MockData.BASIC_POLYGONS.getLocalPart()
                + "&styles="
                + MockData.BASIC_POLYGONS.getLocalPart()
                + "&height=1024&width=1024&bbox=-180,-90,180,90&srs=EPSG:4326"
                + "&featureid=BasicPolygons.1107531493643");

    assertEquals(1, doc.getElementsByTagName("Placemark").getLength());
  }
  @Test
  public void testWmsRepeatedLayerWithNonStandardStyleAndCqlFiler() throws Exception {
    final String layerName =
        MockData.BASIC_POLYGONS.getPrefix() + ":" + MockData.BASIC_POLYGONS.getLocalPart();
    final String titleName = MockData.BASIC_POLYGONS.getLocalPart();
    final String abstractValue = "abstract about " + titleName;

    String requestUrl =
        "wms/kml?mode=refresh&layers="
            + layerName
            + ","
            + layerName
            + "&styles=Default,Default&cql_filter=att1<10;att1>1000";
    Document dom = getAsDOM(requestUrl);

    assertEquals("kml", dom.getDocumentElement().getLocalName());

    assertXpathEvaluatesTo("2", "count(kml:kml/kml:Document/kml:NetworkLink)", dom);
    assertXpathEvaluatesTo(titleName, "kml:kml/kml:Document/kml:NetworkLink[1]/kml:name", dom);
    assertXpathEvaluatesTo(
        abstractValue, "kml:kml/kml:Document/kml:NetworkLink[1]/kml:description", dom);
    assertXpathEvaluatesTo(titleName, "kml:kml/kml:Document/kml:NetworkLink[2]/kml:name", dom);
    assertXpathEvaluatesTo(
        abstractValue, "kml:kml/kml:Document/kml:NetworkLink[2]/kml:description", dom);

    XpathEngine xpath = XMLUnit.newXpathEngine();

    String url1 = xpath.evaluate("/kml:kml/kml:Document/kml:NetworkLink[1]/kml:Url/kml:href", dom);
    String url2 = xpath.evaluate("/kml:kml/kml:Document/kml:NetworkLink[2]/kml:Url/kml:href", dom);

    assertNotNull(url1);
    assertNotNull(url2);

    Map<String, Object> kvp1 = KvpUtils.parseQueryString(url1);
    Map<String, Object> kvp2 = KvpUtils.parseQueryString(url2);

    assertEquals(layerName, kvp1.get("layers"));
    assertEquals(layerName, kvp2.get("layers"));

    assertEquals("Default", kvp1.get("styles"));
    assertEquals("Default", kvp2.get("styles"));

    assertEquals("att1<10", kvp1.get("cql_filter"));
    assertEquals("att1>1000", kvp2.get("cql_filter"));
  }
Beispiel #6
0
  public void testVector() throws Exception {
    Document doc =
        getAsDOM(
            "wms?request=getmap&service=wms&version=1.1.1"
                + "&format="
                + KMLMapOutputFormat.MIME_TYPE
                + "&layers="
                + MockData.BASIC_POLYGONS.getPrefix()
                + ":"
                + MockData.BASIC_POLYGONS.getLocalPart()
                + "&styles="
                + MockData.BASIC_POLYGONS.getLocalPart()
                + "&height=1024&width=1024&bbox=-180,-90,180,90&srs=EPSG:4326");

    assertEquals(
        getFeatureSource(MockData.BASIC_POLYGONS).getFeatures().size(),
        doc.getElementsByTagName("Placemark").getLength());
  }
  @Test
  public void testGML3() throws Exception {
    Document dom =
        getAsDOM(
            "wfs?request=getfeature&version=1.0.0&outputFormat=gml3&typename="
                + MockData.BASIC_POLYGONS.getPrefix()
                + ":"
                + MockData.BASIC_POLYGONS.getLocalPart());
    assertEquals("FeatureCollection", dom.getDocumentElement().getLocalName());
    assertNull(getFirstElementByTagName(dom, "gml:outerBoundaryIs"));
    assertNotNull(getFirstElementByTagName(dom, "gml:exterior"));

    dom =
        getAsDOM(
            "wfs?request=getfeature&version=1.1.0&outputFormat=gml3&typename="
                + MockData.BASIC_POLYGONS.getPrefix()
                + ":"
                + MockData.BASIC_POLYGONS.getLocalPart());
    assertEquals("FeatureCollection", dom.getDocumentElement().getLocalName());
    assertNull(getFirstElementByTagName(dom, "gml:outerBoundaryIs"));
    assertNotNull(getFirstElementByTagName(dom, "gml:exterior"));

    dom =
        getAsDOM(
            "wfs?request=getfeature&version=1.0.0&outputFormat=text/xml; subtype%3Dgml/3.1.1&typename="
                + MockData.BASIC_POLYGONS.getPrefix()
                + ":"
                + MockData.BASIC_POLYGONS.getLocalPart());
    assertEquals("FeatureCollection", dom.getDocumentElement().getLocalName());
    assertNull(getFirstElementByTagName(dom, "gml:outerBoundaryIs"));
    assertNotNull(getFirstElementByTagName(dom, "gml:exterior"));

    dom =
        getAsDOM(
            "wfs?request=getfeature&version=1.1.0&outputFormat=text/xml; subtype%3Dgml/3.1.1&typename="
                + MockData.BASIC_POLYGONS.getPrefix()
                + ":"
                + MockData.BASIC_POLYGONS.getLocalPart());
    assertEquals("FeatureCollection", dom.getDocumentElement().getLocalName());
    assertNull(getFirstElementByTagName(dom, "gml:outerBoundaryIs"));
    assertNotNull(getFirstElementByTagName(dom, "gml:exterior"));
  }
 @Test
 public void testGML32() throws Exception {
   Document dom =
       getAsDOM(
           "wfs?request=getfeature&version=2.0.0&outputFormat=gml32&typename="
               + MockData.BASIC_POLYGONS.getPrefix()
               + ":"
               + MockData.BASIC_POLYGONS.getLocalPart());
   assertEquals(WFS.NAMESPACE, dom.getDocumentElement().getNamespaceURI());
   assertEquals("FeatureCollection", dom.getDocumentElement().getLocalName());
 }
 @Test
 public void testForce() throws Exception {
   FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.BASIC_POLYGONS.getLocalPart());
   assertEquals("EPSG:4269", fti.getSRS());
   assertEquals(ProjectionPolicy.FORCE_DECLARED, fti.getProjectionPolicy());
   FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures();
   assertEquals(CRS.decode("EPSG:4269"), fc.getSchema().getCoordinateReferenceSystem());
   FeatureIterator fi = fc.features();
   Feature f = fi.next();
   fi.close();
   assertEquals(CRS.decode("EPSG:4269"), f.getType().getCoordinateReferenceSystem());
 }
Beispiel #10
0
  /** Do some spot checks on the KML generated when an overlay hierarchy is requested. */
  @Test
  public void testSuperOverlayReflection() throws Exception {
    final String layerName =
        MockData.BASIC_POLYGONS.getPrefix() + ":" + MockData.BASIC_POLYGONS.getLocalPart();

    final String requestUrl = "wms/kml?layers=" + layerName + "&styles=&mode=superoverlay";
    Document dom = getAsDOM(requestUrl);
    // print(dom);
    assertEquals("kml", dom.getDocumentElement().getLocalName());
    assertXpathExists("kml:kml/kml:Document/kml:Folder/kml:NetworkLink/kml:Link/kml:href", dom);
    assertXpathExists("kml:kml/kml:Document/kml:LookAt/kml:longitude", dom);
  }
Beispiel #11
0
  @Test
  public void testKmlTitleFormatOption() throws Exception {
    final String layerName =
        MockData.BASIC_POLYGONS.getPrefix() + ":" + MockData.BASIC_POLYGONS.getLocalPart();

    final String requestUrl =
        "wms/kml?layers="
            + layerName
            + "&styles=&mode=superoverlay&format_options=kmltitle:myCustomLayerTitle";
    // System.out.println(getAsServletResponse(requestUrl).getContentType());
    Document dom = getAsDOM(requestUrl);
    // print(dom);
    assertEquals("kml", dom.getDocumentElement().getLocalName());
    assertXpathEvaluatesTo("myCustomLayerTitle", "/kml:kml/kml:Document/kml:name", dom);
  }
Beispiel #12
0
  @Test
  public void testKmlVisibleFormatOption() throws Exception {
    final String layerName =
        MockData.BASIC_POLYGONS.getPrefix() + ":" + MockData.BASIC_POLYGONS.getLocalPart();

    String requestUrl = "wms/kml?layers=" + layerName + "&format_options=kmlvisible:true";
    Document dom = getAsDOM(requestUrl);

    // print(dom);
    assertEquals("kml", dom.getDocumentElement().getLocalName());
    assertXpathEvaluatesTo("1", "/kml:kml/kml:Document/kml:NetworkLink/kml:visibility", dom);

    requestUrl = "wms/kml?layers=" + layerName + "&format_options=kmlvisible:false";
    dom = getAsDOM(requestUrl);
    assertEquals("kml", dom.getDocumentElement().getLocalName());
    assertXpathEvaluatesTo("0", "/kml:kml/kml:Document/kml:NetworkLink/kml:visibility", dom);
  }
Beispiel #13
0
  @Test
  public void testKmlRefreshFormatOption() throws Exception {
    final String layerName =
        MockData.BASIC_POLYGONS.getPrefix() + ":" + MockData.BASIC_POLYGONS.getLocalPart();

    String requestUrl = "wms/kml?layers=" + layerName + "&format_options=kmlrefresh:expires";
    Document dom = getAsDOM(requestUrl);

    // print(dom);
    assertEquals("kml", dom.getDocumentElement().getLocalName());
    assertXpathEvaluatesTo(
        "onExpire", "/kml:kml/kml:Document/kml:NetworkLink/kml:Url/kml:refreshMode", dom);

    requestUrl = "wms/kml?layers=" + layerName + "&format_options=kmlrefresh:60";
    dom = getAsDOM(requestUrl);
    assertXpathEvaluatesTo(
        "onInterval", "/kml:kml/kml:Document/kml:NetworkLink/kml:Url/kml:refreshMode", dom);
    assertXpathEvaluatesTo(
        "60.0", "/kml:kml/kml:Document/kml:NetworkLink/kml:Url/kml:refreshInterval", dom);
  }