Skip to content

Commit

Permalink
[GEOS-8493] Support POST for non-SLD styles
Browse files Browse the repository at this point in the history
Support POSTing non-SLD style body
Refactor StyleController to be a bit more consistent / structured. Move common code to methods.
Improve javadocs for utility methods
  • Loading branch information
tbarsballe committed Jan 24, 2018
1 parent 66b38ec commit e149eb1
Show file tree
Hide file tree
Showing 4 changed files with 442 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,29 @@ public void testRawPutJson() throws Exception {
catalog.remove(styleInfo);
}

@Test
public void testPostJson() throws Exception {
String jsonBody = newMbStyle();
Catalog cat = getCatalog();
assertNull("foo not available", cat.getStyleByName("foo"));

MockHttpServletResponse response = postAsServletResponse("/rest/styles?name=foo",jsonBody, MBStyleHandler.MIME_TYPE);
assertEquals(201, response.getStatus());

GeoServerResourceLoader resources = catalog.getResourceLoader();
Resource resource = resources.get("/styles/foo.json");
String definition = new String(resource.getContents());
assertTrue("is json", definition.contains("\"circle-color\": \"#FFFFFF\""));

StyleInfo styleInfo = catalog.getStyleByName("foo");
Style s = styleInfo.getStyle();
ByteArrayOutputStream out = new ByteArrayOutputStream();

SLDHandler handler = new SLDHandler();
handler.encode(Styles.sld(s), SLDHandler.VERSION_10, false, out);
String contentOut = new String(out.toByteArray());
assertTrue(contentOut.contains("<sld:Name>foo</sld:Name>"));
catalog.remove(styleInfo);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,33 @@ public void testRawPutCSS() throws Exception {
catalog.remove(styleInfo);
}

@Test
public void testPostCSS() throws Exception {
Catalog cat = getCatalog();
assertNull("foo not available", cat.getStyleByName("foo"));

String content = newCSS();
MockHttpServletResponse response = postAsServletResponse("/rest/styles?name=foo", content, CssHandler.MIME_TYPE);
assertEquals(201, response.getStatus());

GeoServerResourceLoader resources = catalog.getResourceLoader();

Resource resource = resources.get("/styles/foo.css");

String definition = new String(resource.getContents());
assertTrue("is css", definition.contains("stroke: red"));

StyleInfo styleInfo = catalog.getStyleByName("foo");
Style s = styleInfo.getStyle();
ByteArrayOutputStream out = new ByteArrayOutputStream();

SLDHandler handler = new SLDHandler();
handler.encode(Styles.sld(s), SLDHandler.VERSION_10, false, out);
content = new String(out.toByteArray());
assertTrue(content.contains("<sld:Name>foo</sld:Name>"));
catalog.remove(styleInfo);
}

@Test
public void testPutCSS() throws Exception {
// step 1 create style info with correct format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@ public void testRawPutYSLD() throws Exception {
assertTrue(content.contains("<sld:Name>foo</sld:Name>"));
catalog.remove(styleInfo);
}

@Test
public void testPostYSLD() throws Exception {
// step 1 create style info with correct format
Catalog cat = getCatalog();
assertNull("foo not available",cat.getStyleByName("foo"));

String content = newYSLD();
MockHttpServletResponse response = postAsServletResponse( "/rest/styles?name=foo", content, YsldHandler.MIMETYPE);
assertEquals( 201, response.getStatus() );

GeoServerResourceLoader resources = catalog.getResourceLoader();

Resource resource = resources.get("/styles/foo.yaml");

String definition = new String(resource.getContents());
assertTrue("is yaml",definition.contains("stroke-color: '#FF0000'"));

StyleInfo styleInfo = catalog.getStyleByName( "foo" );
Style s = styleInfo.getStyle();
ByteArrayOutputStream out = new ByteArrayOutputStream();

SLDHandler handler = new SLDHandler();
handler.encode(Styles.sld(s), SLDHandler.VERSION_10, false, out);
content = new String(out.toByteArray());
assertTrue(content.contains("<sld:Name>foo</sld:Name>"));
catalog.remove(styleInfo);
}

@Test
public void testPutYSLD() throws Exception {
Expand Down

0 comments on commit e149eb1

Please sign in to comment.