diff --git a/webapi/src/it/scala/org/knora/webapi/CoreSpec.scala b/webapi/src/it/scala/org/knora/webapi/CoreSpec.scala index d83f943cdf..8c9d6c67f3 100644 --- a/webapi/src/it/scala/org/knora/webapi/CoreSpec.scala +++ b/webapi/src/it/scala/org/knora/webapi/CoreSpec.scala @@ -43,7 +43,7 @@ abstract class CoreSpec * The effect layers from which the App is built. * Can be overriden in specs that need other implementations. */ - lazy val effectLayers = core.LayersTest.defaultLayersTestWithoutSipi + lazy val effectLayers = core.LayersTest.integrationTestsWithFusekiTestcontainers() /** * `Bootstrap` will ensure that everything is instantiated when the Runtime is created diff --git a/webapi/src/it/scala/org/knora/webapi/E2ESpec.scala b/webapi/src/it/scala/org/knora/webapi/E2ESpec.scala index 2d7e38398e..a076f851bf 100644 --- a/webapi/src/it/scala/org/knora/webapi/E2ESpec.scala +++ b/webapi/src/it/scala/org/knora/webapi/E2ESpec.scala @@ -67,7 +67,7 @@ abstract class E2ESpec * The effect layers from which the App is built. * Can be overriden in specs that need other implementations. */ - lazy val effectLayers = core.LayersTest.defaultLayersTestWithoutSipi + lazy val effectLayers = core.LayersTest.integrationTestsWithFusekiTestcontainers() /** * `Bootstrap` will ensure that everything is instantiated when the Runtime is created diff --git a/webapi/src/it/scala/org/knora/webapi/ITKnoraLiveSpec.scala b/webapi/src/it/scala/org/knora/webapi/ITKnoraLiveSpec.scala index 9b0055f466..0a45947be3 100644 --- a/webapi/src/it/scala/org/knora/webapi/ITKnoraLiveSpec.scala +++ b/webapi/src/it/scala/org/knora/webapi/ITKnoraLiveSpec.scala @@ -59,7 +59,7 @@ abstract class ITKnoraLiveSpec * The effect layers from which the App is built. * Can be overriden in specs that need other implementations. */ - lazy val effectLayers = core.LayersTest.defaultLayersTestWithSipi + lazy val effectLayers = core.LayersTest.integrationTestsWithSipiAndFusekiTestcontainers /** * `Bootstrap` will ensure that everything is instantiated when the Runtime is created diff --git a/webapi/src/it/scala/org/knora/webapi/R2RSpec.scala b/webapi/src/it/scala/org/knora/webapi/R2RSpec.scala index b24687e37f..a7a7875020 100644 --- a/webapi/src/it/scala/org/knora/webapi/R2RSpec.scala +++ b/webapi/src/it/scala/org/knora/webapi/R2RSpec.scala @@ -50,7 +50,7 @@ abstract class R2RSpec * The effect layers from which the App is built. * Can be overriden in specs that need other implementations. */ - lazy val effectLayers = core.LayersTest.defaultLayersTestWithoutSipi(system) + lazy val effectLayers = core.LayersTest.integrationTestsWithFusekiTestcontainers(Some(system)) /** * `Bootstrap` will ensure that everything is instantiated when the Runtime is created diff --git a/webapi/src/it/scala/org/knora/webapi/core/LayersTest.scala b/webapi/src/it/scala/org/knora/webapi/core/LayersTest.scala index 1cef56af8d..5a13f322df 100644 --- a/webapi/src/it/scala/org/knora/webapi/core/LayersTest.scala +++ b/webapi/src/it/scala/org/knora/webapi/core/LayersTest.scala @@ -1,15 +1,21 @@ package org.knora.webapi.core +import zio.ULayer import zio.ZLayer + import org.knora.webapi.auth.JWTService +import org.knora.webapi.config.AppConfig import org.knora.webapi.config.AppConfigForTestContainers import org.knora.webapi.routing.ApiRoutes import org.knora.webapi.store.cache.CacheServiceManager +import org.knora.webapi.store.cache.api.CacheService import org.knora.webapi.store.cache.impl.CacheServiceInMemImpl import org.knora.webapi.store.iiif.IIIFServiceManager +import org.knora.webapi.store.iiif.api.IIIFService import org.knora.webapi.store.iiif.impl.IIIFServiceMockImpl import org.knora.webapi.store.iiif.impl.IIIFServiceSipiImpl import org.knora.webapi.store.triplestore.TriplestoreServiceManager +import org.knora.webapi.store.triplestore.api.TriplestoreService import org.knora.webapi.store.triplestore.impl.TriplestoreServiceHttpConnectorImpl import org.knora.webapi.store.triplestore.upgrade.RepositoryUpdater import org.knora.webapi.testcontainers.FusekiTestContainer @@ -24,129 +30,74 @@ object LayersTest { type DefaultTestEnvironmentWithoutSipi = LayersLive.DspEnvironmentLive with FusekiTestContainer with TestClientService type DefaultTestEnvironmentWithSipi = DefaultTestEnvironmentWithoutSipi with SipiTestContainer - /** - * All live layers with both Fuseki and Sipi testcontainers - */ - val defaultLayersTestWithSipi = - ZLayer.make[DefaultTestEnvironmentWithSipi]( - ActorSystem.layer, + type CommonR0 = ActorSystem with IIIFService with AppConfig + type CommonR = ApiRoutes + with AppRouter + with CacheService + with CacheServiceManager + with HttpServer + with IIIFServiceManager + with RepositoryUpdater + with State + with TestClientService + with TriplestoreService + with TriplestoreServiceManager + + private val commonLayersForAllIntegrationTests = + ZLayer.makeSome[CommonR0, CommonR]( ApiRoutes.layer, - AppConfigForTestContainers.testcontainers, AppRouter.layer, - CacheServiceManager.layer, CacheServiceInMemImpl.layer, + CacheServiceManager.layer, HttpServer.layer, IIIFServiceManager.layer, - IIIFServiceSipiImpl.layer, // alternative: MockSipiImpl.layer - JWTService.layer, RepositoryUpdater.layer, State.layer, - TriplestoreServiceManager.layer, + TestClientService.layer, TriplestoreServiceHttpConnectorImpl.layer, - // testcontainers - SipiTestContainer.layer, - FusekiTestContainer.layer, - // Test services - TestClientService.layer + TriplestoreServiceManager.layer ) - /** - * All live layers - with ActorSystem - but without Sipi testcontainer - */ - val defaultLayersTestWithoutSipi = - ZLayer.make[DefaultTestEnvironmentWithoutSipi]( - ActorSystem.layer, - ApiRoutes.layer, - AppConfigForTestContainers.fusekiOnlyTestcontainer, - AppRouter.layer, - CacheServiceManager.layer, - CacheServiceInMemImpl.layer, - HttpServer.layer, - IIIFServiceManager.layer, - IIIFServiceSipiImpl.layer, // alternative: MockSipiImpl.layer - JWTService.layer, - RepositoryUpdater.layer, - State.layer, - TriplestoreServiceManager.layer, - TriplestoreServiceHttpConnectorImpl.layer, - // testcontainers + private val fusekiAndSipiTestcontainers = + ZLayer.make[FusekiTestContainer with SipiTestContainer with AppConfig with JWTService with IIIFService]( + AppConfigForTestContainers.testcontainers, FusekiTestContainer.layer, - // Test services - TestClientService.layer + SipiTestContainer.layer, + IIIFServiceSipiImpl.layer, + JWTService.layer ) - /** - * All live layers - with ActorSystemTest - but without Sipi testcontainer - */ - def defaultLayersTestWithoutSipi(system: akka.actor.ActorSystem) = - ZLayer.make[DefaultTestEnvironmentWithoutSipi]( - ActorSystemTest.layer(system), - ApiRoutes.layer, + private val fusekiTestcontainers = + ZLayer.make[FusekiTestContainer with AppConfig with JWTService with IIIFService]( AppConfigForTestContainers.fusekiOnlyTestcontainer, - AppRouter.layer, - CacheServiceManager.layer, - CacheServiceInMemImpl.layer, - HttpServer.layer, - IIIFServiceManager.layer, - IIIFServiceSipiImpl.layer, // alternative: MockSipiImpl.layer - JWTService.layer, - RepositoryUpdater.layer, - State.layer, - TriplestoreServiceManager.layer, - TriplestoreServiceHttpConnectorImpl.layer, - // testcontainers FusekiTestContainer.layer, - // Test services - TestClientService.layer + IIIFServiceMockImpl.layer, + JWTService.layer ) /** - * All live layers - with ActorSystemTest - but with the mocked IIIF layer + * Provides a layer for integration tests which depend on Fuseki as Testcontainers. + * Sipi/IIIFService will be mocked with the [[IIIFServiceMockImpl.l]] + * @param system An optional [[akka.actor.ActorSystem]] for use with Akka's [[akka.testkit.TestKit]] + * @return a [[ULayer]] with the [[DefaultTestEnvironmentWithoutSipi]] */ - val defaultLayersTestWithMockedSipi = + def integrationTestsWithFusekiTestcontainers( + system: Option[akka.actor.ActorSystem] = None + ): ULayer[DefaultTestEnvironmentWithoutSipi] = ZLayer.make[DefaultTestEnvironmentWithoutSipi]( - ActorSystem.layer, - ApiRoutes.layer, - AppConfigForTestContainers.fusekiOnlyTestcontainer, - AppRouter.layer, - CacheServiceManager.layer, - CacheServiceInMemImpl.layer, - HttpServer.layer, - IIIFServiceManager.layer, - IIIFServiceMockImpl.layer, - JWTService.layer, - RepositoryUpdater.layer, - State.layer, - TriplestoreServiceManager.layer, - TriplestoreServiceHttpConnectorImpl.layer, - // testcontainers - FusekiTestContainer.layer, - // Test services - TestClientService.layer + commonLayersForAllIntegrationTests, + fusekiTestcontainers, + system.map(ActorSystemTest.layer).getOrElse(ActorSystem.layer) ) /** - * All live layers - with ActorSystemTest - but with the mocked IIIF layer + * Provides a layer for integration tests which depend on Fuseki and Sipi as Testcontainers. + * @return a [[ULayer]] with the [[DefaultTestEnvironmentWithSipi]] */ - def defaultLayersTestWithMockedSipi(system: akka.actor.ActorSystem) = - ZLayer.make[DefaultTestEnvironmentWithoutSipi]( - ActorSystemTest.layer(system), - ApiRoutes.layer, - AppConfigForTestContainers.fusekiOnlyTestcontainer, - AppRouter.layer, - CacheServiceManager.layer, - CacheServiceInMemImpl.layer, - HttpServer.layer, - IIIFServiceManager.layer, - IIIFServiceMockImpl.layer, - JWTService.layer, - RepositoryUpdater.layer, - State.layer, - TriplestoreServiceManager.layer, - TriplestoreServiceHttpConnectorImpl.layer, - // testcontainers - FusekiTestContainer.layer, - // Test services - TestClientService.layer + val integrationTestsWithSipiAndFusekiTestcontainers: ULayer[DefaultTestEnvironmentWithSipi] = + ZLayer.make[DefaultTestEnvironmentWithSipi]( + commonLayersForAllIntegrationTests, + fusekiAndSipiTestcontainers, + ActorSystem.layer ) } diff --git a/webapi/src/it/scala/org/knora/webapi/e2e/v1/SipiV1R2RSpec.scala b/webapi/src/it/scala/org/knora/webapi/e2e/v1/SipiV1R2RSpec.scala index aa251798aa..0f39809538 100644 --- a/webapi/src/it/scala/org/knora/webapi/e2e/v1/SipiV1R2RSpec.scala +++ b/webapi/src/it/scala/org/knora/webapi/e2e/v1/SipiV1R2RSpec.scala @@ -48,7 +48,7 @@ class SipiV1R2RSpec extends R2RSpec { /* we need to run our app with the mocked sipi implementation */ override type Environment = core.LayersTest.DefaultTestEnvironmentWithoutSipi - override lazy val effectLayers = core.LayersTest.defaultLayersTestWithMockedSipi(system) + override lazy val effectLayers = core.LayersTest.integrationTestsWithFusekiTestcontainers(Some(system)) object RequestParams { diff --git a/webapi/src/it/scala/org/knora/webapi/e2e/v2/ValuesV2R2RSpec.scala b/webapi/src/it/scala/org/knora/webapi/e2e/v2/ValuesV2R2RSpec.scala index a145daa5bb..5814fe7658 100644 --- a/webapi/src/it/scala/org/knora/webapi/e2e/v2/ValuesV2R2RSpec.scala +++ b/webapi/src/it/scala/org/knora/webapi/e2e/v2/ValuesV2R2RSpec.scala @@ -48,7 +48,7 @@ class ValuesV2R2RSpec extends R2RSpec { /* we need to run our app with the mocked sipi implementation */ override type Environment = core.LayersTest.DefaultTestEnvironmentWithoutSipi - override lazy val effectLayers = core.LayersTest.defaultLayersTestWithMockedSipi(system) + override lazy val effectLayers = core.LayersTest.integrationTestsWithFusekiTestcontainers(Some(system)) private val aThingPictureIri = "http://rdfh.ch/0001/a-thing-picture" diff --git a/webapi/src/it/scala/org/knora/webapi/responders/v1/ResourcesResponderV1Spec.scala b/webapi/src/it/scala/org/knora/webapi/responders/v1/ResourcesResponderV1Spec.scala index a62fb3d75e..afecb55b86 100644 --- a/webapi/src/it/scala/org/knora/webapi/responders/v1/ResourcesResponderV1Spec.scala +++ b/webapi/src/it/scala/org/knora/webapi/responders/v1/ResourcesResponderV1Spec.scala @@ -7,13 +7,12 @@ package org.knora.webapi.responders.v1 import akka.testkit.ImplicitSender import spray.json.JsValue - import java.util.UUID import scala.concurrent.duration._ - import dsp.errors.BadRequestException import dsp.errors.NotFoundException import dsp.errors.OntologyConstraintException + import org.knora.webapi._ import org.knora.webapi.messages.IriConversions._ import org.knora.webapi.messages.OntologyConstants @@ -656,7 +655,7 @@ class ResourcesResponderV1Spec extends CoreSpec with ImplicitSender { /* we need to run our app with the mocked sipi implementation */ override type Environment = core.LayersTest.DefaultTestEnvironmentWithoutSipi - override lazy val effectLayers = core.LayersTest.defaultLayersTestWithMockedSipi + override lazy val effectLayers = core.LayersTest.integrationTestsWithFusekiTestcontainers() // The default timeout for receiving reply messages from actors. private val timeout = 60.seconds diff --git a/webapi/src/it/scala/org/knora/webapi/responders/v1/ValuesResponderV1Spec.scala b/webapi/src/it/scala/org/knora/webapi/responders/v1/ValuesResponderV1Spec.scala index fbe3b56199..39a08af807 100644 --- a/webapi/src/it/scala/org/knora/webapi/responders/v1/ValuesResponderV1Spec.scala +++ b/webapi/src/it/scala/org/knora/webapi/responders/v1/ValuesResponderV1Spec.scala @@ -54,7 +54,7 @@ class ValuesResponderV1Spec extends CoreSpec with ImplicitSender { /* we need to run our app with the mocked sipi implementation */ override type Environment = core.LayersTest.DefaultTestEnvironmentWithoutSipi - override lazy val effectLayers = core.LayersTest.defaultLayersTestWithMockedSipi + override lazy val effectLayers = core.LayersTest.integrationTestsWithFusekiTestcontainers() override lazy val rdfDataObjects = List( RdfDataObject( diff --git a/webapi/src/it/scala/org/knora/webapi/responders/v2/ResourcesResponderV2Spec.scala b/webapi/src/it/scala/org/knora/webapi/responders/v2/ResourcesResponderV2Spec.scala index 7d359938b9..00557f2250 100644 --- a/webapi/src/it/scala/org/knora/webapi/responders/v2/ResourcesResponderV2Spec.scala +++ b/webapi/src/it/scala/org/knora/webapi/responders/v2/ResourcesResponderV2Spec.scala @@ -402,7 +402,7 @@ class ResourcesResponderV2Spec extends CoreSpec with ImplicitSender { /* we need to run our app with the mocked sipi implementation */ override type Environment = core.LayersTest.DefaultTestEnvironmentWithoutSipi - override lazy val effectLayers = core.LayersTest.defaultLayersTestWithMockedSipi + override lazy val effectLayers = core.LayersTest.integrationTestsWithFusekiTestcontainers() override lazy val rdfDataObjects = List( RdfDataObject(path = "test_data/all_data/incunabula-data.ttl", name = "http://www.knora.org/data/0803/incunabula"), diff --git a/webapi/src/it/scala/org/knora/webapi/responders/v2/ValuesResponderV2Spec.scala b/webapi/src/it/scala/org/knora/webapi/responders/v2/ValuesResponderV2Spec.scala index b4bbe0b33f..f0f34f3477 100644 --- a/webapi/src/it/scala/org/knora/webapi/responders/v2/ValuesResponderV2Spec.scala +++ b/webapi/src/it/scala/org/knora/webapi/responders/v2/ValuesResponderV2Spec.scala @@ -61,7 +61,7 @@ class ValuesResponderV2Spec extends CoreSpec with ImplicitSender { /* we need to run our app with the mocked sipi implementation */ override type Environment = core.LayersTest.DefaultTestEnvironmentWithoutSipi - override lazy val effectLayers = core.LayersTest.defaultLayersTestWithMockedSipi + override lazy val effectLayers = core.LayersTest.integrationTestsWithFusekiTestcontainers() override lazy val rdfDataObjects = List( RdfDataObject( diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServer.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServer.scala index 811383f14a..5981d04821 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServer.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServer.scala @@ -20,7 +20,7 @@ trait HttpServer { } object HttpServer { - val layer: ZLayer[core.ActorSystem & AppConfig & ApiRoutes, Nothing, HttpServer] = + val layer: ZLayer[ActorSystem with AppConfig with ApiRoutes, Nothing, HttpServer] = ZLayer.scoped { for { as <- ZIO.service[core.ActorSystem]