예제 #1
0
 @Test
 public void testCreateAsJSON() throws Exception {
   GeoServer geoServer = getGeoServer();
   geoServer.remove(geoServer.getSettings(geoServer.getCatalog().getWorkspaceByName("sf")));
   String json =
       "{'settings':{'workspace':{'name':'sf'},"
           + "'contact':{'addressCity':'Alexandria','addressCountry':'Egypt','addressType':'Work',"
           + "'contactEmail':'*****@*****.**','contactOrganization':'The ancient geographes INC',"
           + "'contactPerson':'Claudius Ptolomaeus','contactPosition':'Chief geographer'},"
           + "'charset':'UTF-8','numDecimals':10,'onlineResource':'http://geoserver.org',"
           + "'proxyBaseUrl':'http://proxy.url','verbose':false,'verboseExceptions':'true'}}";
   MockHttpServletResponse response =
       putAsServletResponse("/rest/workspaces/sf/settings", json, "text/json");
   assertEquals(200, response.getStatusCode());
   JSON jsonMod = getAsJSON("/rest/workspaces/sf/settings.json");
   JSONObject jsonObject = (JSONObject) jsonMod;
   assertNotNull(jsonObject);
   JSONObject settings = jsonObject.getJSONObject("settings");
   assertNotNull(settings);
   JSONObject workspace = settings.getJSONObject("workspace");
   assertNotNull(workspace);
   assertEquals("sf", workspace.get("name"));
   assertEquals("10", settings.get("numDecimals").toString().trim());
   assertEquals("http://geoserver.org", settings.get("onlineResource"));
   assertEquals("http://proxy.url", settings.get("proxyBaseUrl"));
   JSONObject contact = settings.getJSONObject("contact");
   assertEquals("Claudius Ptolomaeus", contact.get("contactPerson"));
   assertEquals("The ancient geographes INC", contact.get("contactOrganization"));
   assertEquals("Work", contact.get("addressType"));
   assertEquals("*****@*****.**", contact.get("contactEmail"));
 }
예제 #2
0
  @Test
  public void testCreateAsXML() throws Exception {
    GeoServer geoServer = getGeoServer();
    geoServer.remove(geoServer.getSettings(geoServer.getCatalog().getWorkspaceByName("sf")));
    String xml =
        "<settings>"
            + "<workspace><name>sf</name></workspace>"
            + "<contact>"
            + "<addressCity>Alexandria</addressCity>"
            + "<addressCountry>Egypt</addressCountry>"
            + "<addressType>Work</addressType>"
            + "<contactEmail>[email protected]</contactEmail>"
            + "<contactOrganization>The ancient geographes INC</contactOrganization>"
            + "<contactPerson>Claudius Ptolomaeus</contactPerson>"
            + "<contactPosition>Chief geographer</contactPosition>"
            + "</contact>"
            + "<charset>UTF-8</charset>"
            + "<numDecimals>8</numDecimals>"
            + "<onlineResource>http://geoserver.org</onlineResource>"
            + "<proxyBaseUrl>http://proxy.url</proxyBaseUrl>"
            + "<verbose>false</verbose>"
            + "<verboseExceptions>false</verboseExceptions>"
            + "</settings>";
    MockHttpServletResponse response =
        putAsServletResponse("/rest/workspaces/sf/settings", xml, "text/xml");
    assertEquals(200, response.getStatusCode());

    Document dom = getAsDOM("/rest/workspaces/sf/settings.xml");
    assertEquals("settings", dom.getDocumentElement().getLocalName());
    assertXpathEvaluatesTo("sf", "/settings/workspace/name", dom);
    assertXpathEvaluatesTo("false", "/settings/verbose", dom);
    assertXpathEvaluatesTo("false", "/settings/verboseExceptions", dom);
    assertXpathEvaluatesTo("http://geoserver.org", "/settings/onlineResource", dom);
    assertXpathEvaluatesTo("http://proxy.url", "/settings/proxyBaseUrl", dom);
    assertXpathEvaluatesTo("Claudius Ptolomaeus", "/settings/contact/contactPerson", dom);
    assertXpathEvaluatesTo("*****@*****.**", "/settings/contact/contactEmail", dom);
    assertXpathEvaluatesTo("Chief geographer", "/settings/contact/contactPosition", dom);
    assertXpathEvaluatesTo(
        "The ancient geographes INC", "/settings/contact/contactOrganization", dom);
    assertXpathEvaluatesTo("Egypt", "/settings/contact/addressCountry", dom);
  }