diff --git a/protocol/src/test/kotlin/tbdex/sdk/protocol/MessagesVectorTest.kt b/protocol/src/test/kotlin/tbdex/sdk/protocol/MessagesVectorTest.kt index 55f2d9c9..00a8bd9d 100644 --- a/protocol/src/test/kotlin/tbdex/sdk/protocol/MessagesVectorTest.kt +++ b/protocol/src/test/kotlin/tbdex/sdk/protocol/MessagesVectorTest.kt @@ -1,5 +1,8 @@ package tbdex.sdk.protocol +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import org.junit.jupiter.api.Test import tbdex.sdk.protocol.models.Close import tbdex.sdk.protocol.models.Message @@ -10,52 +13,24 @@ import tbdex.sdk.protocol.models.Rfq import tbdex.sdk.protocol.serialization.Json import kotlin.test.assertEquals import kotlin.test.assertIs +import kotlin.test.assertNotNull class MessagesVectorTest { @Test - fun `parse rfq`() { - testParsing(TestVectors.rfq()) - } - - @Test - fun `serialize rfq`() { - testSerialisation(TestVectors.rfq()) - } - @Test - fun `parse quote`() { - testParsing(TestVectors.quote()) - } - - @Test - fun `serialize quote`() { - testSerialisation(TestVectors.quote()) - } - @Test - fun `parse order`() { - testParsing(TestVectors.order()) - } + fun `parse-close json`() { + val vector = TestVectors.getVector("parse-rfq.json") + assertNotNull(vector) - @Test - fun `serialize order`() { - testSerialisation(TestVectors.order()) - } - @Test - fun `parse order status`() { - testParsing(TestVectors.orderStatus()) - } + // `input` is stringified JSON, which we must parse separately + val input = vector["input"].textValue() + assertNotNull(input) - @Test - fun `serialize order status`() { - testSerialisation(TestVectors.orderStatus()) - } - @Test - fun `parse close`() { - testParsing(TestVectors.close()) - } + val tbDEXMessage = Message.parse(input) + assertIs(tbDEXMessage) - @Test - fun `serialize close`() { - testSerialisation(TestVectors.close()) + // Test parsed input json is the same as output json +// val output = vector["output"] +// assertEquals(output, Json.jsonMapper.readTree(tbDEXMessage.toString())) } /** diff --git a/protocol/src/test/kotlin/tbdex/sdk/protocol/ResourceVectorTest.kt b/protocol/src/test/kotlin/tbdex/sdk/protocol/ResourceVectorTest.kt index ea6b948c..2f8d1669 100644 --- a/protocol/src/test/kotlin/tbdex/sdk/protocol/ResourceVectorTest.kt +++ b/protocol/src/test/kotlin/tbdex/sdk/protocol/ResourceVectorTest.kt @@ -8,20 +8,4 @@ import kotlin.test.assertEquals import kotlin.test.assertIs class ResourceVectorTest { - @Test - fun `parse offering`() { - val serializedOffering = TestVectors.offering() - val offering = Resource.parse(serializedOffering) - assertIs(offering) - } - - @Test - fun `serialized offering matches original`() { - val serializedOffering = TestVectors.offering() - val offering = Resource.parse(serializedOffering) - val serializedOffering2 = Json.stringify(offering) - - assertEquals(serializedOffering, serializedOffering2) - } - } \ No newline at end of file diff --git a/protocol/src/test/kotlin/tbdex/sdk/protocol/TestVectors.kt b/protocol/src/test/kotlin/tbdex/sdk/protocol/TestVectors.kt index 3a0bbddf..5f4acc4d 100644 --- a/protocol/src/test/kotlin/tbdex/sdk/protocol/TestVectors.kt +++ b/protocol/src/test/kotlin/tbdex/sdk/protocol/TestVectors.kt @@ -4,36 +4,27 @@ import com.fasterxml.jackson.databind.JsonNode import tbdex.sdk.protocol.serialization.Json object TestVectors { -// val vectors = readVectors() -// -// fun readVectors(): JsonNode { -// val loader = Thread.currentThread().contextClassLoader -// val vectorsJson = loader.getResourceAsStream("testVectors.json")?.bufferedReader()?.readText()!! -// return Json.jsonMapper.readTree(vectorsJson) -// } + val vectors = readVectors() - fun offering(): String { + fun readVectors(): MutableMap { val loader = Thread.currentThread().contextClassLoader - return loader.getResourceAsStream("test-vectors/parse-offering.json")?.bufferedReader()?.readText()!! + val vectors = mutableMapOf(); + val vectorFiles = arrayOf( + "parse-close.json", + "parse-offering.json", + "parse-order.json", + "parse-orderstatus.json", + "parse-quote.json", + "parse-rfq.json" + ) + for (vectorFile in vectorFiles) { + val vectorJson = loader.getResourceAsStream("test-vectors/$vectorFile")?.bufferedReader()?.readText()!! + vectors[vectorFile] = Json.jsonMapper.readTree(vectorJson) + } + return vectors } - fun rfq(): String { - val loader = Thread.currentThread().contextClassLoader - return loader.getResourceAsStream("test-vectors/parse-rfq.json")?.bufferedReader()?.readText()!! - } - fun quote(): String { - val loader = Thread.currentThread().contextClassLoader - return loader.getResourceAsStream("test-vectors/parse-quote.json")?.bufferedReader()?.readText()!! - } - fun order(): String { - val loader = Thread.currentThread().contextClassLoader - return loader.getResourceAsStream("test-vectors/parse-order.json")?.bufferedReader()?.readText()!! - } - fun orderStatus(): String { - val loader = Thread.currentThread().contextClassLoader - return loader.getResourceAsStream("test-vectors/parse-orderstatus.json")?.bufferedReader()?.readText()!! - } - fun close(): String { - val loader = Thread.currentThread().contextClassLoader - return loader.getResourceAsStream("test-vectors/parse-close.json")?.bufferedReader()?.readText()!! + + fun getVector(vectorFile: String): JsonNode? { + return vectors[vectorFile] } } \ No newline at end of file