Skip to content

Commit

Permalink
Revert "gwc - handles workspace-based paths (#380)" as it breaks inte…
Browse files Browse the repository at this point in the history
…gration tests

This reverts commit bc7cf9b.
  • Loading branch information
groldan committed Oct 8, 2024
1 parent 61d53d6 commit 4c8b016
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 513 deletions.
13 changes: 0 additions & 13 deletions src/apps/geoserver/gwc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geoserver.cloud.catalog</groupId>
<artifactId>gs-cloud-catalog-plugin</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,29 @@
package org.geoserver.cloud.gwc.app;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.MediaType.*;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_XML;

import com.google.gson.JsonElement;
import com.google.gson.JsonParser;

import org.geoserver.catalog.GeoServerCatalogTestData;
import org.geoserver.gwc.controller.GwcUrlHandlerMapping;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.beans.factory.annotation.Autowired;
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.context.ApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
class GeoWebCacheApplicationTest {

@Autowired private TestRestTemplate restTemplate;

@Autowired private ApplicationContext context;

@TempDir private static Path tmpPath;

@BeforeAll
static void initializeDatadir() throws URISyntaxException, IOException {
assertThat(tmpPath).isNotNull();
GeoServerCatalogTestData.unzipGeoserverCatalogTestData(tmpPath);
}

@DynamicPropertySource
static void dynamicProperties(DynamicPropertyRegistry registry)
throws URISyntaxException, IOException {
File tmpFilePath = tmpPath.toFile();
registry.add("geoserver.backend.data-directory.location", tmpFilePath::toString);
}

@BeforeEach
void before() {
restTemplate = restTemplate.withBasicAuth("admin", "geoserver");
Expand All @@ -81,84 +53,10 @@ void testRESTPathExtensionContentNegotiation() {
testGetRequestContentType("/gwc/rest/layers.xml", APPLICATION_XML);
}

@Test
void testGwcUrlHandlerMappingArePresentInTheClasspath() {
assertThat(context.isTypeMatch("gwcDemoUrlHandlerMapping", GwcUrlHandlerMapping.class))
.as("expected a bean gwcDemoUrlHandlerMapping of type GwcUrlHandlerMapping")
.isTrue();
assertThat(context.isTypeMatch("gwcRestWebUrlHandlerMapping", GwcUrlHandlerMapping.class))
.as("expected a bean gwcRestWebUrlHandlerMapping of type GwcUrlHandlerMapping")
.isTrue();
}

@Test
void testGeneralGwcHome() {
ResponseEntity<String> response = testGetRequestContentType("/gwc/home", TEXT_HTML);
assertThat(response.getHeaders().getContentType()).isNotEqualTo(APPLICATION_XML);
assertThat(response.getBody()).doesNotContain("ows:Exception");
}

@Test
void testGeneralGwcDemo() {
ResponseEntity<String> response = testGetRequestContentType("/gwc/demo", TEXT_HTML);
assertThat(response.getHeaders().getContentType()).isNotEqualTo(APPLICATION_XML);
assertThat(response.getBody()).doesNotContain("ows:Exception");
}

@Test
void testGeneralGwcDemoWithNameSpaceLayer() {
ResponseEntity<String> response =
testGetRequestContentType("/gwc/demo/ne:boundary_lines", TEXT_HTML);
assertThat(response.getHeaders().getContentType()).isNotEqualTo(APPLICATION_XML);
assertThat(response.getBody()).doesNotContain("ows:Exception");
}

@Test
void testGeneralGwcServiceWmts() {
ResponseEntity<String> response =
testGetRequestContentType("/gwc/service/wmts?REQUEST=GetCapabilities", TEXT_XML);
assertThat(response.getBody()).doesNotContain("ows:Exception");
}

@Test
void testGwcDemoPrefixedUrls() {
ResponseEntity<String> response = testGetRequestContentType("/ne/gwc/demo", TEXT_HTML);
assertThat(response.getHeaders().getContentType()).isNotEqualTo(APPLICATION_XML);
assertThat(response.getBody()).doesNotContain("ows:Exception");
}

@Test
void testGwcDemoWorkspacePrefixedUrlsLayer() {
ResponseEntity<String> response =
testGetRequestContentType("/ne/gwc/demo/boundary_lines", TEXT_HTML);
assertThat(response.getHeaders().getContentType()).isNotEqualTo(APPLICATION_XML);
assertThat(response.getBody()).doesNotContain("ows:Exception");
}

@Test
void testGwcDemoWorkspacePrefixedUrlsWorkspaceLayer() {
ResponseEntity<String> response =
testGetRequestContentType("/ne/gwc/demo/ne:boundary_lines", TEXT_HTML);
assertThat(response.getHeaders().getContentType()).isNotEqualTo(APPLICATION_XML);
assertThat(response.getBody()).doesNotContain("ows:Exception");
}

@Test
void testGwcServicePrefixedUrl() {
ResponseEntity<String> response =
testGetRequestContentType("/ne/gwc/service/wmts?REQUEST=GetCapabilities", TEXT_XML);
assertThat(response.getBody()).doesNotContain("ows:Exception");
}

protected ResponseEntity<String> testGetRequestContentType(String uri, MediaType expected) {
ResponseEntity<String> response = restTemplate.getForEntity(uri, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getHeaders().getContentType().isCompatibleWith(expected))
.as(
String.format(
"expected content-type %s to be compatible with %s",
response.getHeaders().getContentType(), expected))
.isTrue();
assertThat(response.getHeaders().getContentType()).isEqualTo(expected);
return response;
}
}
5 changes: 0 additions & 5 deletions src/catalog/plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@
<groupId>org.geotools</groupId>
<artifactId>gt-process-feature</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-sample-data</artifactId>
<version>${gt.version}</version>
</dependency>
<dependency>
<groupId>com.github.f4b6a3</groupId>
<artifactId>ulid-creator</artifactId>
Expand Down

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@

import lombok.extern.slf4j.Slf4j;

import org.geoserver.catalog.Catalog;
import org.geoserver.cloud.autoconfigure.gwc.ConditionalOnGeoWebCacheRestConfigEnabled;
import org.geoserver.cloud.autoconfigure.gwc.ConditionalOnWebUIEnabled;
import org.geoserver.cloud.gwc.config.core.GeoWebCacheConfigurationProperties;
import org.geoserver.cloud.virtualservice.VirtualServiceVerifier;
import org.geoserver.gwc.controller.GwcUrlHandlerMapping;
import org.geoserver.ows.Dispatcher;
import org.geowebcache.GeoWebCacheDispatcher;
import org.geowebcache.rest.controller.ByteStreamController;
import org.gwc.web.rest.GeoWebCacheController;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
Expand All @@ -32,79 +28,17 @@ public class GeoWebCacheUIAutoConfiguration {
}

@Bean
GeoWebCacheController gwcController(
Dispatcher geoserverDispatcher,
GeoWebCacheDispatcher geoWebCacheDispatcher,
VirtualServiceVerifier verifier) {
return new GeoWebCacheController(geoserverDispatcher, geoWebCacheDispatcher, verifier);
GeoWebCacheController gwcController(GeoWebCacheDispatcher gwcDispatcher) {
return new GeoWebCacheController(gwcDispatcher);
}

/** ConditionalOnGeoWebCacheRestConfigEnabled} is disabled */
/**
* Provide a handler for static web resources if missing, for example, because {@link
* ConditionalOnGeoWebCacheRestConfigEnabled} is disabled
*/
@Bean
@ConditionalOnMissingBean(ByteStreamController.class)
ByteStreamController byteStreamController() {
return new ByteStreamController();
}

@Bean
VirtualServiceVerifier virtualServiceVerifier(@Qualifier("rawCatalog") Catalog catalog) {
return new VirtualServiceVerifier(catalog);
}

/**
* GS's src/web/gwc/src/main/java/applicationContext.xml
* <!-- Used for workspace-based demo requests so the requests to GS stay workspace-based -->
* <bean id="gwcDemoUrlHandlerMapping"
* class="org.geoserver.gwc.controller.GwcUrlHandlerMapping"> <constructor-arg ref="catalog" />
* <constructor-arg value="/gwc/demo"/> <property name="alwaysUseFullPath" value="true" />
* <property name="order" value="10" /> </bean>
* <!-- Used for workspace-based web requests (i.e. for rest/web/openlayer/ol.js) -->
* <bean id="gwcRestWebUrlHandlerMapping"
* class="org.geoserver.gwc.controller.GwcUrlHandlerMapping"> <constructor-arg ref="catalog" />
* <constructor-arg type="java.lang.String" value="/gwc/rest/web"/> <property
* name="alwaysUseFullPath" value="true" /> <property name="order" value="10" /> </bean>
*/
@Bean
@Qualifier("gwcDemoUrlHandlerMapping")
GwcUrlHandlerMapping gwcDemoUrlHandlerMapping(@Qualifier("rawCatalog") Catalog catalog) {
GwcUrlHandlerMapping handler = new GwcUrlHandlerMapping(catalog, "/gwc/demo");
handler.setAlwaysUseFullPath(true);
handler.setOrder(10);

return handler;
}

/*
@Bean
WebMvcRegistrations gwcDemoUrlHandlerMappingRegistrations(
@Qualifier("gwcDemoUrlHandlerMapping") GwcUrlHandlerMapping handler) {
return new WebMvcRegistrations() {
@Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
return handler;
}
};
}*/

@Bean
@Qualifier("gwcRestWebUrlHandlerMapping")
GwcUrlHandlerMapping gwcRestWebUrlHandlerMapping(@Qualifier("rawCatalog") Catalog catalog) {
GwcUrlHandlerMapping handler = new GwcUrlHandlerMapping(catalog, "/gwc/rest/web");
handler.setAlwaysUseFullPath(true);
handler.setOrder(10);

return handler;
}

/*
@Bean
WebMvcRegistrations gwcRestWebUrlHandlerMappingRegistrations(
@Qualifier("gwcRestWebUrlHandlerMapping") GwcUrlHandlerMapping handler) {
return new WebMvcRegistrations() {
@Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
return handler;
}
};
}*/
}

This file was deleted.

Loading

0 comments on commit 4c8b016

Please sign in to comment.