Skip to content

Commit

Permalink
refactor: remove unnecessary runTest from service-related test cases …
Browse files Browse the repository at this point in the history
…and rename ServiceBlock remnants to ServiceMap
  • Loading branch information
cpatsonakis committed Sep 21, 2024
1 parent 18c691f commit 999560b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package id.walt.did.serialize.service

import id.walt.crypto.utils.JsonUtils.toJsonElement
import id.walt.did.dids.document.models.service.*
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.buildJsonObject
Expand All @@ -12,7 +11,7 @@ import kotlin.test.assertEquals
class ServiceEndpointTest {

@Test
fun testServiceEndpointURLSerialization() = runTest {
fun testServiceEndpointURLSerialization() {
val svcEndpoint = ServiceEndpointURL("something")
val svcJsonEncodedString = "\"${svcEndpoint.url}\""
//encoding single element
Expand Down Expand Up @@ -43,7 +42,7 @@ class ServiceEndpointTest {
}

@Test
fun testServiceEndpointObjectSerialization() = runTest {
fun testServiceEndpointObjectSerialization() {
val svcEndpointJsonObject = ServiceEndpointObject(
buildJsonObject {
put("some-url-property", "url-value".toJsonElement())
Expand Down Expand Up @@ -91,7 +90,7 @@ class ServiceEndpointTest {
}

@Test
fun testServiceEndpointMixedSerialization() = runTest {
fun testServiceEndpointMixedSerialization() {
val mixSvcEndpointList = listOf(
ServiceEndpointObject(
buildJsonObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ import id.walt.did.dids.document.models.service.ServiceMap
import id.walt.did.dids.document.models.service.ServiceEndpointObject
import id.walt.did.dids.document.models.service.ServiceEndpointURL
import id.walt.did.dids.document.models.service.RegisteredServiceType
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.buildJsonObject
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class ServiceBlockTest {
class ServiceMapTest {

private val customProperties = mapOf(
"ckey1" to "cvalue1".toJsonElement(),
"ckey2" to "cvalue2".toJsonElement(),
)

@Test
fun testServiceBlockEndpointURLSerialization() = runTest {
fun testServiceMapEndpointURLSerialization() {
//with URL endpoint block and no custom properties
val svcBlockWithURLEndpointNoCustom = ServiceMap(
id = "some-id",
Expand Down Expand Up @@ -86,7 +85,7 @@ class ServiceBlockTest {
}

@Test
fun testServiceBlockEndpointObjectSerialization() = runTest {
fun testServiceMapEndpointObjectSerialization() {
//with object endpoint block and no custom properties
val svcBlockWithObjectEndpointNoCustom = ServiceMap(
id = "some-id",
Expand Down Expand Up @@ -165,7 +164,7 @@ class ServiceBlockTest {
}

@Test
fun testServiceBlockWithSameEndpoints() = runTest {
fun testServiceMapWithSameEndpoints() {
val svcBlockWithURLEndpoints = ServiceMap(
id = "some-id",
type = setOf(RegisteredServiceType.DIDCommMessaging.toString()),
Expand Down Expand Up @@ -221,7 +220,7 @@ class ServiceBlockTest {
}

@Test
fun testServiceBlockWithMixEndpoints() = runTest {
fun testServiceMapWithMixEndpoints() {
val svcBlock = ServiceMap(
id = "some-id",
type = setOf(RegisteredServiceType.DIDCommMessaging.toString()),
Expand Down Expand Up @@ -251,7 +250,7 @@ class ServiceBlockTest {
}

@Test
fun testServiceBlockMultipleTypes() = runTest {
fun testServiceMapMultipleTypes() {
val svcBlock = ServiceMap(
id = "some-id",
type = setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package id.walt.did.serialize.service

import id.walt.crypto.utils.JsonUtils.toJsonElement
import id.walt.did.dids.document.models.service.*
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.buildJsonObject
Expand All @@ -16,20 +15,20 @@ class ServiceTest {
"tit" to "tat".toJsonElement(),
)

private val svcBlockSingleURLNoCustom = ServiceMap(
private val svcMapSingleURLNoCustom = ServiceMap(
id = "some-id",
type = setOf(RegisteredServiceType.DIDCommMessaging.toString()),
serviceEndpoint = setOf(ServiceEndpointURL("some-url")),
)

private val svcBlockSingleURLCustom = ServiceMap(
private val svcMapSingleURLCustom = ServiceMap(
id = "some-id",
type = setOf(RegisteredServiceType.DIDCommMessaging.toString()),
serviceEndpoint = setOf(ServiceEndpointURL("some-url")),
customProperties = customProperties,
)

private val svcBlockMultipleURLNoCustom = ServiceMap(
private val svcMapMultipleURLNoCustom = ServiceMap(
id = "some-id",
type = setOf(RegisteredServiceType.DIDCommMessaging.toString()),
serviceEndpoint = setOf(
Expand All @@ -38,7 +37,7 @@ class ServiceTest {
),
)

private val svcBlockMultipleURLCustom = ServiceMap(
private val svcMapMultipleURLCustom = ServiceMap(
id = "some-id",
type = setOf(RegisteredServiceType.DIDCommMessaging.toString()),
serviceEndpoint = setOf(
Expand All @@ -48,7 +47,7 @@ class ServiceTest {
customProperties = customProperties,
)

private val svcBlockSingleObjectNoCustom = ServiceMap(
private val svcMapSingleObjectNoCustom = ServiceMap(
id = "some-id",
type = setOf(RegisteredServiceType.DIDCommMessaging.toString()),
serviceEndpoint = setOf(
Expand All @@ -61,7 +60,7 @@ class ServiceTest {
),
)

private val svcBlockSingleObjectCustom = ServiceMap(
private val svcMapSingleObjectCustom = ServiceMap(
id = "some-id",
type = setOf(RegisteredServiceType.DIDCommMessaging.toString()),
serviceEndpoint = setOf(
Expand All @@ -75,7 +74,7 @@ class ServiceTest {
customProperties = customProperties,
)

private val svcBlockMultipleObjectNoCustom = ServiceMap(
private val svcMapMultipleObjectNoCustom = ServiceMap(
id = "some-id",
type = setOf(RegisteredServiceType.DIDCommMessaging.toString()),
serviceEndpoint = setOf(
Expand All @@ -94,7 +93,7 @@ class ServiceTest {
),
)

private val svcBlockMultipleObjectCustom = ServiceMap(
private val svcMapMultipleObjectCustom = ServiceMap(
id = "some-id",
type = setOf(RegisteredServiceType.DIDCommMessaging.toString()),
serviceEndpoint = setOf(
Expand All @@ -114,20 +113,20 @@ class ServiceTest {
customProperties = customProperties,
)

private val svcBlockSet = setOf(
svcBlockSingleURLNoCustom,
svcBlockSingleURLCustom,
svcBlockMultipleURLNoCustom,
svcBlockMultipleURLCustom,
svcBlockSingleObjectNoCustom,
svcBlockSingleObjectCustom,
svcBlockMultipleObjectNoCustom,
svcBlockMultipleObjectCustom,
private val svcMapSet = setOf(
svcMapSingleURLNoCustom,
svcMapSingleURLCustom,
svcMapMultipleURLNoCustom,
svcMapMultipleURLCustom,
svcMapSingleObjectNoCustom,
svcMapSingleObjectCustom,
svcMapMultipleObjectNoCustom,
svcMapMultipleObjectCustom,
)

@Test
fun testSingleServiceSerialization() = runTest {
svcBlockSet.forEach {
fun testSingleServiceSerialization() {
svcMapSet.forEach {
val svc = Service(setOf(it))
val svcJsonString = """[${Json.encodeToString(it)}]"""
assertEquals(
Expand All @@ -142,8 +141,8 @@ class ServiceTest {
}

@Test
fun testMultiServiceSerialization() = runTest {
val svc = Service(svcBlockSet)
fun testMultiServiceSerialization() {
val svc = Service(svcMapSet)
val svcJsonString =
"""[{"id":"some-id","type":"DIDCommMessaging","serviceEndpoint":"some-url"},{"id":"some-id","type":"DIDCommMessaging","serviceEndpoint":"some-url","this":"that","tit":"tat"},{"id":"some-id","type":"DIDCommMessaging","serviceEndpoint":["some-url1","some-url2"]},{"id":"some-id","type":"DIDCommMessaging","serviceEndpoint":["some-url1","some-url2"],"this":"that","tit":"tat"},{"id":"some-id","type":"DIDCommMessaging","serviceEndpoint":{"some-url-property1":"url-value1","some-additional-property1":"some-value1"}},{"id":"some-id","type":"DIDCommMessaging","serviceEndpoint":{"some-url-property1":"url-value1","some-additional-property1":"some-value1"},"this":"that","tit":"tat"},{"id":"some-id","type":"DIDCommMessaging","serviceEndpoint":[{"some-url-property1":"url-value1","some-additional-property1":"some-value1"},{"some-url-property2":"url-value2","some-additional-property2":"some-value2"}]},{"id":"some-id","type":"DIDCommMessaging","serviceEndpoint":[{"some-url-property1":"url-value1","some-additional-property1":"some-value1"},{"some-url-property2":"url-value2","some-additional-property2":"some-value2"}],"this":"that","tit":"tat"}]"""
assertEquals(
Expand Down

0 comments on commit 999560b

Please sign in to comment.