|
| 1 | +package org.geoserver.shell; |
| 2 | + |
| 3 | +import org.glassfish.grizzly.http.Method; |
| 4 | +import org.glassfish.grizzly.http.util.HttpStatus; |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +import java.io.File; |
| 8 | +import java.util.List; |
| 9 | +import java.util.Map; |
| 10 | + |
| 11 | +import static com.xebialabs.restito.builder.stub.StubHttp.whenHttp; |
| 12 | +import static com.xebialabs.restito.builder.verify.VerifyHttp.verifyHttp; |
| 13 | +import static com.xebialabs.restito.semantics.Action.status; |
| 14 | +import static com.xebialabs.restito.semantics.Action.stringContent; |
| 15 | +import static com.xebialabs.restito.semantics.Condition.*; |
| 16 | +import static junit.framework.Assert.assertEquals; |
| 17 | +import static junit.framework.Assert.assertTrue; |
| 18 | + |
| 19 | +public class WorldImageCommandsTest extends BaseTest { |
| 20 | + |
| 21 | + @Test |
| 22 | + public void zipWorldImae() throws Exception { |
| 23 | + WorldImageCommands commands = new WorldImageCommands(); |
| 24 | + File file = getResourceFile("raster.jpg"); |
| 25 | + File zipFile = File.createTempFile("raster", ".zip"); |
| 26 | + boolean result = commands.zip(file, zipFile); |
| 27 | + assertTrue(result); |
| 28 | + List<String> names = getFileNamesFromZip(zipFile); |
| 29 | + assertEquals(3, names.size()); |
| 30 | + assertTrue(names.contains("raster.jpg")); |
| 31 | + assertTrue(names.contains("raster.jgw")); |
| 32 | + assertTrue(names.contains("raster.prj")); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void uploadWorldImage() throws Exception { |
| 37 | + String workspace = "nurc"; |
| 38 | + String coverageStore = "terrain"; |
| 39 | + File file = getResourceFile("coverageStore.xml"); |
| 40 | + String coverage = "myterrain"; |
| 41 | + String url = "/geoserver/rest/workspaces/nurc/coveragestores/terrain/file.worldimage"; |
| 42 | + whenHttp(server).match(put(url)).then(stringContent("true"), status(HttpStatus.OK_200)); |
| 43 | + Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver"); |
| 44 | + WorldImageCommands commands = new WorldImageCommands(); |
| 45 | + commands.setGeoserver(geoserver); |
| 46 | + boolean result = commands.publish(workspace, coverageStore, file, coverage); |
| 47 | + assertTrue(result); |
| 48 | + String body = server.getCalls().get(0).getPostBody(); |
| 49 | + String contentType = server.getCalls().get(0).getContentType(); |
| 50 | + assertEquals("application/zip", contentType); |
| 51 | + Map<String, String[]> params = server.getCalls().get(0).getParameters(); |
| 52 | + assertEquals("first", params.get("configure")[0]); |
| 53 | + assertEquals(coverage, params.get("coverageName")[0]); |
| 54 | + verifyHttp(server).once(method(Method.PUT), uri(url)); |
| 55 | + } |
| 56 | +} |
0 commit comments