From 1fc1234ba590bc2bc9043c3dfef651bd42fee9c0 Mon Sep 17 00:00:00 2001 From: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com> Date: Tue, 18 Jun 2024 15:27:33 +0200 Subject: [PATCH] restructure test --- .../repo/service/ResourcesRepoLiveSpec.scala | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala b/webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala index a9bcdc61e2..47c72fe163 100644 --- a/webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala @@ -20,21 +20,7 @@ import org.knora.webapi.messages.twirl.TypeSpecificValueInfo import org.knora.webapi.slice.resourceinfo.domain.InternalIri import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Update -object ResourcesRepoLiveSpec extends ZIOSpecDefault { - - private def assertUpdateQueriesEqual(expected: Update, actual: Update) = { - val parsedExpected = UpdateFactory.create(expected.sparql) - val parsedActual = UpdateFactory.create(actual.sparql) - if (parsedExpected.equalTo(parsedActual)) { - assertTrue(true) - } else { - val expectedStr = parsedExpected.toString() - val actualStr = parsedActual.toString() - assertTrue(expectedStr == actualStr) - } - } - - def spec: Spec[Environment & (TestEnvironment & Scope), Any] = tests.provide(StringFormatter.test) +object TestData { val graphIri = InternalIri("foo:Graph") val projectIri = "foo:ProjectIri" @@ -45,9 +31,10 @@ object ResourcesRepoLiveSpec extends ZIOSpecDefault { val creationDate = Instant.parse("2024-01-01T10:00:00.673298Z") val permissions = "fooPermissionsString" val valueIri = "foo:ValueIri" - val valueCreator = "foo:valueCreatorIri" + val valueCreator = "foo:ValueCreatorIri" val valuePermissions = "fooValuePermissions" val valueCreationDate = Instant.parse("2024-01-01T12:00:00.673298Z") + val propertyIri = "foo:propertyIri" val resourceDefinition = ResourceReadyToCreate( resourceIri = resourceIri, @@ -59,6 +46,41 @@ object ResourcesRepoLiveSpec extends ZIOSpecDefault { linkUpdates = Seq.empty, ) + def intValueDefinition(uuid: UUID) = + NewValueInfo( + resourceIri = resourceIri, + propertyIri = propertyIri, + valueIri = valueIri, + valueTypeIri = OntologyConstants.KnoraBase.IntValue, + valueUUID = uuid, + value = TypeSpecificValueInfo.IntegerValueInfo(42), + valuePermissions = valuePermissions, + valueCreator = valueCreator, + creationDate = valueCreationDate, + valueHasOrder = 1, + valueHasString = "42", + comment = None, + ) + +} + +object ResourcesRepoLiveSpec extends ZIOSpecDefault { + import TestData.* + + private def assertUpdateQueriesEqual(expected: Update, actual: Update) = { + val parsedExpected = UpdateFactory.create(expected.sparql) + val parsedActual = UpdateFactory.create(actual.sparql) + if (parsedExpected.equalTo(parsedActual)) { + assertTrue(true) + } else { + val expectedStr = parsedExpected.toString() + val actualStr = parsedActual.toString() + assertTrue(expectedStr == actualStr) + } + } + + def spec: Spec[Environment & (TestEnvironment & Scope), Any] = tests.provide(StringFormatter.test) + val createResourceWithoutValuesTest = test("Create a new resource query without values") { val expected = Update(s"""| @@ -101,25 +123,7 @@ object ResourcesRepoLiveSpec extends ZIOSpecDefault { test("Create a new resource with an integer value") { val uuid = UUID.randomUUID() val uuidEncoded = UuidUtil.base64Encode(uuid) - val propertyIri = "foo:Property" - val values = List( - NewValueInfo( - resourceIri = resourceIri, - propertyIri = "foo:Property", - valueIri = valueIri, - valueTypeIri = OntologyConstants.KnoraBase.IntValue, - valueUUID = uuid, - value = TypeSpecificValueInfo.IntegerValueInfo(42), - valuePermissions = valuePermissions, - valueCreator = valueCreator, - creationDate = valueCreationDate, - valueHasOrder = 1, - valueHasString = "42", - comment = None, - ), - ) - - val resource = resourceDefinition.copy(newValueInfos = values) + val resource = resourceDefinition.copy(newValueInfos = List(intValueDefinition(uuid))) val expected = Update(s"""|