Skip to content

Commit

Permalink
Add test data and some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matthijsln committed Oct 10, 2024
1 parent d2148ac commit 2b10371
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,28 @@ public void createTestConfiguration() throws Exception {
"Gemeentegebied",
new GeoServiceLayerSettings().legendImageId(legend.getId().toString())))
.setPublished(true)
.setTitle("PDOK Kadaster bestuurlijke gebieden")
.setTitle("PDOK Kadaster bestuurlijke gebieden"),

Check warning on line 496 in src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java#L496

Added line #L496 was not covered by tests
new GeoService()
.setId("bestuurlijkegebieden-proxied")
.setProtocol(WMS)
.setUrl(

Check warning on line 500 in src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java#L498-L500

Added lines #L498 - L500 were not covered by tests
"https://service.pdok.nl/kadaster/bestuurlijkegebieden/wms/v1_0?service=WMS")
.setAuthorizationRules(rule)

Check warning on line 502 in src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java#L502

Added line #L502 was not covered by tests
// The service actually doesn't require authentication, but also doesn't mind it
// Just for testing that proxied services with auth are not available in public
// apps (even when logged in), in any controllers (map, proxy, features)
.setAuthentication(

Check warning on line 506 in src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java#L506

Added line #L506 was not covered by tests
new ServiceAuthentication()
.method(ServiceAuthentication.MethodEnum.PASSWORD)
.username("test")
.password("test"))
.setSettings(

Check warning on line 511 in src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java#L508-L511

Added lines #L508 - L511 were not covered by tests
new GeoServiceSettings()
// No attribution required: service is CC0
.serverType(GeoServiceSettings.ServerTypeEnum.MAPSERVER)
.useProxy(true))
.setPublished(true)
.setTitle("Bestuurlijke gebieden (proxied met auth)")

Check warning on line 517 in src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java#L514-L517

Added lines #L514 - L517 were not covered by tests
// TODO MapServer WMS "https://wms.geonorge.no/skwms1/wms.adm_enheter_historisk"
);

Expand Down Expand Up @@ -677,6 +698,27 @@ public void createTestConfiguration() throws Exception {
geoServiceRepository.save(geoService);
});

geoServiceRepository
.findById("bestuurlijkegebieden-proxied")
.ifPresent(

Check warning on line 703 in src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java#L701-L703

Added lines #L701 - L703 were not covered by tests
geoService -> {
geoService
.getSettings()
.getLayerSettings()
.put(

Check warning on line 708 in src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java#L705-L708

Added lines #L705 - L708 were not covered by tests
"Provinciegebied",
new GeoServiceLayerSettings()
.featureType(

Check warning on line 711 in src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java#L711

Added line #L711 was not covered by tests
new FeatureTypeRef()
.featureSourceId(

Check warning on line 713 in src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java#L713

Added line #L713 was not covered by tests
featureSources
.get("pdok-kadaster-bestuurlijkegebieden")
.getId())
.featureTypeName("bestuurlijkegebieden:Provinciegebied"))
.title("Provinciegebied (WFS, proxied met auth)"));
geoServiceRepository.save(geoService);
});

Check warning on line 720 in src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java#L715-L720

Added lines #L715 - L720 were not covered by tests

CatalogNode featureSourceCatalogNode =
new CatalogNode().id("feature_sources").title("Test feature sources");
rootCatalogNode.addChildrenItem(featureSourceCatalogNode.getId());
Expand Down Expand Up @@ -938,6 +980,7 @@ public void createTestConfiguration() throws Exception {
.childrenIds(
List.of(
"lyr:pdok-kadaster-bestuurlijkegebieden:Provinciegebied",
"lyr:bestuurlijkegebieden-proxied:Provinciegebied",
"lyr:pdok-kadaster-bestuurlijkegebieden:Gemeentegebied",
"lyr:snapshot-geoserver:postgis:begroeidterreindeel",
"lyr:snapshot-geoserver:sqlserver:wegdeel",
Expand All @@ -953,6 +996,16 @@ public void createTestConfiguration() throws Exception {
.serviceId("pdok-kadaster-bestuurlijkegebieden")
.layerName("Provinciegebied")
.visible(true))
// This is a layer from proxied service with auth that should also not be
// visible, but it has a feature source attached, should also be denied for
// features access and not be included in TOC
.addLayerNodesItem(

Check warning on line 1002 in src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java#L1002

Added line #L1002 was not covered by tests
new AppTreeLayerNode()
.objectType("AppTreeLayerNode")
.id("lyr:bestuurlijkegebieden-proxied:Provinciegebied")
.serviceId("bestuurlijkegebieden-proxied")
.layerName("Provinciegebied")
.visible(false))

Check warning on line 1008 in src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java#L1004-L1008

Added lines #L1004 - L1008 were not covered by tests
.addLayerNodesItem(
new AppTreeLayerNode()
.objectType("AppTreeLayerNode")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand Down Expand Up @@ -146,13 +147,54 @@ void should_contain_proxy_url() throws Exception {
username = "tm-admin",
authorities = {"admin"})
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
void should_not_contain_proxied_secured_service_layer() throws Exception {
void should_contain_proxied_secured_service_layer() throws Exception {
final String path = apiBasePath + "/app/secured/map";
mockMvc
.perform(get(path).accept(MediaType.APPLICATION_JSON).with(setServletPath(path)))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.services[?(@.title == 'Openbasiskaart (proxied)')]").exists());
.andExpect(jsonPath("$.appLayers[?(@.id == 'lyr:openbasiskaart-proxied:osm')]").exists())
.andExpect(jsonPath("$.services[?(@.id == 'openbasiskaart-proxied')]").exists());
}

@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
void should_not_contain_proxied_secured_service_layer_on_public_app() throws Exception {
final String path = apiBasePath + "/app/default/map";
mockMvc
.perform(get(path).accept(MediaType.APPLICATION_JSON).with(setServletPath(path)))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(
jsonPath("$.appLayers[?(@.id == 'lyr:openbasiskaart-proxied:osm')]").doesNotExist())
.andExpect(jsonPath("$.services[?(@.id == 'openbasiskaart-proxied')]").doesNotExist())
.andExpect(
jsonPath("$.appLayers[?(@.id == 'lyr:bestuurlijkegebieden-proxied:Provinciegebied')]")
.doesNotExist())
.andExpect(
jsonPath("$.services[?(@.id == 'bestuurlijkegebieden-proxied')]").doesNotExist());
}

@Test
@WithMockUser(
username = "tm-admin",
authorities = {"admin"})
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
void should_not_contain_proxied_secured_service_layer_on_public_app_even_when_authorized()
throws Exception {
final String path = apiBasePath + "/app/default/map";
mockMvc
.perform(get(path).accept(MediaType.APPLICATION_JSON).with(setServletPath(path)))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(
jsonPath("$.appLayers[?(@.id == 'lyr:openbasiskaart-proxied:osm')]").doesNotExist())
.andExpect(jsonPath("$.services[?(@.id == 'openbasiskaart-proxied')]").doesNotExist())
.andExpect(
jsonPath("$.appLayers[?(@.id == 'lyr:bestuurlijkegebieden-proxied:Provinciegebied')]")
.doesNotExist())
.andExpect(
jsonPath("$.services[?(@.id == 'bestuurlijkegebieden-proxied')]").doesNotExist());
}

@Test
Expand All @@ -179,14 +221,15 @@ void should_return_data_for_configured_app() throws Exception {
final String path = apiBasePath + "/app/default/map";
mockMvc
.perform(get(path).accept(MediaType.APPLICATION_JSON).with(setServletPath(path)))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.initialExtent").isMap())
.andExpect(jsonPath("$.maxExtent").isMap())
.andExpect(jsonPath("$.services").isArray())
.andExpect(jsonPath("$.appLayers").isArray())
.andExpect(jsonPath("$.appLayers[0]").isMap())
.andExpect(jsonPath("$.appLayers.length()").value(14))
.andExpect(jsonPath("$.appLayers.length()").value(19))
.andExpect(jsonPath("$.appLayers[0].hasAttributes").value(false))
.andExpect(jsonPath("$.appLayers[1].hasAttributes").value(false))
.andExpect(jsonPath("$.appLayers[4].legendImageUrl").isEmpty())
Expand Down

0 comments on commit 2b10371

Please sign in to comment.