Skip to content

Commit

Permalink
Migrate (possibly) all scalatests to use BaseSpec (#4390)
Browse files Browse the repository at this point in the history
* Migrate (possibly) all scalatests to use BaseSpec

* Unify IOFixedClock, fix tests where one was missing

* Fix accidentally removed clock
  • Loading branch information
shinyhappydan authored Oct 20, 2023
1 parent 5b7c121 commit 72dc3ba
Show file tree
Hide file tree
Showing 144 changed files with 344 additions and 1,036 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package ch.epfl.bluebrain.nexus.delta.config

import ch.epfl.bluebrain.nexus.delta.kernel.utils.ClasspathResourceUtils
import ch.epfl.bluebrain.nexus.testkit.scalatest.bio.BIOValues
import ch.epfl.bluebrain.nexus.testkit.scalatest.bio.BioSpec
import com.typesafe.config.impl.ConfigImpl
import org.scalatest.BeforeAndAfterAll
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike

class AppConfigSpec extends AnyWordSpecLike with Matchers with BIOValues with BeforeAndAfterAll {
class AppConfigSpec extends BioSpec with BeforeAndAfterAll {

implicit private val classLoader: ClassLoader = getClass.getClassLoader

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package ch.epfl.bluebrain.nexus.delta.dependency
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.ServiceDescription
import ch.epfl.bluebrain.nexus.delta.sdk.model.Name
import ch.epfl.bluebrain.nexus.delta.sourcing.postgres.{DoobieScalaTestFixture, PostgresDocker}
import ch.epfl.bluebrain.nexus.testkit.scalatest.bio.BIOValues
import org.scalatest.matchers.should.Matchers
import ch.epfl.bluebrain.nexus.testkit.scalatest.bio.BioSpec

class PostgresServiceDependencySpec extends DoobieScalaTestFixture with Matchers with PostgresDocker with BIOValues {
class PostgresServiceDependencySpec extends BioSpec with DoobieScalaTestFixture with PostgresDocker {

"PostgresServiceDependency" should {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package ch.epfl.bluebrain.nexus.delta.plugin

import ch.epfl.bluebrain.nexus.delta.testplugin.ClassLoaderTestClassImpl
import ch.epfl.bluebrain.nexus.testkit.scalatest.ShouldMatchers.convertToAnyShouldWrapper
import ch.epfl.bluebrain.nexus.testkit.plugin.ClassLoaderTestClass
import ch.epfl.bluebrain.nexus.testkit.scalatest.BaseSpec
import org.scalatest.BeforeAndAfterAll
import org.scalatest.matchers.must.Matchers
import org.scalatest.wordspec.AnyWordSpecLike

import java.nio.file.Path
import scala.io.Source

class PluginClassLoaderSpec extends AnyWordSpecLike with Matchers with BeforeAndAfterAll {
class PluginClassLoaderSpec extends BaseSpec with BeforeAndAfterAll {

val jarPath = Path.of("../plugins/test-plugin/target/delta-test-plugin.jar")
val cl = new PluginClassLoader(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
package ch.epfl.bluebrain.nexus.delta.plugin

import akka.http.scaladsl.testkit.ScalatestRouteTest
import cats.effect.{ContextShift, IO, Timer}
import ch.epfl.bluebrain.nexus.delta.kernel.effect.migration._
import ch.epfl.bluebrain.nexus.delta.plugin.PluginsLoader.PluginLoaderConfig
import ch.epfl.bluebrain.nexus.delta.sdk.PriorityRoute
import ch.epfl.bluebrain.nexus.delta.sdk.model.BaseUri
import ch.epfl.bluebrain.nexus.testkit.ce.CatsRunContext
import ch.epfl.bluebrain.nexus.testkit.scalatest.bio.BioSpec
import com.typesafe.config.impl.ConfigImpl
import izumi.distage.model.definition.ModuleDef
import monix.bio.Task
import ch.epfl.bluebrain.nexus.delta.kernel.effect.migration._
import ch.epfl.bluebrain.nexus.testkit.scalatest.bio.BIOValues
import monix.execution.Scheduler
import monix.execution.Scheduler.Implicits.global
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike

import scala.concurrent.ExecutionContext

class PluginLoaderSpec extends AnyWordSpecLike with ScalatestRouteTest with Matchers with BIOValues {
class PluginLoaderSpec extends BioSpec with ScalatestRouteTest with CatsRunContext {

private val baseUri = BaseUri.withoutPrefix("http://localhost")
private val serviceModule = new ModuleDef {
make[BaseUri].fromValue(baseUri)
make[Scheduler].from(Scheduler.global)
}

implicit val contextShift: ContextShift[IO] = IO.contextShift(ExecutionContext.global)
implicit val timer: Timer[IO] = IO.timer(ExecutionContext.global)

"A PluginLoader" should {
val config = PluginLoaderConfig("../plugins/test-plugin/target")
"load plugins from .jar in a directory" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import ch.epfl.bluebrain.nexus.delta.routes.AclsRoutes.{AclValues, PatchAcl, Rep
import ch.epfl.bluebrain.nexus.delta.sdk.permissions.Permissions.resources
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity
import ch.epfl.bluebrain.nexus.testkit.CirceLiteral
import ch.epfl.bluebrain.nexus.testkit.scalatest.EitherValues
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
import ch.epfl.bluebrain.nexus.testkit.scalatest.BaseSpec

class AclsRoutesPayloadSpec extends AnyWordSpecLike with Matchers with CirceLiteral with EitherValues {
class AclsRoutesPayloadSpec extends BaseSpec with CirceLiteral {

private val json = json"""{"acl": [{"permissions": ["resources/read"], "identity": {"@type": "Anonymous"} } ] }"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ import ch.epfl.bluebrain.nexus.delta.sdk.generators.OrganizationGen
import ch.epfl.bluebrain.nexus.delta.sdk.identities.IdentitiesDummy
import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.Caller
import ch.epfl.bluebrain.nexus.delta.sdk.implicits._
import ch.epfl.bluebrain.nexus.delta.sdk.organizations.{OrganizationDeleter, OrganizationsConfig, OrganizationsImpl}
import ch.epfl.bluebrain.nexus.delta.sdk.organizations.model.OrganizationRejection.OrganizationNonEmpty
import ch.epfl.bluebrain.nexus.delta.sdk.organizations.{OrganizationDeleter, OrganizationsConfig, OrganizationsImpl}
import ch.epfl.bluebrain.nexus.delta.sdk.permissions.Permissions.{events, orgs => orgsPermissions}
import ch.epfl.bluebrain.nexus.delta.sdk.projects.OwnerPermissionsScopeInitialization
import ch.epfl.bluebrain.nexus.delta.sdk.utils.BaseRouteSpec
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Authenticated, Group, Subject}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Label
import ch.epfl.bluebrain.nexus.testkit.bio.IOFromMap
import ch.epfl.bluebrain.nexus.testkit.ce.IOFixedClock
import io.circe.Json

import java.util.UUID

class OrganizationsRoutesSpec extends BaseRouteSpec with IOFromMap with IOFixedClock {
class OrganizationsRoutesSpec extends BaseRouteSpec with IOFromMap {

private val fixedUuid = UUID.randomUUID()
implicit private val uuidF: UUIDF = UUIDF.fixed(fixedUuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ import ch.epfl.bluebrain.nexus.delta.sdk.permissions.{Permissions, PermissionsCo
import ch.epfl.bluebrain.nexus.delta.sdk.utils.BaseRouteSpec
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Subject}
import ch.epfl.bluebrain.nexus.testkit.ce.IOFixedClock
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsIOValues
import io.circe.Json

class PermissionsRoutesSpec extends BaseRouteSpec with IOFixedClock with CatsIOValues {
class PermissionsRoutesSpec extends BaseRouteSpec with CatsIOValues {

implicit private val caller: Subject = Identity.Anonymous

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import ch.epfl.bluebrain.nexus.delta.sdk.realms.{RealmsConfig, RealmsImpl}
import ch.epfl.bluebrain.nexus.delta.sdk.utils.BaseRouteSpec
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Authenticated, Group, Subject}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Label
import ch.epfl.bluebrain.nexus.testkit.ce.{IOFixedClock, IOFromMap}
import ch.epfl.bluebrain.nexus.testkit.ce.IOFromMap
import io.circe.Json

class RealmsRoutesSpec extends BaseRouteSpec with IOFromMap with IOFixedClock {
class RealmsRoutesSpec extends BaseRouteSpec with IOFromMap {

val (github, gitlab) = (Label.unsafe("github"), Label.unsafe("gitlab"))
val (githubName, gitlabName) = (Name.unsafe("github-name"), Name.unsafe("gitlab-name"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ import ch.epfl.bluebrain.nexus.delta.sdk.{Defaults, IndexingAction}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Authenticated, Group, Subject}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ResourceRef.{Latest, Revision}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{Label, ProjectRef, ResourceRef}
import ch.epfl.bluebrain.nexus.testkit.ce.IOFixedClock
import io.circe.Json
import io.circe.syntax._

import java.util.UUID
import java.util.concurrent.atomic.AtomicInteger

class ResolversRoutesSpec extends BaseRouteSpec with IOFixedClock {
class ResolversRoutesSpec extends BaseRouteSpec {

private val uuid = UUID.randomUUID()
implicit private val uuidF: UUIDF = UUIDF.fixed(uuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Authent
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{ProjectRef, ResourceRef}
import ch.epfl.bluebrain.nexus.testkit.bio.IOFromMap
import ch.epfl.bluebrain.nexus.testkit.ce.IOFixedClock
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsIOValues
import io.circe.{Json, Printer}

import java.util.UUID

class ResourcesRoutesSpec extends BaseRouteSpec with IOFromMap with IOFixedClock with CatsIOValues {
class ResourcesRoutesSpec extends BaseRouteSpec with IOFromMap with CatsIOValues {

private val uuid = UUID.randomUUID()
implicit private val uuidF: UUIDF = UUIDF.fixed(uuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ import ch.epfl.bluebrain.nexus.delta.sdk.utils.BaseRouteSpec
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Authenticated, Group, Subject}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef
import ch.epfl.bluebrain.nexus.testkit.bio.IOFromMap
import ch.epfl.bluebrain.nexus.testkit.ce.IOFixedClock
import io.circe.Json

import java.util.UUID

class SchemasRoutesSpec extends BaseRouteSpec with IOFixedClock with IOFromMap {
class SchemasRoutesSpec extends BaseRouteSpec with IOFromMap {

private val uuid = UUID.randomUUID()
implicit private val uuidF: UUIDF = UUIDF.fixed(uuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,14 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ResourceRef.Latest
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{Identity, Label, ProjectRef, ResourceRef}
import ch.epfl.bluebrain.nexus.testkit.archive.ArchiveHelpers
import ch.epfl.bluebrain.nexus.testkit.ce.IOFixedClock
import io.circe.Json
import io.circe.syntax.EncoderOps
import org.scalatest.TryValues

import java.util.UUID
import scala.concurrent.duration._

class ArchiveRoutesSpec
extends BaseRouteSpec
with StorageFixtures
with IOFixedClock
with TryValues
with ArchiveHelpers {
class ArchiveRoutesSpec extends BaseRouteSpec with StorageFixtures with TryValues with ArchiveHelpers {

private val uuid = UUID.fromString("8249ba90-7cc6-4de5-93a1-802c04200dcc")
implicit private val uuidF: StatefulUUIDF = UUIDF.stateful(uuid).accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,21 @@ import cats.data.NonEmptySet
import ch.epfl.bluebrain.nexus.delta.kernel.utils.UUIDF
import ch.epfl.bluebrain.nexus.delta.plugins.archive.model.ArchiveReference.{FileReference, ResourceReference}
import ch.epfl.bluebrain.nexus.delta.plugins.archive.model.ArchiveRejection.{DecodingFailed, InvalidJsonLdFormat, UnexpectedArchiveId}
import ch.epfl.bluebrain.nexus.delta.sdk.model.ResourceRepresentation.{AnnotatedSourceJson, CompactedJsonLd, Dot, ExpandedJsonLd, NTriples, SourceJson}
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.AbsolutePath
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.nxv
import ch.epfl.bluebrain.nexus.delta.rdf.implicits._
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.api.{JsonLdApi, JsonLdJavaApi}
import ch.epfl.bluebrain.nexus.delta.sdk.model.ResourceRepresentation.{AnnotatedSourceJson, CompactedJsonLd, Dot, ExpandedJsonLd, NTriples, SourceJson}
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.{ApiMappings, ProjectContext}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ResourceRef.{Latest, Revision, Tag}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.testkit.scalatest.EitherValues
import ch.epfl.bluebrain.nexus.testkit.TestHelpers
import ch.epfl.bluebrain.nexus.testkit.scalatest.bio.BIOValues
import ch.epfl.bluebrain.nexus.testkit.scalatest.bio.BioSpec
import io.circe.literal._
import org.scalatest.Inspectors
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike

import java.nio.file.Paths

class ArchivesDecodingSpec
extends AnyWordSpecLike
with Matchers
with Inspectors
with BIOValues
with EitherValues
with TestHelpers
with RemoteContextResolutionFixture {
class ArchivesDecodingSpec extends BioSpec with RemoteContextResolutionFixture {

implicit private val uuidF: UUIDF = UUIDF.random
implicit private val api: JsonLdApi = JsonLdJavaApi.strict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@ import ch.epfl.bluebrain.nexus.delta.sdk.model.ResourceRepresentation.SourceJson
import ch.epfl.bluebrain.nexus.delta.sdk.syntax._
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.User
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{Label, ProjectRef, ResourceRef}
import ch.epfl.bluebrain.nexus.testkit.ce.IOFixedClock
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsIOValues
import ch.epfl.bluebrain.nexus.testkit.TestHelpers
import ch.epfl.bluebrain.nexus.testkit.scalatest.EitherValues
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsEffectSpec

import java.nio.file.Paths
import java.time.Instant

class ArchivesSTMSpec
extends AnyWordSpecLike
with Matchers
with CatsIOValues
with IOFixedClock
with EitherValues
with TestHelpers {
class ArchivesSTMSpec extends CatsEffectSpec {

"An Archive STM" when {
val id = iri"http://localhost${genString()}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,16 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Subject, User}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ResourceRef.Latest
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{Label, ProjectRef}
import ch.epfl.bluebrain.nexus.delta.sourcing.postgres.DoobieScalaTestFixture
import ch.epfl.bluebrain.nexus.testkit.TestHelpers
import ch.epfl.bluebrain.nexus.testkit.ce.{CatsRunContext, IOFixedClock}
import ch.epfl.bluebrain.nexus.testkit.scalatest.EitherValues
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsIOValues
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsEffectSpec
import io.circe.literal._
import org.scalatest.matchers.should.Matchers

import java.net.URLEncoder
import java.nio.charset.StandardCharsets
import java.time.Instant
import java.util.UUID
import scala.concurrent.duration._

class ArchivesSpec
extends DoobieScalaTestFixture
with Matchers
with IOFixedClock
with CatsRunContext
with CatsIOValues
with EitherValues
with TestHelpers
with RemoteContextResolutionFixture {
class ArchivesSpec extends CatsEffectSpec with DoobieScalaTestFixture with RemoteContextResolutionFixture {

private val uuid = UUID.randomUUID()
implicit private val uuidF: UUIDF = UUIDF.random
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,15 @@ import ch.epfl.bluebrain.nexus.delta.sdk.{ConfigFixtures, Defaults}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Subject, User}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Label
import ch.epfl.bluebrain.nexus.delta.sourcing.postgres.DoobieScalaTestFixture
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsIOValues
import ch.epfl.bluebrain.nexus.testkit.TestHelpers
import ch.epfl.bluebrain.nexus.testkit.bio.IOFixedClock
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsEffectSpec
import monix.bio.UIO
import monix.execution.Scheduler
import org.scalatest.Inspectors
import org.scalatest.matchers.should.Matchers

import java.util.UUID

class BlazegraphScopeInitializationSpec
extends DoobieScalaTestFixture
with Matchers
with Inspectors
with IOFixedClock
with CatsIOValues
with TestHelpers
extends CatsEffectSpec
with DoobieScalaTestFixture
with ConfigFixtures
with Fixtures {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,12 @@ import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.{ApiMappings, ProjectCon
import ch.epfl.bluebrain.nexus.delta.sdk.views.ViewRef
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{Label, ProjectRef}
import ch.epfl.bluebrain.nexus.testkit.TestHelpers
import ch.epfl.bluebrain.nexus.testkit.scalatest.bio.BIOValues
import ch.epfl.bluebrain.nexus.testkit.scalatest.bio.BioSpec
import io.circe.literal._
import org.scalatest.Inspectors
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike

import java.util.UUID

class BlazegraphViewDecodingSpec
extends AnyWordSpecLike
with Matchers
with Inspectors
with BIOValues
with TestHelpers
with Fixtures {
class BlazegraphViewDecodingSpec extends BioSpec with Fixtures {

private val context = ProjectContext.unsafe(
ApiMappings.empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,15 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Authenticated, Gro
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Label
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.delta.sourcing.postgres.DoobieScalaTestFixture
import ch.epfl.bluebrain.nexus.testkit._
import ch.epfl.bluebrain.nexus.testkit.bio.IOFixedClock
import ch.epfl.bluebrain.nexus.testkit.scalatest.bio.BIOValues
import ch.epfl.bluebrain.nexus.testkit.scalatest.bio.BioSpec
import io.circe.Json
import io.circe.syntax._
import monix.bio.UIO
import monix.execution.Scheduler
import org.scalatest.Inspectors
import org.scalatest.matchers.should.Matchers

import java.util.UUID

class BlazegraphViewsSpec
extends DoobieScalaTestFixture
with Matchers
with Inspectors
with IOFixedClock
with BIOValues
with TestHelpers
with ConfigFixtures
with Fixtures {
class BlazegraphViewsSpec extends BioSpec with DoobieScalaTestFixture with ConfigFixtures with Fixtures {

"BlazegraphViews" when {
val uuid = UUID.randomUUID()
Expand Down
Loading

0 comments on commit 72dc3ba

Please sign in to comment.