Skip to content

Commit

Permalink
Add resolver test
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergrabinski committed Mar 21, 2024
1 parent c496bce commit fc0bb53
Showing 1 changed file with 65 additions and 20 deletions.
85 changes: 65 additions & 20 deletions ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/EndToEndTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package ch.epfl.bluebrain.nexus.ship
import akka.http.scaladsl.model.StatusCodes
import cats.data.NonEmptyList
import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.kernel.utils.UrlUtils
import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.nxv
import ch.epfl.bluebrain.nexus.delta.sourcing.exporter.ExportEventQuery
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{Label, ProjectRef}
import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset
Expand All @@ -26,8 +29,6 @@ class EndToEndTest extends BaseIntegrationSpec {
()
}



"The ship" should {

"transfer a project" in {
Expand All @@ -45,10 +46,25 @@ class EndToEndTest extends BaseIntegrationSpec {
thereShouldBeAProject(project, projectJson)
}

"transfer a resolver" in {
val (project, _) = thereIsAProject()
val defaultInProjectResolver = nxv + "defaultInProject"
val (_, resolverJson) = thereIsAResolver(defaultInProjectResolver, project)

whenTheExportIsRunOnProject(project)
theOldProjectIsDeleted(project)

weRunTheImporter(project)
weFixThePermissions(project)

thereShouldBeAResolver(project, defaultInProjectResolver, resolverJson)
}

def thereIsAProject(): (ProjectRef, Json) = {
val project: ProjectRef = ProjectRef.unsafe(genString(), genString())
val project: ProjectRef = ProjectRef.unsafe(genString(), genString())
createProjects(writer, project.organization.value, project.project.value).accepted
val (projectJson, status) = deltaClient.getJsonAndStatus(s"/projects/${project.organization}/${project.project}", writer).accepted
val (projectJson, status) =
deltaClient.getJsonAndStatus(s"/projects/${project.organization}/${project.project}", writer).accepted
status shouldEqual StatusCodes.OK
project -> projectJson
}
Expand All @@ -60,21 +76,25 @@ class EndToEndTest extends BaseIntegrationSpec {
Offset.start
).asJson

deltaClient.post[Json]("/export/events", query, writer) { (_, response) =>
response.status shouldEqual StatusCodes.Accepted
}.accepted
deltaClient
.post[Json]("/export/events", query, writer) { (_, response) =>
response.status shouldEqual StatusCodes.Accepted
}
.accepted

IO.sleep(6.seconds).accepted
IO.sleep(5.seconds).accepted
}

def theOldProjectIsDeleted(project: ProjectRef): Unit = {
deltaClient.delete[Json](s"/projects/${project.organization}/${project.project}?rev=1&prune=true", writer) {
(_, response) => response.status shouldEqual StatusCodes.OK
}.accepted
deltaClient
.delete[Json](s"/projects/${project.organization}/${project.project}?rev=1&prune=true", writer) {
(_, response) => response.status shouldEqual StatusCodes.OK
}
.accepted

eventually {
deltaClient.get[Json](s"/projects/${project.organization}/${project.project}", writer) {
(_, response) => response.status shouldEqual StatusCodes.NotFound
deltaClient.get[Json](s"/projects/${project.organization}/${project.project}", writer) { (_, response) =>
response.status shouldEqual StatusCodes.NotFound
}
}
()
Expand All @@ -83,22 +103,47 @@ class EndToEndTest extends BaseIntegrationSpec {
def weRunTheImporter(project: ProjectRef): Unit = {
val folder = s"/tmp/ship/${project.project.value}/"
val folderPath = Paths.get(folder)
val file = Files.newDirectoryStream(folderPath, "*.json").iterator().asScala.toList.head
val file = Files.newDirectoryStream(folderPath, "*.json").iterator().asScala.toList.head

new RunShip().run(fs2.io.file.Path.fromNioPath(file), None).accepted
()
}

def thereShouldBeAProject(project: ProjectRef, originalJson: Json): Assertion = {
deltaClient.get[Json](s"/projects/${project.organization}/${project.project}", writer) {
(json, response) => {
response.status shouldEqual StatusCodes.OK
json shouldEqual originalJson
deltaClient
.get[Json](s"/projects/${project.organization}/${project.project}", writer) { (json, response) =>
{
response.status shouldEqual StatusCodes.OK
json shouldEqual originalJson
}
}
}.accepted
.accepted
}

def weFixThePermissions(project: ProjectRef) = aclDsl.addPermissions(s"/$project", writer, Permission.minimalPermissions).accepted
def weFixThePermissions(project: ProjectRef) =
aclDsl.addPermissions(s"/$project", writer, Permission.minimalPermissions).accepted

def thereIsAResolver(resolver: Iri, project: ProjectRef): (Iri, Json) = {
val encodedResolver = UrlUtils.encode(resolver.toString)
val (resolverJson, status) = deltaClient
.getJsonAndStatus(s"/resolvers/${project.organization}/${project.project}/$encodedResolver", writer)
.accepted
status shouldEqual StatusCodes.OK
resolver -> resolverJson
}

def thereShouldBeAResolver(project: ProjectRef, resolver: Iri, originalJson: Json): Assertion = {
val encodedResolver = UrlUtils.encode(resolver.toString)
deltaClient
.get[Json](s"/resolvers/${project.organization}/${project.project}/$encodedResolver", writer) {
(json, response) =>
{
response.status shouldEqual StatusCodes.OK
json shouldEqual originalJson
}
}
.accepted
}
}

}

0 comments on commit fc0bb53

Please sign in to comment.