Skip to content

Commit

Permalink
test: Add test for providing an empty list as values for a required p…
Browse files Browse the repository at this point in the history
…roperty (DEV-4017) (#3357)
  • Loading branch information
seakayone authored Sep 9, 2024
1 parent 3ba1d84 commit e95ffb2
Showing 1 changed file with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.apache.pekko.testkit.ImplicitSender
import org.xmlunit.builder.DiffBuilder
import org.xmlunit.builder.Input
import org.xmlunit.diff.Diff
import zio.ULayer
import zio.ZIO

import java.time.Instant
Expand All @@ -20,6 +21,7 @@ import scala.concurrent.duration.*
import dsp.errors.*
import dsp.valueobjects.UuidUtil
import org.knora.webapi.*
import org.knora.webapi.core.LayersTest.DefaultTestEnvironmentWithoutSipi
import org.knora.webapi.messages.IriConversions.*
import org.knora.webapi.messages.OntologyConstants
import org.knora.webapi.messages.SmartIri
Expand Down Expand Up @@ -58,7 +60,7 @@ object ResourcesResponderV2Spec {
private val defaultStillImageFileValuePermissions =
"M knora-admin:Creator,knora-admin:ProjectMember|V knora-admin:KnownUser,knora-admin:UnknownUser"

private val zeitglöckleinIri = "http://rdfh.ch/0803/c5058f3a"
private val zeitgloeckleinIri = "http://rdfh.ch/0803/c5058f3a"

private val aThingIri = "http://rdfh.ch/0001/a-thing"
private var aThingLastModificationDate = Instant.now
Expand Down Expand Up @@ -410,9 +412,10 @@ 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.integrationTestsWithFusekiTestcontainers()
override lazy val effectLayers: ULayer[DefaultTestEnvironmentWithoutSipi] =
core.LayersTest.integrationTestsWithFusekiTestcontainers()

override lazy val rdfDataObjects = List(
override lazy val rdfDataObjects: List[RdfDataObject] = List(
RdfDataObject(
path = "test_data/project_data/incunabula-data.ttl",
name = "http://www.knora.org/data/0803/incunabula",
Expand Down Expand Up @@ -914,6 +917,21 @@ class ResourcesResponderV2Spec extends CoreSpec with ImplicitSender {
)
}

"not create a resource when empty list for required property is provided" in {
val createThis = CreateResourceV2(
Some(stringFormatter.makeRandomResourceIri(SharedTestDataADM.anythingProject.shortcode).toSmartIri),
"http://www.knora.org/ontology/0803/incunabula#book".toSmartIri,
"test book",
Map("http://www.knora.org/ontology/0803/incunabula#title".toSmartIri -> Seq.empty),
SharedTestDataADM.incunabulaProject,
)

val req = CreateResourceRequestV2(createThis, incunabulaUserProfile, UUID.randomUUID)

val exit = UnsafeZioRun.run(resourcesResponderV2(_.createResource(req)))
assertFailsWithA[OntologyConstraintException](exit)
}

"create a resource with no values and custom permissions" in {
// Create the resource.

Expand Down Expand Up @@ -1578,7 +1596,7 @@ class ResourcesResponderV2Spec extends CoreSpec with ImplicitSender {
CreateValueInNewResourceV2(
valueContent = LinkValueContentV2(
ontologySchema = ApiV2Complex,
referredResourceIri = zeitglöckleinIri,
referredResourceIri = zeitgloeckleinIri,
),
),
),
Expand Down Expand Up @@ -1876,8 +1894,8 @@ class ResourcesResponderV2Spec extends CoreSpec with ImplicitSender {
response.resources.size should equal(1)
val resource = response.resources.head
resource.resourceClassIri should equal(OntologyConstants.KnoraBase.DeletedResource.toSmartIri)
resource.deletionInfo should not be (None)
resource.lastModificationDate should not be (None)
resource.deletionInfo should not be None
resource.lastModificationDate should not be None
resource.creationDate should equal(aThingCreationDate)
}
}
Expand Down Expand Up @@ -2389,7 +2407,7 @@ class ResourcesResponderV2Spec extends CoreSpec with ImplicitSender {
val response: ResourceAndValueVersionHistoryResponseV2 =
expectMsgType[ResourceAndValueVersionHistoryResponseV2](timeout)
val events: Seq[ResourceAndValueHistoryEvent] = response.historyEvents
events.size shouldEqual (3)
events.size shouldEqual 3
val createResourceEvents =
events.filter(historyEvent => historyEvent.eventType == ResourceAndValueEventsUtil.CREATE_RESOURCE_EVENT)
createResourceEvents.size should be(1)
Expand Down Expand Up @@ -2448,7 +2466,7 @@ class ResourcesResponderV2Spec extends CoreSpec with ImplicitSender {
assert(updatePermissionEvent.isDefined)
val updatePermissionPayload = updatePermissionEvent.get.eventBody
.asInstanceOf[ValueEventBody]
updatePermissionPayload.valueIri shouldEqual (updateValuePermissionResponse.valueIri)
updatePermissionPayload.valueIri shouldEqual updateValuePermissionResponse.valueIri
}

"create a new value to test create value history event" in {
Expand Down

0 comments on commit e95ffb2

Please sign in to comment.