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..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 @@ -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 deleted file mode 100644 index b32bdc3..0000000 --- a/src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigMock.java +++ /dev/null @@ -1,40 +0,0 @@ -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; -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 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; - } -} diff --git a/src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigSpy.java b/src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigSpy.java new file mode 100644 index 0000000..44ae880 --- /dev/null +++ b/src/test/java/edu/kit/scc/dem/wapsrv/app/WapServerConfigSpy.java @@ -0,0 +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 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)) 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