From 53f47810d18331c5c386d69c65a0a6a91e103904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germaine=20G=C3=B6tzelmann?= Date: Wed, 15 Apr 2026 12:35:51 +0200 Subject: [PATCH 1/2] Improve config usage for tests --- .../kit/scc/dem/wapsrv/app/FusekiRunnerTest.java | 11 +++-------- .../kit/scc/dem/wapsrv/app/WapServerConfigMock.java | 13 ++----------- .../test-config/application-test.properties | 4 ++-- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/test/java/edu/kit/scc/dem/wapsrv/app/FusekiRunnerTest.java b/src/test/java/edu/kit/scc/dem/wapsrv/app/FusekiRunnerTest.java index 122b1a3..17e6a05 100644 --- a/src/test/java/edu/kit/scc/dem/wapsrv/app/FusekiRunnerTest.java +++ b/src/test/java/edu/kit/scc/dem/wapsrv/app/FusekiRunnerTest.java @@ -72,24 +72,19 @@ final void testInit() { when(wapServerConfig.getSparqlReadIp()).thenReturn("localhost"); when(wapServerConfig.getSparqlWriteIp()).thenReturn("localhost"); // test readPort > 0 || writePort > 0 - // test true || false - when(wapServerConfig.getSparqlReadPort()).thenReturn(3330); + // test with disabled write port when(wapServerConfig.getSparqlWritePort()).thenReturn(-1); objFusekiRunner.init(); objFusekiRunner.deinit(); - // test false || true + // test with disabled read port when(wapServerConfig.getSparqlReadPort()).thenReturn(-1); - when(wapServerConfig.getSparqlWritePort()).thenReturn(3331); objFusekiRunner.init(); objFusekiRunner.deinit(); - // test false || false + // test with disabled read and write port when(wapServerConfig.getSparqlReadPort()).thenReturn(-1); when(wapServerConfig.getSparqlWritePort()).thenReturn(-1); objFusekiRunner.init(); objFusekiRunner.deinit(); - // set back to default - when(wapServerConfig.getSparqlReadPort()).thenReturn(3330); - when(wapServerConfig.getSparqlWritePort()).thenReturn(3331); } /** diff --git a/src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigMock.java b/src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigMock.java index b32bdc3..c3609b5 100644 --- a/src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigMock.java +++ b/src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigMock.java @@ -1,6 +1,5 @@ package edu.kit.scc.dem.wapsrv.app; -import static org.mockito.Mockito.when; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -26,15 +25,7 @@ public class WapServerConfigMock { @Bean @Primary public WapServerConfig wapServerConfig() { - WapServerConfig wapServerConfigMock = Mockito.mock(WapServerConfig.class); - when(wapServerConfigMock.getRootContainerIri()).thenReturn("http://www.example.org/wap/"); - when(wapServerConfigMock.getDataBasePath()).thenReturn("temp/"); - when(wapServerConfigMock.getJsonLdProfileFolder()).thenReturn("temp/"); - when(wapServerConfigMock.getSparqlReadIp()).thenReturn("localhost"); - when(wapServerConfigMock.getSparqlWriteIp()).thenReturn("localhost"); - when(wapServerConfigMock.getSparqlReadPort()).thenReturn(3330); - when(wapServerConfigMock.getSparqlWritePort()).thenReturn(3331); - when(wapServerConfigMock.getJsonLdProfileFile()).thenReturn("temp/"); - return wapServerConfigMock; + WapServerConfig real = new WapServerConfig(); + return Mockito.spy(real); } } diff --git a/src/test/resources/test-config/application-test.properties b/src/test/resources/test-config/application-test.properties index 7c6dec3..5b5ca10 100644 --- a/src/test/resources/test-config/application-test.properties +++ b/src/test/resources/test-config/application-test.properties @@ -9,7 +9,7 @@ WebClientFolder=webcontent JsonLdProfileFolder=profiles SparqlReadIp=* EnableContentNegotiation=true -SparqlReadPort=4330 +SparqlReadPort=44330 Hostname=localhost WapIp=localhost EnableMandatoryLabelInContainers=false @@ -18,7 +18,7 @@ EnableHttps=false JsonLdFrameFolder=./profiles JsonLdValidator_SchemaFolder=./schemas SimpleFormatters=NTRIPLES*application/n-triples|RDF_JSON*application/rdf+json -SparqlWritePort=4331 +SparqlWritePort=44331 SparqlWriteIp=localhost PageSize=20 MultipleAnnotationPost=true From 3611a03413d4aae3856aa4d8a419ac3470e8af31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germaine=20G=C3=B6tzelmann?= Date: Wed, 15 Apr 2026 13:09:43 +0200 Subject: [PATCH 2/2] WapServerConfigMock renamed appropriately --- .../scc/dem/wapsrv/app/FusekiRunnerTest.java | 2 +- ...onfigMock.java => WapServerConfigSpy.java} | 62 +++++++++---------- .../service/AbstractWapServiceTest.java | 5 +- .../service/ContainerServiceImplTest.java | 4 +- 4 files changed, 36 insertions(+), 37 deletions(-) rename src/test/java/edu/kit/scc/dem/wapsrv/app/{WapServerConfigMock.java => WapServerConfigSpy.java} (88%) diff --git a/src/test/java/edu/kit/scc/dem/wapsrv/app/FusekiRunnerTest.java b/src/test/java/edu/kit/scc/dem/wapsrv/app/FusekiRunnerTest.java index 17e6a05..9fc7433 100644 --- a/src/test/java/edu/kit/scc/dem/wapsrv/app/FusekiRunnerTest.java +++ b/src/test/java/edu/kit/scc/dem/wapsrv/app/FusekiRunnerTest.java @@ -22,7 +22,7 @@ * @version 1.1 */ @ExtendWith(SpringExtension.class) -@SpringBootTest(classes = {FusekiRunner.class, JenaDataBase.class, WapServerConfigMock.class}) +@SpringBootTest(classes = {FusekiRunner.class, JenaDataBase.class, WapServerConfigSpy.class}) @ActiveProfiles("test") class FusekiRunnerTest { @Autowired diff --git a/src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigMock.java b/src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigSpy.java similarity index 88% rename from src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigMock.java rename to src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigSpy.java index c3609b5..44ae880 100644 --- a/src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigMock.java +++ b/src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigSpy.java @@ -1,31 +1,31 @@ -package edu.kit.scc.dem.wapsrv.app; - -import org.mockito.Mockito; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.Profile; - -/** - * @author Matthias Dressel - * @author Michael Hitzker - * @author Markus Hoefler - * @author Andreas Loeffler - * @author Timo Schmidt - * @version 1.1 - */ -@Configuration -@Profile("test") -public class WapServerConfigMock { - /** - * Providing a fake WapServerConfig for testing. Separate class to work with spring @autowired. - * - * @return WapServerConfig mock - */ - @Bean - @Primary - public WapServerConfig wapServerConfig() { - WapServerConfig real = new WapServerConfig(); - return Mockito.spy(real); - } -} +package edu.kit.scc.dem.wapsrv.app; + +import org.mockito.Mockito; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; + +/** + * @author Matthias Dressel + * @author Michael Hitzker + * @author Markus Hoefler + * @author Andreas Loeffler + * @author Timo Schmidt + * @version 1.1 + */ +@Configuration +@Profile("test") +public class WapServerConfigSpy { + /** + * Providing a fake WapServerConfig for testing. Separate class to work with spring @autowired. + * + * @return WapServerConfig spy + */ + @Bean + @Primary + public WapServerConfig wapServerConfig() { + WapServerConfig real = new WapServerConfig(); + return Mockito.spy(real); + } +} diff --git a/src/test/java/edu/kit/scc/dem/wapsrv/service/AbstractWapServiceTest.java b/src/test/java/edu/kit/scc/dem/wapsrv/service/AbstractWapServiceTest.java index 0f3fd8c..48522e0 100644 --- a/src/test/java/edu/kit/scc/dem/wapsrv/service/AbstractWapServiceTest.java +++ b/src/test/java/edu/kit/scc/dem/wapsrv/service/AbstractWapServiceTest.java @@ -22,7 +22,7 @@ import edu.kit.scc.dem.wapsrv.app.EtagFactory; import edu.kit.scc.dem.wapsrv.app.EtagFactoryMock; import edu.kit.scc.dem.wapsrv.app.WapServerConfig; -import edu.kit.scc.dem.wapsrv.app.WapServerConfigMock; +import edu.kit.scc.dem.wapsrv.app.WapServerConfigSpy; import edu.kit.scc.dem.wapsrv.model.Container; import edu.kit.scc.dem.wapsrv.model.ModelFactory; import edu.kit.scc.dem.wapsrv.model.Page; @@ -38,7 +38,6 @@ import edu.kit.scc.dem.wapsrv.model.validators.ValidatorRegistry; import edu.kit.scc.dem.wapsrv.repository.CollectedRepository; import edu.kit.scc.dem.wapsrv.repository.RepositoryMock; -import edu.kit.scc.dem.wapsrv.repository.jena.JenaRepository; import edu.kit.scc.dem.wapsrv.testscommon.ModelFactoryMock; import org.springframework.context.annotation.ComponentScan; @@ -55,7 +54,7 @@ @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @ExtendWith(SpringExtension.class) @SpringBootTest(classes = {ContainerServiceImpl.class, RepositoryMock.class, ModelFactoryMock.class, - EtagFactoryMock.class, JsonLdProfileRegistry.class, ValidatorRegistry.class, WapServerConfigMock.class, + EtagFactoryMock.class, JsonLdProfileRegistry.class, ValidatorRegistry.class, WapServerConfigSpy.class, JsonLdValidator.class, Validator.class}) @ExtendWith(HoverflyExtension.class) @HoverflySimulate(source = @HoverflySimulate.Source(value = "w3c_simulation.json", type = HoverflySimulate.SourceType.DEFAULT_PATH)) diff --git a/src/test/java/edu/kit/scc/dem/wapsrv/service/ContainerServiceImplTest.java b/src/test/java/edu/kit/scc/dem/wapsrv/service/ContainerServiceImplTest.java index 611a4c5..05781fa 100644 --- a/src/test/java/edu/kit/scc/dem/wapsrv/service/ContainerServiceImplTest.java +++ b/src/test/java/edu/kit/scc/dem/wapsrv/service/ContainerServiceImplTest.java @@ -30,7 +30,7 @@ import edu.kit.scc.dem.wapsrv.app.EtagFactory; import edu.kit.scc.dem.wapsrv.app.EtagFactoryMock; import edu.kit.scc.dem.wapsrv.app.WapServerConfig; -import edu.kit.scc.dem.wapsrv.app.WapServerConfigMock; +import edu.kit.scc.dem.wapsrv.app.WapServerConfigSpy; import edu.kit.scc.dem.wapsrv.exceptions.ContainerNotEmptyException; import edu.kit.scc.dem.wapsrv.exceptions.InvalidContainerException; import edu.kit.scc.dem.wapsrv.exceptions.ResourceDeletedException; @@ -66,7 +66,7 @@ // @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) @ExtendWith(SpringExtension.class) @SpringBootTest(classes = {ContainerServiceImpl.class, RepositoryMock.class, ModelFactoryMock.class, - EtagFactoryMock.class, JsonLdProfileRegistry.class, ValidatorRegistry.class, WapServerConfigMock.class, + EtagFactoryMock.class, JsonLdProfileRegistry.class, ValidatorRegistry.class, WapServerConfigSpy.class, JsonLdValidator.class, Validator.class}) @ExtendWith(HoverflyExtension.class) @HoverflySimulate(source = @HoverflySimulate.Source(value = "w3c_simulation.json", type = HoverflySimulate.SourceType.DEFAULT_PATH))