Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QA Improvements based on SonarCloud analysis #386

Merged
merged 33 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6d86e1b
qa: Remove public modifier from test methods
groldan Dec 2, 2023
041c18f
qa: Reorder the modifiers to comply with the Java Language Specificat…
groldan Dec 2, 2023
bec8096
qa: Pattern Matching for "instanceof" operator should be used instead…
groldan Dec 2, 2023
a0d657c
qa: JUnit5 test classes and methods should have default package visib…
groldan Dec 2, 2023
2672567
qa: Remove useless "org.mockito.ArgumentMatchers.eq(...)" invocation;…
groldan Dec 3, 2023
4641929
qa: Replace field injection by constructor injection
groldan Dec 3, 2023
a67ce34
qa: Remove commented out lines of code
groldan Dec 4, 2023
f237710
qa: JUnit5 test classes and methods should have default package visib…
groldan Dec 4, 2023
9b9b9ad
qa: Remove unused method parameters
groldan Dec 4, 2023
49fbc13
qa: Rename constants as upper-case
groldan Dec 4, 2023
391c83e
qa: Local variables should not be declared and then immediately retur…
groldan Dec 4, 2023
a205bc0
qa: Pattern Matching for "instanceof" operator should be used instead…
groldan Dec 4, 2023
ce295cd
qa: Fields in a "Serializable" class should either be transient or se…
groldan Dec 4, 2023
76b5f9b
qa: Generic exceptions should never be thrown
groldan Dec 5, 2023
ae635d2
qa: Operator "instanceof" should be used instead of "A.class.isInstan…
groldan Dec 5, 2023
a280106
qa: Redundant casts should not be used
groldan Dec 5, 2023
b3ced6f
qa: Utility classes should not have public constructors
groldan Dec 5, 2023
a27ab5c
qa: Exceptions in "throws" clauses should not be superfluous
groldan Dec 5, 2023
7dab822
qa: Remove usage of generic wildcard type in return types.
groldan Dec 5, 2023
fd12036
qa: Replace usage of 'Stream.collect(Collectors.toList())' with 'Stre…
groldan Dec 5, 2023
fe46fd4
qa: Local variables should not shadow class fields
groldan Dec 5, 2023
f77be55
qa: The diamond operator ("<>") should be used
groldan Dec 5, 2023
651dfa1
qa: String literals should not be duplicated
groldan Dec 5, 2023
02c6ce4
qa: Comma-separated labels should be used in Switch with colon case
groldan Dec 5, 2023
f6af14a
qa: Constructors of an "abstract" class should not be declared "public"
groldan Dec 5, 2023
318f2b8
qa: Raw types should not be used
groldan Dec 5, 2023
f48d1e6
qa: Subclasses that add fields to classes that override "equals" shou…
groldan Dec 5, 2023
3112e56
qa: Format strings should be used correctly
groldan Dec 5, 2023
9c2cfac
qa: Instance methods should not write to "static" fields
groldan Dec 5, 2023
9680a0e
qa: Nested "enum"s should not be declared static
groldan Dec 5, 2023
f4f5004
qa: Static non-final field names should comply with a naming convention
groldan Dec 5, 2023
3dc8033
qa: "@Override" should be used on overriding and implementing methods
groldan Dec 5, 2023
fe9da6a
qa: Lambdas should be replaced with method references
groldan Dec 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
*/
@SuppressWarnings("deprecation")
@Bean
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping(
@Qualifier("mvcContentNegotiationManager")
ContentNegotiationManager contentNegotiationManager,
Expand Down Expand Up @@ -102,17 +103,20 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha

protected ServletRequest adaptRequest(HttpServletRequest request) {
final String requestURI = request.getRequestURI();
final int restIdx = requestURI.indexOf("/rest");
final String restBasePath = "/rest";
final int restIdx = requestURI.indexOf(restBasePath);
if (restIdx > -1) {
final String pathToRest = requestURI.substring(0, restIdx + "/rest".length());
final String pathToRest = requestURI.substring(0, restIdx + restBasePath.length());
final String pathInfo = requestURI.substring(pathToRest.length());

return new HttpServletRequestWrapper(request) {
public @Override String getServletPath() {
return "/rest";
@Override
public String getServletPath() {
return restBasePath;
}

public @Override String getPathInfo() {
@Override
public String getPathInfo() {
return pathInfo;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

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

@Autowired private TestRestTemplate restTemplate;

Expand All @@ -37,15 +37,15 @@ void before() {
}

@Test
public void testRESTDefaultContentType() throws ParseException {
void testRESTDefaultContentType() throws ParseException {
ResponseEntity<String> response =
testGetRequestContentType("/gwc/rest/layers", APPLICATION_JSON);
JsonElement parsed = JsonParser.parseString(response.getBody());
assertThat(parsed.isJsonArray());
}

@Test
public void testRESTPathExtensionContentNegotiation() {
void testRESTPathExtensionContentNegotiation() {
ResponseEntity<String> response =
testGetRequestContentType("/gwc/rest/layers.json", APPLICATION_JSON);
JsonElement parsed = JsonParser.parseString(response.getBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
* https://github.com/spring-projects/spring-framework/issues/24179}
*/
@Bean
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping(
@Qualifier("mvcContentNegotiationManager")
ContentNegotiationManager contentNegotiationManager,
Expand All @@ -68,8 +69,6 @@ public RequestMappingHandlerMapping requestMappingHandlerMapping(

handlerMapping.setUseSuffixPatternMatch(true);
handlerMapping.setUseRegisteredSuffixPatternMatch(true);
// handlerMapping.setUseTrailingSlashMatch(true);
// handlerMapping.setAlwaysUseFullPath(true);

return handlerMapping;
}
Expand Down Expand Up @@ -98,17 +97,20 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha

protected ServletRequest adaptRequest(HttpServletRequest request) {
final String requestURI = request.getRequestURI();
final int restIdx = requestURI.indexOf("/rest");
final String restBasePath = "/rest";
final int restIdx = requestURI.indexOf(restBasePath);
if (restIdx > -1) {
final String pathToRest = requestURI.substring(0, restIdx + "/rest".length());
final String pathToRest = requestURI.substring(0, restIdx + restBasePath.length());
final String pathInfo = requestURI.substring(pathToRest.length());

return new HttpServletRequestWrapper(request) {
public @Override String getServletPath() {
return "/rest";
@Override
public String getServletPath() {
return restBasePath;
}

public @Override String getPathInfo() {
@Override
public String getPathInfo() {
return pathInfo;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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

@Autowired private TestRestTemplate restTemplate;

Expand All @@ -33,14 +33,14 @@ void before() {
}

@Test
public void testDefaultContentType() {
void testDefaultContentType() {

testPathExtensionContentType("/rest/workspaces", APPLICATION_JSON);
testPathExtensionContentType("/rest/layers", APPLICATION_JSON);
}

@Test
public void testPathExtensionContentNegotiation() {
void testPathExtensionContentNegotiation() {

testPathExtensionContentType("/rest/styles/line.json", APPLICATION_JSON);
testPathExtensionContentType("/rest/styles/line.xml", APPLICATION_XML);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
*/
package org.geoserver.cloud.wcs;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import org.geoserver.cloud.virtualservice.VirtualServiceVerifier;
import org.geoserver.ows.Dispatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -16,13 +18,14 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RequiredArgsConstructor
public @Controller class WCSController {

private @Autowired Dispatcher geoserverDispatcher;
private final @NonNull Dispatcher geoserverDispatcher;

private @Autowired org.geoserver.ows.ClasspathPublisher classPathPublisher;
private final @NonNull org.geoserver.ows.ClasspathPublisher classPathPublisher;

private @Autowired VirtualServiceVerifier virtualServiceVerifier;
private final @NonNull VirtualServiceVerifier virtualServiceVerifier;

@GetMapping("/")
public RedirectView redirectRootToGetCapabilities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
*/
package org.geoserver.cloud.wcs;

import org.geoserver.catalog.Catalog;
import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader;
import org.geoserver.cloud.virtualservice.VirtualServiceVerifier;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
Expand All @@ -22,7 +24,7 @@
public class WcsApplicationConfiguration {

@Bean
VirtualServiceVerifier virtualServiceVerifier() {
return new VirtualServiceVerifier();
VirtualServiceVerifier virtualServiceVerifier(@Qualifier("rawCatalog") Catalog catalog) {
return new VirtualServiceVerifier(catalog);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

@SpringBootTest
@ActiveProfiles("test")
public class WcsApplicationTest {
class WcsApplicationTest {

@Test
public void contextLoads() {}
void contextLoads() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,21 @@ TestWfsPost testWfsPostServlet() {
@Bean
ServletRegistrationBean<GeoServerWicketServlet> geoServerWicketServletRegistration() {
GeoServerWicketServlet servlet = geoServerWicketServlet();
ServletRegistrationBean<GeoServerWicketServlet> registration;
registration =
new ServletRegistrationBean<GeoServerWicketServlet>(servlet, "/web", "/web/*");

return registration;
return new ServletRegistrationBean<>(servlet, "/web", "/web/*");
}

/** Register the {@link TestWfsPost servlet} */
@Bean
ServletRegistrationBean<TestWfsPost> wfsTestServletRegistration() {
TestWfsPost servlet = testWfsPostServlet();
ServletRegistrationBean<TestWfsPost> registration;
registration = new ServletRegistrationBean<TestWfsPost>(servlet, "/TestWfsPost");

return registration;
return new ServletRegistrationBean<>(servlet, "/TestWfsPost");
}

@Bean
HeaderContribution geoserverCloudCssTheme() {
HeaderContribution contribution = new HeaderContribution();
contribution.setScope(GeoServerBasePage.class);
contribution.setCSSFilename("geoserver-cloud.css");
// contribution.setFaviconFilename("favicon.ico");
return contribution;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
package org.geoserver.cloud.autoconfigure.web.core;

import lombok.extern.slf4j.Slf4j;

import org.geoserver.cloud.autoconfigure.core.GeoServerWebMvcMainAutoConfiguration;
import org.geoserver.cloud.autoconfigure.web.demo.DemosAutoConfiguration;
import org.geoserver.cloud.autoconfigure.web.extension.ExtensionsAutoConfiguration;
Expand All @@ -15,16 +13,11 @@
import org.geoserver.cloud.autoconfigure.web.wfs.WfsAutoConfiguration;
import org.geoserver.cloud.autoconfigure.web.wms.WmsAutoConfiguration;
import org.geoserver.cloud.autoconfigure.web.wps.WpsAutoConfiguration;
import org.geoserver.config.GeoServer;
import org.geoserver.config.GeoServerInfo;
import org.geoserver.config.GeoServerInfo.WebUIMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;

import javax.annotation.PostConstruct;

@AutoConfiguration(after = {GeoServerWebMvcMainAutoConfiguration.class})
@Import({ //
WebCoreConfiguration.class, // this one is mandatory
Expand All @@ -37,27 +30,10 @@
DemosAutoConfiguration.class,
ToolsAutoConfiguration.class
})
@Slf4j
public class WebUIApplicationAutoConfiguration {

private @Autowired GeoServer geoServer;
private @Autowired Environment environment;

public @PostConstruct void setDefaults() {
GeoServerInfo global = geoServer.getGlobal();
WebUIMode webUIMode = global.getWebUIMode();
if (!WebUIMode.DO_NOT_REDIRECT.equals(webUIMode)) {
log.info("Forcing web-ui mode to DO_NOT_REDIRECT, was {}", webUIMode);
global.setWebUIMode(WebUIMode.DO_NOT_REDIRECT);
geoServer.save(global);
}

Boolean hidefs =
environment.getProperty(
"geoserver.web-ui.file-browser.hide-file-system", Boolean.class);
if (Boolean.TRUE.equals(hidefs)) {
log.info("Setting GEOSERVER_FILEBROWSER_HIDEFS=true System Property");
System.setProperty("GEOSERVER_FILEBROWSER_HIDEFS", "true");
}
@Bean
WebUIInitializer webUIDefaultsInitializer(Environment env) {
return new WebUIInitializer(env);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* (c) 2020 Open Source Geospatial Foundation - all rights reserved This code is licensed under the
* GPL 2.0 license, available at the root application directory.
*/
package org.geoserver.cloud.autoconfigure.web.core;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.geoserver.config.GeoServer;
import org.geoserver.config.GeoServerInfo;
import org.geoserver.config.GeoServerInfo.WebUIMode;
import org.geoserver.config.GeoServerInitializer;
import org.springframework.core.env.Environment;

@Slf4j
@RequiredArgsConstructor
class WebUIInitializer implements GeoServerInitializer {

private final @NonNull Environment environment;

@Override
public void initialize(GeoServer geoServer) throws Exception {
GeoServerInfo global = geoServer.getGlobal();
WebUIMode webUIMode = global.getWebUIMode();
if (!WebUIMode.DO_NOT_REDIRECT.equals(webUIMode)) {
log.info("Forcing web-ui mode to DO_NOT_REDIRECT, was {}", webUIMode);
global.setWebUIMode(WebUIMode.DO_NOT_REDIRECT);
geoServer.save(global);
}

Boolean hidefs =
environment.getProperty(
"geoserver.web-ui.file-browser.hide-file-system", Boolean.class);
if (Boolean.TRUE.equals(hidefs)) {
log.info("Setting GEOSERVER_FILEBROWSER_HIDEFS=true System Property");
System.setProperty("GEOSERVER_FILEBROWSER_HIDEFS", "true");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
package org.geoserver.cloud.autoconfigure.web.demo;

import lombok.Getter;

import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration;
import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand All @@ -27,5 +25,8 @@ public class DemoRequestsConfiguration extends AbstractWebUIAutoConfiguration {

static final String CONFIG_PREFIX = DemosAutoConfiguration.CONFIG_PREFIX + ".demo-requests";

private final @Getter String configPrefix = CONFIG_PREFIX;
@Override
public String getConfigPrefix() {
return CONFIG_PREFIX;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
package org.geoserver.cloud.autoconfigure.web.demo;

import lombok.Getter;

import org.geoserver.cloud.autoconfigure.web.core.AbstractWebUIAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -31,5 +29,8 @@ public class DemosAutoConfiguration extends AbstractWebUIAutoConfiguration {

static final String CONFIG_PREFIX = "geoserver.web-ui.demos";

private final @Getter String configPrefix = CONFIG_PREFIX;
@Override
public String getConfigPrefix() {
return CONFIG_PREFIX;
}
}
Loading
Loading