Skip to content

Commit

Permalink
Merge pull request #395 from groldan/qa/empty_tests
Browse files Browse the repository at this point in the history
Complete tests with missing assertions
  • Loading branch information
groldan authored Dec 11, 2023
2 parents 496929c + 1e87cb5 commit b6a4a1d
Show file tree
Hide file tree
Showing 15 changed files with 331 additions and 101 deletions.
15 changes: 15 additions & 0 deletions src/apps/geoserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,20 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-matchers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-assertj3</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,123 @@
*/
package org.geoserver.cloud.wcs;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ActiveProfiles;

import java.util.stream.Stream;

@SpringBootTest
@ActiveProfiles("test")
class WcsApplicationTest {
protected @Autowired ConfigurableApplicationContext context;

@Test
void testWcsCoreBeans() {
expectBean("legacyWcsLoader", org.geoserver.wcs.WCSLoader.class);
expectBean("wcsLoader", org.geoserver.wcs.WCSXStreamLoader.class);
expectBean("wcsFactoryExtension", org.geoserver.wcs.WCSFactoryExtension.class);
expectBean("wcsURLMapping", org.geoserver.ows.OWSHandlerMapping.class);
expectBean("wcsLocalWorkspaceURLManger", org.geoserver.ows.LocalWorkspaceURLMangler.class);
expectBean("cqlKvpParser", org.geoserver.ows.kvp.CQLFilterKvpParser.class);
expectBean(
"coverageResponseDelegateFactory",
org.geoserver.wcs.responses.CoverageResponseDelegateFinder.class);
expectBean(
"geotiffCoverageResponseDelegate",
org.geoserver.wcs.responses.GeoTIFFCoverageResponseDelegate.class);
expectBean(
"imgCoverageResponseDelegate",
org.geoserver.wcs.responses.IMGCoverageResponseDelegate.class);
expectBean(
"debugCoverageResponseDelegate",
org.geoserver.wcs.responses.DebugCoverageResponseDelegate.class);
expectBean("coverageCleaner", org.geoserver.wcs.CoverageCleanerCallback.class);
expectBean("wcsResourceVoter", org.geoserver.wcs.WCSResourceVoter.class);
expectBean("legacyWcsLoader", org.geoserver.wcs.WCSLoader.class);
expectBean("wcsLoader", org.geoserver.wcs.WCSXStreamLoader.class);
expectBean("wcsFactoryExtension", org.geoserver.wcs.WCSFactoryExtension.class);
expectBean("wcsURLMapping", org.geoserver.ows.OWSHandlerMapping.class);
expectBean("wcsLocalWorkspaceURLManger", org.geoserver.ows.LocalWorkspaceURLMangler.class);
expectBean("cqlKvpParser", org.geoserver.ows.kvp.CQLFilterKvpParser.class);
expectBean(
"coverageResponseDelegateFactory",
org.geoserver.wcs.responses.CoverageResponseDelegateFinder.class);
expectBean(
"geotiffCoverageResponseDelegate",
org.geoserver.wcs.responses.GeoTIFFCoverageResponseDelegate.class);
expectBean(
"imgCoverageResponseDelegate",
org.geoserver.wcs.responses.IMGCoverageResponseDelegate.class);
expectBean(
"debugCoverageResponseDelegate",
org.geoserver.wcs.responses.DebugCoverageResponseDelegate.class);
expectBean("coverageCleaner", org.geoserver.wcs.CoverageCleanerCallback.class);
expectBean("wcsResourceVoter", org.geoserver.wcs.WCSResourceVoter.class);
}

@Test
void contextLoads() {}
void testBeansWcs_1_0() {
expectBeans(
"wcs100ServiceTarget",
"wcsLogger",
"wcs100Service",
"wcsService-1.0.0",
"wcs100ExceptionHandler",
"wcs100AxisSubsetKvpParser",
"wcs100BBoxKvpParser",
"wcs100InterpolationKvpParser",
"wcs100CoverageKvpParser",
"wcs100SourceCoverageKvpParser",
"wcs100SectionKvpParser",
"wcs100TimeKvpParser",
"wcs100ElevationKvpParser",
"wcs100GetCapabilitiesKvpReader",
"wcs100DescribeCoverageKvpReader",
"wcs100GetCoverageRequestReader",
"wcs-1.0.0-configuration",
"wcs100CapabilitiesRequestReader",
"wcs100DescribeCoverageRequestReader",
"wcs100GetCoverageRequestXMLReader",
"wcs100GetCapabilitiesResponse",
"wcs100DescribeCoverageResponse",
"wcs100GetCoverageResponse",
"workspaceQualifier",
"wcs100ServiceTarget",
"wcsLogger",
"wcs100Service",
"wcsService-1.0.0",
"wcs100ExceptionHandler",
"wcs100AxisSubsetKvpParser",
"wcs100BBoxKvpParser",
"wcs100InterpolationKvpParser",
"wcs100CoverageKvpParser",
"wcs100SourceCoverageKvpParser",
"wcs100SectionKvpParser",
"wcs100TimeKvpParser",
"wcs100ElevationKvpParser",
"wcs100GetCapabilitiesKvpReader",
"wcs100DescribeCoverageKvpReader",
"wcs100GetCoverageRequestReader",
"wcs-1.0.0-configuration",
"wcs100CapabilitiesRequestReader",
"wcs100DescribeCoverageRequestReader",
"wcs100GetCoverageRequestXMLReader",
"wcs100GetCapabilitiesResponse",
"wcs100DescribeCoverageResponse",
"wcs100GetCoverageResponse",
"workspaceQualifier");
}

protected void expectBeans(String... names) {
Stream.of(names).forEach(name -> assertThat(context.getBean(name)).isNotNull());
}

protected void expectBean(String name, Class<?> type) {
assertThat(context.getBean(name)).isInstanceOf(type);
}
}
1 change: 1 addition & 0 deletions src/apps/geoserver/wfs/src/main/resources/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ spring:
name: wfs-service
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration
- org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
- org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration
- org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,57 @@
package org.geoserver.cloud.wfs.app;

import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.xmlunit.assertj3.XmlAssert;

@SpringBootTest
@EnableAutoConfiguration
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;

@SpringBootTest(classes = WfsApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
class WfsApplicationTest {

static @TempDir Path tmpdir;
static Path datadir;

@DynamicPropertySource
static void setUpDataDir(DynamicPropertyRegistry registry) throws IOException {
datadir = Files.createDirectory(tmpdir.resolve("datadir"));
registry.add("geoserver.backend.data-directory.location", datadir::toAbsolutePath);
}

private TestRestTemplate restTemplate = new TestRestTemplate("admin", "geoserver");

@Test
void owsGetCapabilitiesSmokeTest(@LocalServerPort int servicePort) {
String url =
"http://localhost:%d/ows?SERVICE=WFS&REQUEST=GETCAPABILITIES&VERSION=1.1.0"
.formatted(servicePort);
String caps = restTemplate.getForObject(url, String.class);
Map<String, String> nscontext = Map.of("wfs", "http://www.opengis.net/wfs");
XmlAssert.assertThat(caps)
.withNamespaceContext(nscontext)
.hasXPath("/wfs:WFS_Capabilities");
}

@Test
void contextLoads() {}
void wfsGetCapabilitiesSmokeTest(@LocalServerPort int servicePort) {
String url =
"http://localhost:%d/wfs?SERVICE=WFS&REQUEST=GETCAPABILITIES&VERSION=1.1.0"
.formatted(servicePort);
String caps = restTemplate.getForObject(url, String.class);
Map<String, String> nscontext = Map.of("wfs", "http://www.opengis.net/wfs");
XmlAssert.assertThat(caps)
.withNamespaceContext(nscontext)
.hasXPath("/wfs:WFS_Capabilities");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ spring:
banner-mode: off
allow-bean-definition-overriding: true
allow-circular-references: true # false by default since spring-boot 2.6.0, breaks geoserver initialization
cloud.bus.enabled: false
cloud.config.enabled: false
cloud.config.discovery.enabled: false
cloud.discovery.enabled: false
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,55 @@
*/
package org.geoserver.cloud.wms.app;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.xmlunit.assertj3.XmlAssert;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;

/** See {@code src/test/resources/bootstrap-testdatadir.yml} */
@SpringBootTest(properties = "gwc.wms-integration=true")
@ActiveProfiles({"test", "testdatadir"})
@SpringBootTest(
classes = WmsApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT,
properties = {"geoserver.backend.data-directory.enabled=true", "gwc.wms-integration=true"})
@ActiveProfiles({"test"})
class WmsApplicationDataDirectoryTest extends WmsApplicationTest {

private static @TempDir File tmpDataDir;
static @TempDir Path tmpdir;
static Path datadir;

@DynamicPropertySource
static void registerPgProperties(DynamicPropertyRegistry registry) {
String datadir = tmpDataDir.getAbsolutePath();
registry.add("data_directory", () -> datadir);
registry.add("gwc.wms-integration", () -> "true");
static void setUpDataDir(DynamicPropertyRegistry registry) throws IOException {
datadir = Files.createDirectory(tmpdir.resolve("datadir"));
registry.add("geoserver.backend.data-directory.location", datadir::toAbsolutePath);
}

private String baseURL;

private TestRestTemplate restTemplate = new TestRestTemplate("admin", "geoserver");

@BeforeEach
void setUp(@LocalServerPort int servicePort) {
baseURL = "http://localhost:%d/ows".formatted(servicePort);
}

@Test
void getCapabilitiesSmokeTest() {
String url = baseURL + "?SERVICE=WMS&REQUEST=GETCAPABILITIES&VERSION=1.3.0";
String caps = restTemplate.getForObject(url, String.class);
Map<String, String> nscontext = Map.of("wms", "http://www.opengis.net/wms");
XmlAssert.assertThat(caps)
.withNamespaceContext(nscontext)
.hasXPath("/wms:WMS_Capabilities");
}
}
Loading

0 comments on commit b6a4a1d

Please sign in to comment.