-
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.
Merge pull request #11 from camptocamp/fixing-mimetypes-in-links-depe…
…nding-on-f-param-accept-header ogc-api-features - fixing links depending on the requested format
- Loading branch information
Showing
3 changed files
with
85 additions
and
1 deletion.
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
23 changes: 23 additions & 0 deletions
23
...features/src/test/java/com/camptocamp/opendata/ogc/features/http/codec/MimeTypesTest.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,23 @@ | ||
package com.camptocamp.opendata.ogc.features.http.codec; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class MimeTypesTest { | ||
|
||
public @Test void testFindByShortName() { | ||
Optional<MimeTypes> ret = MimeTypes.findByShortName("geojson"); | ||
|
||
assertTrue(ret.isPresent() && ret.get().equals(MimeTypes.GeoJSON)); | ||
} | ||
|
||
public @Test void testFindByHeader() { | ||
Optional<MimeTypes> ret = MimeTypes.find("application/json"); | ||
|
||
assertTrue(ret.isPresent() && ret.get().equals(MimeTypes.JSON)); | ||
} | ||
|
||
} |
58 changes: 57 additions & 1 deletion
58
...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,11 +1,67 @@ | ||
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 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 com.camptocamp.opendata.ogc.features.app.OgcFeaturesApp; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@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"); | ||
|
||
ResponseEntity<FeatureCollection> response = collectionsApi.getFeatures("locations", // | ||
10, // | ||
null, // | ||
null, // | ||
null); | ||
|
||
List<Link> links = response.getBody().getLinks(); | ||
assertTrue(links.get(1).getHref().contains("f=geojson")); | ||
} | ||
|
||
public @Test void testGetItemsLinksNoFParam() { | ||
MockHttpServletRequest mockedReq = (MockHttpServletRequest) req.getNativeRequest(); | ||
mockedReq.removeParameter("f"); | ||
mockedReq.addHeader("Accept", "application/json"); | ||
|
||
ResponseEntity<FeatureCollection> response = collectionsApi.getFeatures("locations", // | ||
10, // | ||
null, // | ||
null, // | ||
null); | ||
|
||
List<Link> links = response.getBody().getLinks(); | ||
assertTrue(links.get(1).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); | ||
|
||
List<Link> links = response.getBody().getLinks(); | ||
assertTrue(links.get(1).getHref().contains("f=ooxml")); | ||
} | ||
|
||
} |