org.glassfish.grizzly.http.util.HttpStatus Java Examples

The following examples show how to use org.glassfish.grizzly.http.util.HttpStatus. 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: OWSCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void createWcsSettingsForWorkspace() throws Exception {
    String url = "/geoserver/rest/services/wcs/workspaces/topp/settings.xml";
    whenHttp(server).match(put(url)).then(stringContent("true"), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    OWSCommands commands = new OWSCommands();
    commands.setGeoserver(geoserver);
    String workspace = "topp";
    boolean enabled = true;
    boolean verbose = true;
    boolean gmlPrefixing = false;
    boolean latlon = false;
    int maxInputMemory = 512;
    int maxOutputMemory = 256;
    boolean subsamplingEnabled = true;
    boolean result = commands.wcsCreate(workspace, enabled, verbose, gmlPrefixing, latlon, maxInputMemory, maxOutputMemory, subsamplingEnabled);
    assertTrue(result);
    String actual = server.getCalls().get(0).getPostBody();
    String expected = "<wcs><workspace>topp</workspace><name>WCS</name><enabled>true</enabled>" +
            "<verbose>true</verbose><gmlPrefixing>false</gmlPrefixing><latLon>false</latLon>" +
            "<maxInputMemory>512</maxInputMemory><maxOutputMemory>256</maxOutputMemory>" +
            "<subsamplingEnabled>true</subsamplingEnabled></wcs>";
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.PUT), uri(url));
}
 
Example #2
Source File: GeoWebCacheCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void truncate() throws Exception {
    String url = "/geoserver/gwc/rest/seed/topp:states.xml";
    whenHttp(server).match(post(url)).then(stringContent("true"), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    GeoWebCacheCommands commands = new GeoWebCacheCommands();
    commands.setGeoserver(geoserver);
    String name = "topp:states";
    String bounds = "0,0,100,100";
    String gridSet = "EPSG:4326";
    int start = 0;
    int stop = 5;
    String format = "image/png";
    boolean result = commands.truncate(name, bounds, gridSet, start, stop, format);
    assertTrue(result);
    String actual = server.getCalls().get(0).getPostBody();
    String expected = "<seedRequest><name>topp:states</name><bounds><coords><double>0</double><double>100</double>" +
            "<double>0</double><double>100</double></coords></bounds><gridSetId>EPSG:4326</gridSetId>" +
            "<zoomStart>0</zoomStart><zoomStop>5</zoomStop><format>image/png</format><type>truncate</type>" +
            "<threadCount>1</threadCount></seedRequest>";
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.POST), uri(url));
}
 
Example #3
Source File: WebServer.java    From AthenaX with Apache License 2.0 6 votes vote down vote up
public WebServer(URI endpoint) throws IOException {
  this.server = GrizzlyServerFactory.createHttpServer(endpoint, new HttpHandler() {

    @Override
    public void service(Request rqst, Response rspns) throws Exception {
      rspns.setStatus(HttpStatus.NOT_FOUND_404.getStatusCode(), "Not found");
      rspns.getWriter().write("404: not found");
    }
  });

  WebappContext context = new WebappContext("WebappContext", BASE_PATH);
  ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class);
  registration.setInitParameter(ServletContainer.RESOURCE_CONFIG_CLASS,
      PackagesResourceConfig.class.getName());

  StringJoiner sj = new StringJoiner(",");
  for (String s : PACKAGES) {
    sj.add(s);
  }

  registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, sj.toString());
  registration.addMapping(BASE_PATH);
  context.deploy(server);
}
 
Example #4
Source File: OWSCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void listWcsSettings() throws Exception {
    String url = "/geoserver/rest/services/wcs/settings.xml";
    whenHttp(server).match(get(url)).then(stringContent(getResourceString("wcs.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    OWSCommands commands = new OWSCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.wcsList(null);
    String expected = "WCS" + OsUtils.LINE_SEPARATOR +
            "   Enabled: true" + OsUtils.LINE_SEPARATOR +
            "   Cite Compliant: false" + OsUtils.LINE_SEPARATOR +
            "   Schema Base URL: http://schemas.opengis.net" + OsUtils.LINE_SEPARATOR +
            "   Verbose: false" + OsUtils.LINE_SEPARATOR +
            "   GML Prefixing: false" + OsUtils.LINE_SEPARATOR +
            "   LatLon: false" + OsUtils.LINE_SEPARATOR +
            "   Max Input Memory: -1" + OsUtils.LINE_SEPARATOR +
            "   Max Output Memory: -1" + OsUtils.LINE_SEPARATOR +
            "   Subsampling Enabled: false" + OsUtils.LINE_SEPARATOR +
            "   Versions:" + OsUtils.LINE_SEPARATOR +
            "      1.0.0" + OsUtils.LINE_SEPARATOR +
            "      1.1.1" + OsUtils.LINE_SEPARATOR +
            "      2.0.1" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.GET), uri(url));
}
 
Example #5
Source File: NvdRestServiceMockup.java    From steady with Apache License 2.0 6 votes vote down vote up
/**
 * Starts the server and registers URIs for the different vulnerabilities in {@link NvdRestServiceMockup#CVES}.
 * @throws IOException
 */
public NvdRestServiceMockup() {
	server = new StubServer().run();
	RestAssured.port = server.getPort();
	System.setProperty(VulasConfiguration.getServiceUrlKey(Service.CVE), "http://localhost:" + server.getPort() + "/nvdrest/vulnerabilities/<ID>");
	int cves_registered = 0;
	for(String cve: CVES) {
		try {
			whenHttp(server).
			match(composite(method(Method.GET), uri("/nvdrest/vulnerabilities/" + cve))).
			then(
					stringContent(FileUtil.readFile(Paths.get("./src/test/resources/cves/" + cve + "-new.json"))),
					contentType("application/json"),
					charset("UTF-8"),
					status(HttpStatus.OK_200));
			cves_registered++;
		} catch (IOException e) {
			System.err.println("Could not register URI for cve [" + cve + "]: " + e.getMessage());
		}
	}
	if(cves_registered==0) {
		throw new IllegalStateException("None of the CVEs could be registered");
	}
}
 
Example #6
Source File: CoverageStoreCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void uploadCoverageStore() throws Exception {
    String workspace = "nurc";
    String coverageStore = "terrain";
    File file = getResourceFile("coveragestore.xml");
    String type = "geotiff";
    String configure = "first";
    String coverage = "myterrain";
    String recalculate = "nativebbox";
    String url = "/geoserver/rest/workspaces/nurc/coveragestores/terrain/file.geotiff";
    whenHttp(server).match(put(url)).then(stringContent("true"), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    CoverageStoreCommands commands = new CoverageStoreCommands();
    commands.setGeoserver(geoserver);
    boolean result = commands.upload(workspace, coverageStore, file, type, configure, coverage, recalculate);
    assertTrue(result);
    String body = server.getCalls().get(0).getPostBody();
    String contentType = server.getCalls().get(0).getContentType();
    assertEquals("image/tiff", contentType);
    Map<String, String[]> params = server.getCalls().get(0).getParameters();
    assertEquals(configure, params.get("configure")[0]);
    assertEquals(recalculate, params.get("recalculate")[0]);
    assertEquals(coverage, params.get("coverageName")[0]);
    verifyHttp(server).once(method(Method.PUT), uri(url));
}
 
Example #7
Source File: RootHttpHandler.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void service(final Request request, final Response response) throws Exception {
	// don't decode and avoid creating a string
	final DataChunk requestURIBC = request.getRequest().getRequestURIRef().getRequestURIBC();

	if (requestURIBC.equals("/json")) {
		jsonHandler.service(request, response);
	} else if (requestURIBC.equals("/plaintext")) {
		plainTextHandler.service(request, response);
	} else {
		response.getOutputBuffer().write(
				getErrorPageGenerator(request).generate(request,
						HttpStatus.NOT_FOUND_404.getStatusCode(),
						HttpStatus.NOT_FOUND_404.getReasonPhrase(), null, null));
	}
}
 
Example #8
Source File: TemplateCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void modifyTemplate() throws Exception {
    String url = "/geoserver/rest/templates/template.ftl";
    whenHttp(server).match(put(url)).then(stringContent("true"), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    TemplateCommands commands = new TemplateCommands();
    commands.setGeoserver(geoserver);
    File file = getResourceFile("template.ftl");
    String name = "template";
    String workspace = null;
    String dataStore = null;
    String featureType = null;
    String coverageStore = null;
    String coverage = null;
    boolean result = commands.modify(name, file, workspace, dataStore, featureType, coverageStore, coverage);
    assertTrue(result);
    verifyHttp(server).once(method(Method.PUT), uri(url));
}
 
Example #9
Source File: ScriptCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void createWps() throws Exception {
    whenHttp(server).match(put("/geoserver/rest/scripts/wps/buffer.groovy")).then(stringContent("true"), status(HttpStatus.OK_200));

    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    ScriptCommands commands = new ScriptCommands();
    commands.setGeoserver(geoserver);

    File file = File.createTempFile("buffer", ".groovy");
    FileWriter writer = new FileWriter(file);
    writer.write(getResourceString("script.groovy"));
    writer.close();

    boolean result = commands.createWps("buffer.groovy", file);
    assertTrue(result);

    verifyHttp(server).once(method(Method.PUT), uri("/geoserver/rest/scripts/wps/buffer.groovy"));
}
 
Example #10
Source File: ScriptCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void createFunction() throws Exception {
    whenHttp(server).match(put("/geoserver/rest/scripts/function/buffer.groovy")).then(stringContent("true"), status(HttpStatus.OK_200));

    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    ScriptCommands commands = new ScriptCommands();
    commands.setGeoserver(geoserver);

    File file = File.createTempFile("buffer", ".groovy");
    FileWriter writer = new FileWriter(file);
    writer.write(getResourceString("script.groovy"));
    writer.close();

    boolean result = commands.createFunction("buffer.groovy", file);
    assertTrue(result);

    verifyHttp(server).once(method(Method.PUT), uri("/geoserver/rest/scripts/function/buffer.groovy"));
}
 
Example #11
Source File: ScriptCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void modifyFunction() throws Exception {
    whenHttp(server).match(put("/geoserver/rest/scripts/function/buffer.groovy")).then(stringContent("true"), status(HttpStatus.OK_200));

    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    ScriptCommands commands = new ScriptCommands();
    commands.setGeoserver(geoserver);

    File file = File.createTempFile("buffer", ".groovy");
    FileWriter writer = new FileWriter(file);
    writer.write(getResourceString("script.groovy"));
    writer.close();

    boolean result = commands.modifyFunction("buffer.groovy", file);
    assertTrue(result);

    verifyHttp(server).once(method(Method.PUT), uri("/geoserver/rest/scripts/function/buffer.groovy"));
}
 
Example #12
Source File: DataStoreCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void modifyDataStore() throws Exception {
    String url = "/geoserver/rest/workspaces/topp/datastores/hydro.xml";
    whenHttp(server).match(put(url)).then(stringContent("true"), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    DataStoreCommands commands = new DataStoreCommands();
    commands.setGeoserver(geoserver);
    String workspace = "topp";
    String name = "hydro";
    String connectionParams = null;
    String description = "The hydro lines for Tasmania";
    String enabled = null;
    boolean result = commands.modify(workspace, name, connectionParams, description, enabled);
    assertTrue(result);
    String actual = server.getCalls().get(0).getPostBody();
    String expected = "<dataStore><name>hydro</name>" +
            "<description>The hydro lines for Tasmania</description></dataStore>";
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.PUT), uri(url));
}
 
Example #13
Source File: ScriptCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void modifyWfsTx() throws Exception {
    whenHttp(server).match(put("/geoserver/rest/scripts/wfs/tx/buffer.groovy")).then(stringContent("true"), status(HttpStatus.OK_200));

    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    ScriptCommands commands = new ScriptCommands();
    commands.setGeoserver(geoserver);

    File file = File.createTempFile("buffer", ".groovy");
    FileWriter writer = new FileWriter(file);
    writer.write(getResourceString("script.groovy"));
    writer.close();

    boolean result = commands.modifyWfsTx("buffer.groovy", file);
    assertTrue(result);

    verifyHttp(server).once(method(Method.PUT), uri("/geoserver/rest/scripts/wfs/tx/buffer.groovy"));
}
 
Example #14
Source File: SettingsCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void listLocalSettings() throws Exception {
    String url = "/geoserver/rest/workspaces/topp/settings.xml";
    whenHttp(server).match(get(url)).then(stringContent(getResourceString("localSettings.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    SettingsCommands commands = new SettingsCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.listLocal("topp");
    String expected = "Settings" + OsUtils.LINE_SEPARATOR +
            "   Charset: UTF-8" + OsUtils.LINE_SEPARATOR +
            "   Number of Decimals: 4" + OsUtils.LINE_SEPARATOR +
            "   Online Resource: null" + OsUtils.LINE_SEPARATOR +
            "   Verbose: false" + OsUtils.LINE_SEPARATOR +
            "   Verbose Exceptions: false" + OsUtils.LINE_SEPARATOR +
            "" + OsUtils.LINE_SEPARATOR +
            "Contact" + OsUtils.LINE_SEPARATOR +
            "   City: null" + OsUtils.LINE_SEPARATOR +
            "   Country: null" + OsUtils.LINE_SEPARATOR +
            "   Type: work" + OsUtils.LINE_SEPARATOR +
            "   Email: null" + OsUtils.LINE_SEPARATOR +
            "   Organization: Work" + OsUtils.LINE_SEPARATOR +
            "   Name: John Doe" + OsUtils.LINE_SEPARATOR +
            "   Position: null" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.GET), uri(url));
}
 
Example #15
Source File: CoverageStoreCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void createCoverageStore() throws Exception {
    String url = "/geoserver/rest/workspaces/nurc/coveragestores.xml";
    whenHttp(server).match(post(url)).then(stringContent("true"), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    CoverageStoreCommands commands = new CoverageStoreCommands();
    commands.setGeoserver(geoserver);
    String workspace = "nurc";
    String name = "terrain";
    String type = "geotiff";
    String fileUrl = "file:/terrain.tif";
    boolean enabled = true;
    boolean result = commands.create(workspace, name, type, fileUrl, enabled);
    assertTrue(result);
    String actual = server.getCalls().get(0).getPostBody();
    String expected = "<coverageStore><name>terrain</name><type>geotiff</type><url>file:/terrain.tif</url><enabled>true</enabled><workspace><name>nurc</name></workspace></coverageStore>";
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.POST), uri(url));
}
 
Example #16
Source File: LayerCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void modifyLayer() throws Exception {
    String url = "/geoserver/rest/layers/streams.xml";
    whenHttp(server).match(put(url)).then(stringContent("true"), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    LayerCommands commands = new LayerCommands();
    commands.setGeoserver(geoserver);
    String name = "streams";
    String title = "Streams";
    String abstractStr = null;
    String defaultStyle = null;
    String enabled = null;
    boolean result = commands.modify(name, title, abstractStr, defaultStyle, enabled);
    assertTrue(result);
    String actual = server.getCalls().get(0).getPostBody();
    String expected = "<layer><name>streams</name><title>Streams</title></layer>";
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.PUT), uri(url));
}
 
Example #17
Source File: LayerGroupCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void modifyLayerGroupWithWorkspace() throws Exception {
    String url = "/geoserver/rest/workspaces/topp/layergroups/census.xml";
    whenHttp(server).match(put(url)).then(stringContent("true"), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    LayerGroupCommands commands = new LayerGroupCommands();
    commands.setGeoserver(geoserver);
    String name = "census";
    String layers = "tracts,block groups,blocks";
    String styles = "tracts,block groups,blocks";
    String workspace = "topp";
    boolean result = commands.modify(name, layers, styles, workspace);
    assertTrue(result);
    String actual = server.getCalls().get(0).getPostBody();
    String expected = "<layerGroup><name>census</name><layers><layer>tracts</layer><layer>block groups</layer>" +
            "<layer>blocks</layer></layers><styles><style>tracts</style><style>block groups</style>" +
            "<style>blocks</style></styles></layerGroup>";
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.PUT), uri(url));
}
 
Example #18
Source File: LayerGroupCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void createLayerGroupWithWorspace() throws Exception {
    String url = "/geoserver/rest/workspaces/topp/layergroups.xml";
    whenHttp(server).match(post(url)).then(stringContent("true"), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    LayerGroupCommands commands = new LayerGroupCommands();
    commands.setGeoserver(geoserver);
    String name = "census";
    String layers = "tracts,block groups,blocks";
    String styles = "tracts,block groups, blocks";
    String workspace = "topp";
    boolean result = commands.create(name, layers, styles, workspace);
    assertTrue(result);
    String actual = server.getCalls().get(0).getPostBody();
    String expected = "<layerGroup><name>census</name><layers><layer>tracts</layer><layer>block groups</layer>" +
            "<layer>blocks</layer></layers><styles><style>tracts</style><style>block groups</style>" +
            "<style>blocks</style></styles></layerGroup>";
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.POST), uri(url));
}
 
Example #19
Source File: PostGISCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void publishFeatureType() throws Exception {
    String url = "/geoserver/rest/workspaces/topp/datastores/postgis/featuretypes.xml";
    whenHttp(server).match(post(url)).then(stringContent(getResourceString("featuretypes.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    PostGISCommands commands = new PostGISCommands();
    commands.setGeoserver(geoserver);
    String workspace = "topp";
    String dataStore = "postgis";
    String table = "world_boundaries";
    boolean result = commands.publishLayer(workspace, dataStore, table);
    assertTrue(result);
    String actual = server.getCalls().get(0).getPostBody();
    String expected = "<featureType><name>world_boundaries</name></featureType>";
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.POST), uri(url));
}
 
Example #20
Source File: AboutCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void manifestGet() throws Exception {
    whenHttp(server).match(get("/geoserver/rest/about/manifests.xml")).then(stringContent(getResourceString("manifests.xml")), status(HttpStatus.OK_200));

    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    AboutCommands commands = new AboutCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.manifestGet("gt-xsd-ows-9.1");
    String expected = "gt-xsd-ows-9.1" + OsUtils.LINE_SEPARATOR +
            "   Manifest-Version: 1.0" + OsUtils.LINE_SEPARATOR +
            "   Archiver-Version: Plexus Archiver" + OsUtils.LINE_SEPARATOR +
            "   Built-By: jetty" + OsUtils.LINE_SEPARATOR +
            "   Build-Timestamp: 20-Apr-2013 11:03" + OsUtils.LINE_SEPARATOR +
            "   Git-Revision: f25b08094d1bf7e0949994f4971bc21fb117d37b" + OsUtils.LINE_SEPARATOR +
            "   Build-Jdk: 1.6.0_22" + OsUtils.LINE_SEPARATOR +
            "   Project-Version: 9.1" + OsUtils.LINE_SEPARATOR +
            "   Created-By: Apache Maven" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);

    verifyHttp(server).once(method(Method.GET), uri("/geoserver/rest/about/manifests.xml"));
}
 
Example #21
Source File: ScriptCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void modifyApp() throws Exception {
    whenHttp(server).match(put("/geoserver/rest/scripts/apps/buffer/main.groovy")).then(stringContent("true"), status(HttpStatus.OK_200));

    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    ScriptCommands commands = new ScriptCommands();
    commands.setGeoserver(geoserver);

    File file = File.createTempFile("buffer", "groovy");
    FileWriter writer = new FileWriter(file);
    writer.write(getResourceString("script.groovy"));
    writer.close();

    boolean result = commands.modifyApp("buffer", "groovy", file);
    assertTrue(result);

    verifyHttp(server).once(method(Method.PUT), uri("/geoserver/rest/scripts/apps/buffer/main.groovy"));
}
 
Example #22
Source File: CoverageCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void modifyCoverage() throws Exception {
    String url = "/geoserver/rest/workspaces/nurc/coveragestores/mosaic/coverages/new.xml";
    whenHttp(server).match(put(url)).then(stringContent("true"), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    CoverageCommands commands = new CoverageCommands();
    commands.setGeoserver(geoserver);
    String workspace = "nurc";
    String coveragestore = "mosaic";
    String coverage = "new";
    String title = "New Title";
    String description = "New Description";
    String keywords = null;
    String srs = null;
    String enabled = null;
    boolean result = commands.modify(workspace, coveragestore, coverage, title, description, keywords, srs, enabled);
    assertTrue(result);
    String expected = "<coverage><enabled>true</enabled><metadata /><keywords /><metadataLinks /><supportedFormats /><name>new</name><title>New Title</title><description>New Title</description></coverage>";
    String actual = server.getCalls().get(0).getPostBody();
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.PUT), uri(url));
}
 
Example #23
Source File: WmsStoreCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void listAvailableLayers() throws Exception {
    String url = "/geoserver/rest/workspaces/topp/wmsstores/massgis/wmslayers.xml";
    whenHttp(server).match(get(url)).then(stringContent(getResourceString("wms_available_layers.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    WmsStoreCommands commands = new WmsStoreCommands();
    commands.setGeoserver(geoserver);
    String actual = commands.listAvailableLayers("topp", "massgis");
    String expected = "massgis:AFREEMAN.AUDUBON_BIRD_S_V" + OsUtils.LINE_SEPARATOR +
            "massgis:AFREEMAN.AUDUBON_BUTTERFLY_S_V" + OsUtils.LINE_SEPARATOR +
            "massgis:AFREEMAN.AUDUBON_GRID_POLY" + OsUtils.LINE_SEPARATOR +
            "massgis:AFREEMAN.BLDGS_TEST_POLY" + OsUtils.LINE_SEPARATOR +
            "massgis:AFREEMAN.CAMPUS_BLDGS_POLY" + OsUtils.LINE_SEPARATOR +
            "massgis:AFREEMAN.CAMPUS_SITES_POLY" + OsUtils.LINE_SEPARATOR +
            "massgis:AFREEMAN.CPA_COMBINED_V_PT" + OsUtils.LINE_SEPARATOR +
            "massgis:AFREEMAN.CPA_PT" + OsUtils.LINE_SEPARATOR +
            "massgis:AFREEMAN.DCAM_BLDG_PTS_20120229" + OsUtils.LINE_SEPARATOR;
    assertEquals(expected, actual);
    assertEquals("available", server.getCalls().get(0).getParameters().get("list")[0]);
    verifyHttp(server).once(method(Method.GET), uri(url));
}
 
Example #24
Source File: SettingsCommandsTest.java    From geoserver-shell with MIT License 6 votes vote down vote up
@Test
public void modifyContactSettings() throws Exception {
    String url = "/geoserver/rest/settings/contact.xml";
    whenHttp(server).match(put(url)).then(stringContent(getResourceString("contactSettings.xml")), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    SettingsCommands commands = new SettingsCommands();
    commands.setGeoserver(geoserver);
    String person = "Jane Doe";
    String position = "CIO";
    String email = "[email protected]";
    String organization = "GeoComp";
    String city = "Plainville";
    String country = "Canada";
    String addressType = "Work";
    boolean result = commands.modifyContact(person, position, email, organization, city, country, addressType);
    assertTrue(result);
    String actual = server.getCalls().get(0).getPostBody();
    String expected = "<contact><contactPerson>Jane Doe</contactPerson><contactPosition>CIO</contactPosition>" +
            "<contactEmail>[email protected]</contactEmail><contactOrganization>GeoComp</contactOrganization>" +
            "<addressCity>Plainville</addressCity><addressCountry>Canada</addressCountry><" +
            "addressType>Work</addressType></contact>";
    assertEquals(expected, actual);
    verifyHttp(server).once(method(Method.PUT), uri(url));
}
 
Example #25
Source File: StyleCommandsTest.java    From geoserver-shell with MIT License 5 votes vote down vote up
@Test
public void deleteStyleWithWorkspace() throws Exception {
    String url = "/geoserver/rest/workspaces/topp/styles/polygon";
    whenHttp(server).match(delete(url)).then(status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    StyleCommands commands = new StyleCommands();
    commands.setGeoserver(geoserver);
    boolean result = commands.delete("polygon", "topp", true);
    assertTrue(result);
    verifyHttp(server).once(method(Method.DELETE), uri(url));
}
 
Example #26
Source File: OWSCommandsTest.java    From geoserver-shell with MIT License 5 votes vote down vote up
@Test
public void deleteWcsSettingsForWorkspace() throws Exception {
    String url = "/geoserver/rest/services/wcs/workspaces/topp/settings.xml";
    whenHttp(server).match(delete(url)).then(stringContent("true"), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    OWSCommands commands = new OWSCommands();
    commands.setGeoserver(geoserver);
    boolean result = commands.wcsDelete("topp");
    assertTrue(result);
    verifyHttp(server).once(method(Method.DELETE), uri(url));
}
 
Example #27
Source File: SecurityCommandsTest.java    From geoserver-shell with MIT License 5 votes vote down vote up
@Test public void deleteAclRestRule() throws Exception {
    String url = "/geoserver/rest/security/acl/rest/%2F**";
    whenHttp(server).match(delete(url)).then(stringContent("true"), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    SecurityCommands commands = new SecurityCommands();
    commands.setGeoserver(geoserver);
    boolean result = commands.deleteAclRestRule("/**");
    assertTrue(result);
    verifyHttp(server).once(method(Method.DELETE), uri(url));
}
 
Example #28
Source File: SpaceNewGoalTest.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
	 * Space creation results in the following two HTTP calls.
	 * @param _s
	 */
	private void setupMockSpaceServices(Space _s) {
		final String s_json = JacksonUtil.asJsonString(_s);
		whenHttp(server).
		match(post("/backend" + PathBuilder.spaces())).
		then(
				stringContent(s_json),
				contentType("application/json"),
				charset("UTF-8"),
				status(HttpStatus.CREATED_201));

//		expect()
//			.statusCode(201).
//			and().
//			body("spaceName", equalTo(_s.getSpaceName())).
//			when()
//			.post("/backend/spaces");

		whenHttp(server).
		match(post("/backend" + PathBuilder.goalExcecutions(null, _s, null))).
		then(
				stringContent(s_json),
				contentType("application/json"),
				charset("UTF-8"),
				status(HttpStatus.CREATED_201));
		
//		expect()
//		.statusCode(201).
//		when()
//		.post("/backend" + PathBuilder.goalExcecutions(null, _s, null));
	}
 
Example #29
Source File: SecurityCommandsTest.java    From geoserver-shell with MIT License 5 votes vote down vote up
@Test public void modifyAclLayerRule() throws Exception {
    String url = "/geoserver/rest/security/acl/layers.json";
    whenHttp(server).match(put(url)).then(stringContent("true"), status(HttpStatus.OK_200));
    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    SecurityCommands commands = new SecurityCommands();
    commands.setGeoserver(geoserver);
    boolean result = commands.modifyAclLayerRule("topp.*.w", "USER");
    assertTrue(result);
    verifyHttp(server).once(method(Method.PUT), uri(url));
}
 
Example #30
Source File: NamespaceCommandsTest.java    From geoserver-shell with MIT License 5 votes vote down vote up
@Test
public void createNamespace() throws Exception {
    whenHttp(server).match(post("/geoserver/rest/namespaces")).then(stringContent("true"), status(HttpStatus.OK_200));

    Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
    NamespaceCommands commands = new NamespaceCommands();
    commands.setGeoserver(geoserver);
    boolean actual = commands.create("topp","http://topp.org");
    assertTrue(actual);
    String expectedXml = "<namespace><prefix>topp</prefix><uri>http://topp.org</uri></namespace>";
    String actualXml = server.getCalls().get(0).getPostBody();
    assertEquals(expectedXml, actualXml);

    verifyHttp(server).once(method(Method.POST), uri("/geoserver/rest/namespaces"));
}