-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a data object parameter for CollectionsApiImpl.getFeatures()
Simplify/improve tests readability
- Loading branch information
Showing
5 changed files
with
93 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...eatures/src/main/java/com/camptocamp/opendata/ogc/features/server/impl/FeaturesQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.camptocamp.opendata.ogc.features.server.impl; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Value; | ||
import lombok.With; | ||
|
||
@Value | ||
@With | ||
@RequiredArgsConstructor | ||
public class FeaturesQuery { | ||
|
||
private @NonNull String collectionId; | ||
private Integer offset; | ||
private Integer limit; | ||
private List<BigDecimal> bbox; | ||
private String datetime; | ||
private String filter; | ||
private String filterLang; | ||
|
||
public static FeaturesQuery of(String collectionId) { | ||
return new FeaturesQuery(collectionId, null, null, null, null, null, null); | ||
} | ||
|
||
public FeaturesQuery withBbox(double minx, double miny, double maxx, double maxy) { | ||
return withBbox(List.of(BigDecimal.valueOf(minx), BigDecimal.valueOf(miny), BigDecimal.valueOf(maxx), | ||
BigDecimal.valueOf(maxy))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 27 additions & 36 deletions
63
...rc/test/java/com/camptocamp/opendata/ogc/features/server/impl/CollectionsApiImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,58 @@ | ||
package com.camptocamp.opendata.ogc.features.server.impl; | ||
|
||
import com.camptocamp.opendata.ogc.features.app.OgcFeaturesApp; | ||
import com.camptocamp.opendata.ogc.features.model.FeatureCollection; | ||
import com.camptocamp.opendata.ogc.features.model.Link; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.mock.web.MockHttpServletRequest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import com.camptocamp.opendata.ogc.features.app.OgcFeaturesApp; | ||
import com.camptocamp.opendata.ogc.features.model.FeatureCollection; | ||
import com.camptocamp.opendata.ogc.features.model.Link; | ||
|
||
@SpringBootTest(classes = OgcFeaturesApp.class) | ||
@ActiveProfiles("sample-data") | ||
public class CollectionsApiImplTest extends AbstractCollectionsApiImplIT { | ||
|
||
@Test | ||
public void testGetItemsLinks() { | ||
MockHttpServletRequest mockedReq = (MockHttpServletRequest) req.getNativeRequest(); | ||
mockedReq.addParameter("f", "geojson"); | ||
mockedReq.addHeader("Accept", "application/geo+json"); | ||
actualRequest.setParameter("f", "geojson"); | ||
actualRequest.removeHeader("Accept"); | ||
actualRequest.addHeader("Accept", "application/geo+json"); | ||
|
||
ResponseEntity<FeatureCollection> response = collectionsApi.getFeatures("locations", // | ||
10, // | ||
null, // | ||
null, // | ||
null); | ||
FeaturesQuery query = FeaturesQuery.of("locations").withLimit(10); | ||
ResponseEntity<FeatureCollection> response = collectionsApi.getFeatures(query); | ||
|
||
List<Link> links = response.getBody().getLinks(); | ||
assertTrue(links.get(1).getHref().contains("f=geojson")); | ||
Link nextLink = links.stream().filter(l -> "next".equals(l.getRel())).findFirst().orElseThrow(); | ||
assertThat(nextLink.getHref()).contains("f=geojson"); | ||
} | ||
|
||
public @Test void testGetItemsLinksNoFParam() { | ||
MockHttpServletRequest mockedReq = (MockHttpServletRequest) req.getNativeRequest(); | ||
mockedReq.removeParameter("f"); | ||
mockedReq.addHeader("Accept", "application/json"); | ||
actualRequest.removeParameter("f"); | ||
actualRequest.removeHeader("Accept"); | ||
actualRequest.addHeader("Accept", "application/json"); | ||
|
||
ResponseEntity<FeatureCollection> response = collectionsApi.getFeatures("locations", // | ||
10, // | ||
null, // | ||
null, // | ||
null); | ||
FeaturesQuery query = FeaturesQuery.of("locations").withLimit(10); | ||
ResponseEntity<FeatureCollection> response = collectionsApi.getFeatures(query); | ||
|
||
List<Link> links = response.getBody().getLinks(); | ||
assertTrue(links.get(1).getHref().contains("f=json")); | ||
Link nextLink = links.stream().filter(l -> "next".equals(l.getRel())).findFirst().orElseThrow(); | ||
assertThat(nextLink.getHref()).contains("f=json"); | ||
} | ||
|
||
public @Test void testGetItemsLinksFParamAndDifferentHeaderParams() { | ||
MockHttpServletRequest mockedReq = (MockHttpServletRequest) req.getNativeRequest(); | ||
mockedReq.addParameter("f", "ooxml"); | ||
mockedReq.addHeader("Accept", "application/json"); | ||
|
||
ResponseEntity<FeatureCollection> response = collectionsApi.getFeatures("locations", // | ||
10, // | ||
null, // | ||
null, // | ||
null); | ||
actualRequest.addHeader("Accept", "application/json"); | ||
actualRequest.setParameter("f", "ooxml"); | ||
|
||
ResponseEntity<FeatureCollection> response = collectionsApi | ||
.getFeatures(FeaturesQuery.of("locations").withLimit(2)); | ||
List<Link> links = response.getBody().getLinks(); | ||
assertTrue(links.get(1).getHref().contains("f=ooxml")); | ||
Link nextLink = links.stream().filter(l -> "next".equals(l.getRel())).findFirst().orElseThrow(); | ||
assertThat(nextLink.getHref()).contains("f=ooxml"); | ||
} | ||
|
||
} |