Skip to content

Commit

Permalink
Fix format usage in jackson responses
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed May 28, 2018
1 parent 80929b1 commit b54ca68
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/community/wfs3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ public BaseKvpRequestReader(Class requestBean) {
@Override
public Object read(Object request, Map kvp, Map rawKvp) throws Exception {
Request dispatcherRequest = Dispatcher.REQUEST.get();
if (kvp.containsKey("f")) {
Object format = kvp.get("f");
if (kvp.containsKey("outputFormat")) {
Object format = kvp.get("outputFormat");
setFormat(kvp, rawKvp, format);
} else if (kvp.containsKey("f")) {
Object format = kvp.get("f");
setFormat(kvp, rawKvp, format);
} else if (request != null) {
// ignoring for the moment, until the HTML output formats are ready, otherwise
// it won't show up in the browser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,67 @@
*/
package org.geoserver.wfs3;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

import com.jayway.jsonpath.DocumentContext;

import net.sf.json.JSON;

import org.hamcrest.Matchers;
import org.junit.Test;
import org.w3c.dom.Document;

import java.util.List;

public class LandingPageTest extends WFS3TestSupport {

@Test
public void testLandingPageJson() throws Exception {
JSON json = getAsJSON("wfs3/");
print(json);
public void testLandingPageNoFormat() throws Exception {
DocumentContext json = getAsJSONPath("wfs3/", 200);
checkJSONLandingPage(json);
}

@Test
public void testLandingPageJSON() throws Exception {
DocumentContext json = getAsJSONPath("wfs3/?f=json", 200);
checkJSONLandingPage(json);
}

private void checkJSONLandingPage(DocumentContext json) {
assertEquals(12, (int) json.read("links.length()", Integer.class));
// check landing page links
assertJSONList(
json,
"links[?(@.type == 'application/json' && @.href =~ /.*wfs3\\/\\?.*/)].rel",
"self");
assertJSONList(
json,
"links[?(@.type != 'application/json' && @.href =~ /.*wfs3\\/\\?.*/)].rel",
"service",
"service");
// check API links
assertJSONList(
json, "links[?(@.href =~ /.*wfs3\\/api.*/)].rel", "service", "service", "service");
// check conformance links
assertJSONList(
json,
"links[?(@.href =~ /.*wfs3\\/conformance.*/)].rel",
"service",
"service",
"service");
// check collection links
assertJSONList(
json,
"links[?(@.href =~ /.*wfs3\\/collections.*/)].rel",
"service",
"service",
"service");
}

private <T> void assertJSONList(DocumentContext json, String path, T... expected) {
List<T> selfRels = json.read(path);
assertThat(selfRels, Matchers.containsInAnyOrder(expected));
}

@Test
Expand Down

0 comments on commit b54ca68

Please sign in to comment.