Skip to content

Commit

Permalink
General code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
groldan committed May 17, 2024
1 parent 8087ad6 commit bf22b4c
Show file tree
Hide file tree
Showing 47 changed files with 219 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;

import org.json.simple.parser.ParseException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -37,7 +36,7 @@ void before() {
}

@Test
void testRESTDefaultContentType() throws ParseException {
void testRESTDefaultContentType() {
ResponseEntity<String> response =
testGetRequestContentType("/gwc/rest/layers", APPLICATION_JSON);
JsonElement parsed = JsonParser.parseString(response.getBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ private void print(Component component) {
void GeoServerHomePage_smoke_test_anonymous() {
GeoServerHomePage page = tester.startPage(GeoServerHomePage.class);
assertNotNull(page);
// print(page);
tester.assertInvisible("catalogLinks");
tester.assertComponent("providedCaps", ListView.class);
}
Expand All @@ -111,7 +110,6 @@ void GeoServerHomePage_smoke_test_logged_in() {
login();
GeoServerHomePage page = tester.startPage(GeoServerHomePage.class);
assertNotNull(page);
// print(page);
tester.assertComponent("catalogLinks:layersLink", BookmarkablePageLink.class);
tester.assertComponent("catalogLinks:storesLink", BookmarkablePageLink.class);
tester.assertComponent("catalogLinks:workspacesLink", BookmarkablePageLink.class);
Expand All @@ -132,7 +130,6 @@ void GlobalSettingsPage_smoke_test() {
tester.assertRenderedPage(GlobalSettingsPage.class);
GlobalSettingsPage page = (GlobalSettingsPage) tester.getLastRenderedPage();
assertNotNull(page);
// print(page);
assertHidden("proxyBaseUrlContainer");
assertHidden("useHeadersProxyURL");
assertHidden("loggingSettingsContainer");
Expand All @@ -144,7 +141,6 @@ void GlobalSettingsPage_smoke_test() {
void GeoServerHomePage_smoke_test_service_links() {
GeoServerHomePage page = tester.startPage(GeoServerHomePage.class);
assertNotNull(page);
// print(page);
tester.assertComponent("serviceList", ServicesPanel.class);
tester.assertVisible("serviceList");
tester.assertComponent("serviceList:serviceDescriptions:0", ListItem.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import java.io.IOException;

@SpringBootTest(classes = WfsApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("pgconfigjndi")
@Testcontainers(disabledWithoutDocker = true)
Expand All @@ -35,7 +33,7 @@ class WfsApplicationPgconfigIT extends WfsApplicationTest {
* </ul>
*/
@DynamicPropertySource
static void setUpDataDir(DynamicPropertyRegistry registry) throws IOException {
static void setUpDataDir(DynamicPropertyRegistry registry) {
registry.add("pgconfig.host", container::getHost);
registry.add(
"pgconfig.port",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class EnvironmentAdminAuthenticationProviderTest {
private ApplicationContextRunner runner;

@BeforeEach
void setUp() throws Exception {
void setUp() {
runner = GeoServerSecurityAutoConfigurationTest.createContextRunner(tempDir);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class GeoServerSecurityAutoConfigurationTest {
private ApplicationContextRunner runner;

@BeforeEach
void setUp() throws Exception {
void setUp() {
runner = createContextRunner(tempDir);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -150,7 +152,7 @@ private static void addWorkspaceNamespace(String wsName) {
}

@BeforeEach
public void setupLayerGrups() throws Exception {
public void setupLayerGrups() {
LayerInfo lakes = catalog.getLayerByName(getLayerId(MockData.LAKES));
LayerInfo forests = catalog.getLayerByName(getLayerId(MockData.FORESTS));
LayerInfo roads = catalog.getLayerByName(getLayerId(MockData.ROAD_SEGMENTS));
Expand All @@ -173,7 +175,7 @@ public void setupLayerGrups() throws Exception {
}

@AfterEach
public void clearLayerGroups() throws Exception {
public void clearLayerGroups() {
CascadeDeleteVisitor remover = new CascadeDeleteVisitor(catalog);
for (LayerGroupInfo lg : catalog.getLayerGroups()) {
if (catalog.getLayerGroup(lg.getId()) != null) {
Expand All @@ -183,7 +185,7 @@ public void clearLayerGroups() throws Exception {
}

private LayerGroupInfo addLayerGroup(
String name, Mode mode, WorkspaceInfo ws, PublishedInfo... layers) throws Exception {
String name, Mode mode, WorkspaceInfo ws, PublishedInfo... layers) {
CatalogBuilder cb = new CatalogBuilder(catalog);

LayerGroupInfo group = catalog.getFactory().createLayerGroup();
Expand All @@ -198,7 +200,11 @@ private LayerGroupInfo addLayerGroup(
group.getStyles().add(null);
}
}
cb.calculateLayerGroupBounds(group);
try {
cb.calculateLayerGroupBounds(group);
} catch (Exception e) {
throw new IllegalStateException(e);
}
catalog.add(group);
if (ws != null) {
return catalog.getLayerGroupByName(ws.getName(), name);
Expand Down Expand Up @@ -247,7 +253,7 @@ void buildLayerGroupCaches() {
}

@Test
void testInitialSetup() throws Exception {
void testInitialSetup() {
// nature
Collection<LayerGroupSummary> natureContainers = cc.getContainerGroupsFor(nature);
assertEquals(1, natureContainers.size());
Expand All @@ -268,7 +274,7 @@ void testInitialSetup() throws Exception {
}

@Test
void testAddLayerToNature() throws Exception {
void testAddLayerToNature() {
LayerInfo neatline = catalog.getLayerByName(getLayerId(MockData.MAP_NEATLINE));
nature.getLayers().add(neatline);
nature.getStyles().add(null);
Expand All @@ -278,7 +284,7 @@ void testAddLayerToNature() throws Exception {
}

@Test
void testAddLayerToContainer() throws Exception {
void testAddLayerToContainer() {
LayerInfo neatline = catalog.getLayerByName(getLayerId(MockData.MAP_NEATLINE));
container.getLayers().add(neatline);
container.getStyles().add(null);
Expand All @@ -288,7 +294,7 @@ void testAddLayerToContainer() throws Exception {
}

@Test
void testRemoveLayerFromNature() throws Exception {
void testRemoveLayerFromNature() {
LayerInfo lakes = catalog.getLayerByName(getLayerId(MockData.LAKES));
nature.getLayers().remove(lakes);
nature.getStyles().remove(0);
Expand All @@ -301,7 +307,7 @@ void testRemoveLayerFromNature() throws Exception {
}

@Test
void testRemoveLayerFromContainer() throws Exception {
void testRemoveLayerFromContainer() {
LayerInfo roads = catalog.getLayerByName(getLayerId(MockData.ROAD_SEGMENTS));
container.getLayers().remove(roads);
container.getStyles().remove(0);
Expand All @@ -313,7 +319,7 @@ void testRemoveLayerFromContainer() throws Exception {
}

@Test
void testRemoveNatureFromContainer() throws Exception {
void testRemoveNatureFromContainer() {
container.getLayers().remove(nature);
container.getStyles().remove(0);
catalog.save(container);
Expand All @@ -326,7 +332,7 @@ void testRemoveNatureFromContainer() throws Exception {
}

@Test
void testRemoveAllGrups() throws Exception {
void testRemoveAllGrups() {
catalog.remove(container);
catalog.remove(nature);

Expand All @@ -337,7 +343,7 @@ void testRemoveAllGrups() throws Exception {
}

@Test
void testAddRemoveNamed() throws Exception {
void testAddRemoveNamed() {
final String NAMED_GROUP = "named";
LayerInfo neatline = catalog.getLayerByName(getLayerId(MockData.MAP_NEATLINE));
LayerInfo lakes = catalog.getLayerByName(getLayerId(MockData.LAKES));
Expand All @@ -358,7 +364,7 @@ void testAddRemoveNamed() throws Exception {
}

@Test
void testAddRemoveNestedNamed() throws Exception {
void testAddRemoveNestedNamed() {
final String NESTED_NAMED = "nestedNamed";
LayerInfo neatline = catalog.getLayerByName(getLayerId(MockData.MAP_NEATLINE));
LayerInfo lakes = catalog.getLayerByName(getLayerId(MockData.LAKES));
Expand All @@ -384,7 +390,7 @@ void testAddRemoveNestedNamed() throws Exception {
}

@Test
void testRenameGroup() throws Exception {
void testRenameGroup() {
nature.setName("renamed");
catalog.save(nature);

Expand All @@ -394,7 +400,7 @@ void testRenameGroup() throws Exception {
}

@Test
void testRenameWorkspace() throws Exception {
void testRenameWorkspace() {
WorkspaceInfo ws = catalog.getDefaultWorkspace();
ws.setName("renamed");
try {
Expand All @@ -410,7 +416,7 @@ void testRenameWorkspace() throws Exception {
}

@Test
void testChangeWorkspace() throws Exception {
void testChangeWorkspace() {
DataStoreInfo store = catalog.getDataStores().get(0);
try {
WorkspaceInfo aws = catalog.getWorkspaceByName(ANOTHER_WS);
Expand All @@ -430,7 +436,7 @@ void testChangeWorkspace() throws Exception {
}

@Test
void testChangeGroupMode() throws Exception {
void testChangeGroupMode() {
LayerGroupSummary summary = cc.groupCache.get(nature.getId());
assertEquals(Mode.SINGLE, summary.getMode());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class RemoteEventDataDirectoryProcessorTest {
GeoServerInfo global;

@BeforeEach
void setUp() throws Exception {
void setUp() {
mockFacade = mock(ExtendedCatalogFacade.class);
var catalog = mock(CatalogPlugin.class);
when(catalog.getFacade()).thenReturn(mockFacade);
Expand All @@ -84,8 +84,8 @@ void testRemoteEventDataDirectoryProcessor() {

var catalogFacade = mock(ExtendedCatalogFacade.class);
when(rawCatalog.getFacade()).thenReturn(catalogFacade);
var processor = new RemoteEventDataDirectoryProcessor(configFacade, rawCatalog);
assertSame(catalogFacade, processor.catalogFacade());
var p = new RemoteEventDataDirectoryProcessor(configFacade, rawCatalog);
assertSame(catalogFacade, p.catalogFacade());
}

@Test
Expand Down Expand Up @@ -256,8 +256,6 @@ void testOnRemoteModifyEvent_IgnoresSetDefaultEvents() {

@Test
void testOnRemoteModifyEvent_GeoServerInfo() {
GeoServerInfo global = this.global;

when(mockGeoServerFacade.getGlobal())
.thenReturn(ModificationProxy.create(global, GeoServerInfo.class));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,13 @@ protected Filter adaptMatchActionForCollectionLiteral(final BinaryComparisonOper
}

private Function<List<Filter>, Filter> createOredOrAndedBuilder(final MatchAction matchAction) {
Function<List<Filter>, Filter> aggregateBuilder;
if (matchAction == MatchAction.ALL) {
// if all of the possible combinations match, the result is true (aggregated AND)
aggregateBuilder = ff::and;
} else if (matchAction == MatchAction.ANY) {
// if any of the possible combinations match, the result is true (aggregated OR)
aggregateBuilder = ff::or;
} else {
throw new IllegalStateException();
}
return aggregateBuilder;
return switch (matchAction) {
// if all of the possible combinations match, the result is true (aggregated AND)
case ALL -> ff::and;
// if any of the possible combinations match, the result is true (aggregated OR)
case ANY -> ff::or;
default -> throw new IllegalStateException();
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,6 @@ private <S extends Info> Filter applyTypeFilter(Filter filter, Class<S> type) {
return filter;
}

private String applyTypeFilter(String sql, @NonNull Class<? extends T> type) {
if (!getContentType().equals(type)) {
String infoType = infoType(type);
sql += " AND \"@type\" = '%s'::infotype".formatted(infoType);
}
return sql;
}

protected String applyOffsetLimit(String sql, Integer offset, Integer limit) {
if (null != offset) sql += " OFFSET %d".formatted(offset);
if (null != limit) sql += " LIMIT %d".formatted(limit);
Expand Down Expand Up @@ -303,7 +295,7 @@ private Object[] prepareParams(PgconfigQueryBuilder qb) {
}

private Object asPreparedValue(Object val) {
if (val instanceof Enum e) return e.name();
if (val instanceof Enum<?> e) return e.name();
return val;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public PgconfigResource mkdirs(PgconfigResource resource) {
PgconfigResource parent = getParent(resource);
if (null == parent) return resource;
if (!parent.exists()) {
parent = (PgconfigResource) parent.mkdirs();
parent = parent.mkdirs();
}
resource.parentId = parent.getId();
resource.type = Type.DIRECTORY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void handleRemoveEvent(CatalogRemoveEvent event) {
if (source instanceof WorkspaceInfo ws) {
log.debug("Removing workspace {}", ws.getName());
rmRes(dd.get(ws));
} else if (source instanceof NamespaceInfo ns) {
} else if (source instanceof NamespaceInfo) {
// do not remove the directory, only when removing the workspace
} else if (source instanceof StoreInfo store) {
log.debug("Removing datastore {}", store.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PgconfigBackendAutoConfigurationTest {
PgconfigBackendAutoConfiguration.class));

@BeforeEach
void setUp() throws Exception {
void setUp() {
runner = container.withJdbcUrlConfig(runner);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PgconfigDataSourceAutoConfigurationTest {
String password;

@BeforeEach
void setUp() throws Exception {
void setUp() {
url = container.getJdbcUrl();
username = container.getUsername();
password = container.getPassword();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PgconfigCatalogBackendConformanceTest extends CatalogConformanceTest {

@Override
@BeforeEach
public void setUp() throws Exception {
public void setUp() {
container.setUp();
super.setUp();
}
Expand Down Expand Up @@ -94,7 +94,7 @@ LockRepository pgconfigLockRepository() {
returned ft/ft2 where mockito is not throwing the expected exception
""")
@Override
public void testSaveDataStoreRollbacksBothStoreAndResources() throws Exception {}
public void testSaveDataStoreRollbacksBothStoreAndResources() {}

static @BeforeAll void beforeAll() throws Exception {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PgconfigConfigRepositoryConformanceTest extends GeoServerConfigConformance

@Override
@BeforeEach
public void setUp() throws Exception {
public void setUp() {
container.setUp();
super.setUp();
}
Expand Down
Loading

0 comments on commit bf22b4c

Please sign in to comment.