Skip to content

Commit

Permalink
restructure test
Browse files Browse the repository at this point in the history
  • Loading branch information
BalduinLandolt committed Jun 18, 2024
1 parent 201dbdf commit 1fc1234
Showing 1 changed file with 39 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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.*

Check notice on line 68 in webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

webapi/src/test/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLiveSpec.scala#L68

Put imports in the beginning of the package

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"""|
Expand Down Expand Up @@ -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"""|
Expand Down

0 comments on commit 1fc1234

Please sign in to comment.