Skip to content

Commit b0fbb58

Browse files
committed
Add WorldImageCommands unit tests
1 parent 5a7a432 commit b0fbb58

File tree

5 files changed

+88
-1
lines changed

5 files changed

+88
-1
lines changed

src/test/java/org/geoserver/shell/BaseTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
import java.io.File;
1010
import java.io.IOException;
11-
import java.net.URL;
11+
import java.util.ArrayList;
12+
import java.util.Enumeration;
13+
import java.util.List;
14+
import java.util.zip.ZipEntry;
15+
import java.util.zip.ZipFile;
1216

1317
public class BaseTest {
1418

@@ -33,4 +37,16 @@ protected String getResourceString(String path) throws IOException {
3337
return Resources.toString(Resources.getResource(path), Charsets.UTF_8);
3438
}
3539

40+
protected List<String> getFileNamesFromZip(File zipFile) throws IOException {
41+
List<String> names = new ArrayList<String>();
42+
ZipFile zip = new ZipFile(zipFile);
43+
Enumeration<? extends ZipEntry> zipEntries = zip.entries();
44+
while (zipEntries.hasMoreElements()) {
45+
ZipEntry zipEntry = zipEntries.nextElement();
46+
String name = zipEntry.getName();
47+
names.add(name);
48+
}
49+
return names;
50+
}
51+
3652
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
}

src/test/resources/raster.jgw

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
0.4
2+
0.0
3+
0.0
4+
-0.4
5+
-179.8
6+
89.8

src/test/resources/raster.jpg

12.5 KB
Loading

src/test/resources/raster.prj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
GEOGCS["WGS 84",
2+
DATUM["World Geodetic System 1984",
3+
SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]],
4+
AUTHORITY["EPSG","6326"]],
5+
PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]],
6+
UNIT["degree", 0.017453292519943295],
7+
AXIS["Geodetic longitude", EAST],
8+
AXIS["Geodetic latitude", NORTH],
9+
AUTHORITY["EPSG","4326"]]

0 commit comments

Comments
 (0)