From c0200ba00a7f540c9a4c505a900ff0c3f343244b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Urba=C5=84ski?= Date: Mon, 12 Aug 2019 14:26:09 +0200 Subject: [PATCH] Use VauntSerializer from vaunt-core instead of own mapper --- build.gradle.kts | 4 ++-- .../publisher/capabilities/VauntCapabilitiesReader.kt | 6 +++--- .../publisher/expectations/VauntExpectationsReader.kt | 6 +++--- .../publisher/gradle/plugin/PublisherPlugin.kt | 2 ++ .../contracts/publisher/vaunt/VauntFileReader.kt | 5 +++-- .../contracts/publisher/vaunt/VauntObjectMapper.kt | 7 ------- .../publisher/gradle/plugin/PublisherPluginSpec.groovy | 10 +++++----- src/test/resources/vaunt/information-service.json | 10 +++++----- 8 files changed, 23 insertions(+), 27 deletions(-) delete mode 100644 src/main/kotlin/com/hltech/judged/contracts/publisher/vaunt/VauntObjectMapper.kt diff --git a/build.gradle.kts b/build.gradle.kts index 69a1367..f51bd5c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { } group = "com.hltech" -version = "1.0.1" +version = "1.0.2" repositories { mavenCentral() @@ -29,7 +29,7 @@ dependencies { implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.9.7") implementation("io.github.openfeign:feign-core:9.7.0") implementation("io.github.openfeign:feign-jackson:9.7.0") - implementation("com.hltech:vaunt-core:1.0.16") + implementation("com.hltech:vaunt-core:1.0.24") testImplementation(gradleTestKit()) testImplementation("org.spockframework:spock-core:1.2-groovy-2.5") diff --git a/src/main/kotlin/com/hltech/judged/contracts/publisher/capabilities/VauntCapabilitiesReader.kt b/src/main/kotlin/com/hltech/judged/contracts/publisher/capabilities/VauntCapabilitiesReader.kt index 0efcba6..03597aa 100644 --- a/src/main/kotlin/com/hltech/judged/contracts/publisher/capabilities/VauntCapabilitiesReader.kt +++ b/src/main/kotlin/com/hltech/judged/contracts/publisher/capabilities/VauntCapabilitiesReader.kt @@ -1,20 +1,20 @@ package com.hltech.judged.contracts.publisher.capabilities import com.hltech.judged.contracts.publisher.vaunt.VauntFileReader -import com.hltech.judged.contracts.publisher.vaunt.vauntObjectMapper +import com.hltech.vaunt.core.VauntSerializer import org.gradle.api.Project class VauntCapabilitiesReader : CapabilitiesReader { private val fileReader = VauntFileReader() - private val mapper = vauntObjectMapper() + private val serializer = VauntSerializer() override fun read(project: Project): Capabilities { val contracts = fileReader.read(project) .flatMap { it.capabilities.contracts } .toList() - return Capabilities("jms", mapper.writeValueAsString(contracts), "application/json") + return Capabilities("jms", serializer.serialize(contracts), "application/json") } } \ No newline at end of file diff --git a/src/main/kotlin/com/hltech/judged/contracts/publisher/expectations/VauntExpectationsReader.kt b/src/main/kotlin/com/hltech/judged/contracts/publisher/expectations/VauntExpectationsReader.kt index 1265938..4851969 100644 --- a/src/main/kotlin/com/hltech/judged/contracts/publisher/expectations/VauntExpectationsReader.kt +++ b/src/main/kotlin/com/hltech/judged/contracts/publisher/expectations/VauntExpectationsReader.kt @@ -2,14 +2,14 @@ package com.hltech.judged.contracts.publisher.expectations import com.google.common.collect.ArrayListMultimap import com.hltech.judged.contracts.publisher.vaunt.VauntFileReader -import com.hltech.judged.contracts.publisher.vaunt.vauntObjectMapper +import com.hltech.vaunt.core.VauntSerializer import com.hltech.vaunt.core.domain.model.Contract import org.gradle.api.Project class VauntExpectationsReader : ExpectationsReader { private val fileReader = VauntFileReader() - private val mapper = vauntObjectMapper() + private val serializer = VauntSerializer() override fun read(project: Project): List { val providerNameToContracts = fileReader.read(project) @@ -21,6 +21,6 @@ class VauntExpectationsReader : ExpectationsReader { return providerNameToContracts .keySet() - .map { Expectations(it, "jms", mapper.writeValueAsString(providerNameToContracts[it]), "application/json") } + .map { Expectations(it, "jms", serializer.serialize(providerNameToContracts[it]), "application/json") } } } \ No newline at end of file diff --git a/src/main/kotlin/com/hltech/judged/contracts/publisher/gradle/plugin/PublisherPlugin.kt b/src/main/kotlin/com/hltech/judged/contracts/publisher/gradle/plugin/PublisherPlugin.kt index 051ab1f..61bf0bc 100644 --- a/src/main/kotlin/com/hltech/judged/contracts/publisher/gradle/plugin/PublisherPlugin.kt +++ b/src/main/kotlin/com/hltech/judged/contracts/publisher/gradle/plugin/PublisherPlugin.kt @@ -16,6 +16,8 @@ class PublisherPlugin : Plugin { override fun apply(project: Project) { project.task("publishContracts") { task -> + task.description = "Publish contracts to remote judge-dredd instance." + task.doLast { println("serviceName=${project.name}") println("serviceVersion=${project.version}") diff --git a/src/main/kotlin/com/hltech/judged/contracts/publisher/vaunt/VauntFileReader.kt b/src/main/kotlin/com/hltech/judged/contracts/publisher/vaunt/VauntFileReader.kt index b2ca19a..d40cf58 100644 --- a/src/main/kotlin/com/hltech/judged/contracts/publisher/vaunt/VauntFileReader.kt +++ b/src/main/kotlin/com/hltech/judged/contracts/publisher/vaunt/VauntFileReader.kt @@ -1,12 +1,13 @@ package com.hltech.judged.contracts.publisher.vaunt +import com.hltech.vaunt.core.VauntSerializer import com.hltech.vaunt.core.domain.model.Service import org.gradle.api.Project import java.io.File class VauntFileReader { - private val mapper = vauntObjectMapper() + private val serializer = VauntSerializer() fun read(project: Project): List = when (val vauntLocation = project.properties[VAUNT_LOCATION_KEY]) { @@ -25,7 +26,7 @@ class VauntFileReader { println("Found ${vauntFiles.size} vaunt files") - return vauntFiles.map { mapper.readValue(it, Service::class.java) } + return vauntFiles.map { serializer.readServiceDefinition(it) } } private companion object { diff --git a/src/main/kotlin/com/hltech/judged/contracts/publisher/vaunt/VauntObjectMapper.kt b/src/main/kotlin/com/hltech/judged/contracts/publisher/vaunt/VauntObjectMapper.kt deleted file mode 100644 index caa573f..0000000 --- a/src/main/kotlin/com/hltech/judged/contracts/publisher/vaunt/VauntObjectMapper.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.hltech.judged.contracts.publisher.vaunt - -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.datatype.guava.GuavaModule -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule - -fun vauntObjectMapper(): ObjectMapper = ObjectMapper().registerModule(GuavaModule()).registerModule(JavaTimeModule()) \ No newline at end of file diff --git a/src/test/groovy/com/hltech/judged/contracts/publisher/gradle/plugin/PublisherPluginSpec.groovy b/src/test/groovy/com/hltech/judged/contracts/publisher/gradle/plugin/PublisherPluginSpec.groovy index 438dadb..672762c 100644 --- a/src/test/groovy/com/hltech/judged/contracts/publisher/gradle/plugin/PublisherPluginSpec.groovy +++ b/src/test/groovy/com/hltech/judged/contracts/publisher/gradle/plugin/PublisherPluginSpec.groovy @@ -115,7 +115,7 @@ class PublisherPluginSpec extends Specification { { "destinationType": "QUEUE", "destinationName": "request_for_information_queue", - "body": { + "message": { "type": "object", "id": "urn:jsonschema:com:hltech:vaunt:generator:domain:representation:RepresentationWriterSpec:RequestMessage", "properties": { @@ -128,7 +128,7 @@ class PublisherPluginSpec extends Specification { { "destinationType": "TOPIC", "destinationName": "something_changed_topic", - "body": { + "message": { "type": "object", "id": "urn:jsonschema:com:hltech:vaunt:generator:domain:representation:RepresentationWriterSpec:ChangedEvent", "properties": { @@ -173,7 +173,7 @@ class PublisherPluginSpec extends Specification { { "destinationType": "QUEUE", "destinationName": "audit_queue", - "body": { + "message": { "type": "object", "id": "urn:jsonschema:com:hltech:vaunt:generator:domain:representation:RepresentationWriterSpec:AuditMessage", "properties": { @@ -193,7 +193,7 @@ class PublisherPluginSpec extends Specification { { "destinationType": "QUEUE", "destinationName": "reject_information_queue", - "body": { + "message": { "type": "object", "id": "urn:jsonschema:com:hltech:vaunt:generator:domain:representation:RepresentationWriterSpec:RejectMessage", "properties": { @@ -209,7 +209,7 @@ class PublisherPluginSpec extends Specification { { "destinationType": "QUEUE", "destinationName": "accept_information_queue", - "body": { + "message": { "type": "object", "id": "urn:jsonschema:com:hltech:vaunt:generator:domain:representation:RepresentationWriterSpec:AcceptMessage", "properties": { diff --git a/src/test/resources/vaunt/information-service.json b/src/test/resources/vaunt/information-service.json index 585b9a4..9211b4c 100644 --- a/src/test/resources/vaunt/information-service.json +++ b/src/test/resources/vaunt/information-service.json @@ -5,7 +5,7 @@ { "destinationType": "QUEUE", "destinationName": "request_for_information_queue", - "body": { + "message": { "type": "object", "id": "urn:jsonschema:com:hltech:vaunt:generator:domain:representation:RepresentationWriterSpec:RequestMessage", "properties": { @@ -18,7 +18,7 @@ { "destinationType": "TOPIC", "destinationName": "something_changed_topic", - "body": { + "message": { "type": "object", "id": "urn:jsonschema:com:hltech:vaunt:generator:domain:representation:RepresentationWriterSpec:ChangedEvent", "properties": { @@ -36,7 +36,7 @@ { "destinationType": "QUEUE", "destinationName": "audit_queue", - "body": { + "message": { "type": "object", "id": "urn:jsonschema:com:hltech:vaunt:generator:domain:representation:RepresentationWriterSpec:AuditMessage", "properties": { @@ -51,7 +51,7 @@ { "destinationType": "QUEUE", "destinationName": "reject_information_queue", - "body": { + "message": { "type": "object", "id": "urn:jsonschema:com:hltech:vaunt:generator:domain:representation:RepresentationWriterSpec:RejectMessage", "properties": { @@ -67,7 +67,7 @@ { "destinationType": "QUEUE", "destinationName": "accept_information_queue", - "body": { + "message": { "type": "object", "id": "urn:jsonschema:com:hltech:vaunt:generator:domain:representation:RepresentationWriterSpec:AcceptMessage", "properties": {