From b8ee1bc62bdcebd6ab1a556cdd60b97c38ced55f Mon Sep 17 00:00:00 2001
From: Christopher Turner
<23338096+christopherjturner@users.noreply.github.com>
Date: Fri, 9 Aug 2019 09:42:13 +0100
Subject: [PATCH 1/2] BDOG-302 fixes service dependencies page, adds jdk
vendor, kind to page
---
.../service/DependenciesService.scala | 24 ++++++++--
app/views/DependenciesPage.scala.html | 2 +-
.../ServiceDependenciesConnectorSpec.scala | 47 +++++++++++++++++++
3 files changed, 69 insertions(+), 4 deletions(-)
diff --git a/app/uk/gov/hmrc/cataloguefrontend/service/DependenciesService.scala b/app/uk/gov/hmrc/cataloguefrontend/service/DependenciesService.scala
index e7d2cf4eb..695a13b46 100644
--- a/app/uk/gov/hmrc/cataloguefrontend/service/DependenciesService.scala
+++ b/app/uk/gov/hmrc/cataloguefrontend/service/DependenciesService.scala
@@ -36,7 +36,7 @@ class DependenciesService @Inject()(
_.map { serviceDependency =>
val environmentMappingName =
deployments
- .find(deploymentVO => serviceDependency.version.map(_ == deploymentVO.version).getOrElse(false))
+ .find(deploymentVO => serviceDependency.version.contains(deploymentVO.version))
.map(_.environmentMapping.name)
environmentMappingName match {
@@ -103,7 +103,7 @@ case class ServiceDependencies(
, name : String
, version : Option[String]
, runnerVersion: String
- , jdkVersion : String
+ , java : JDKVersion
, classpath : String
, dependencies : Seq[ServiceDependency]
, environment : Option[String] = None
@@ -117,8 +117,26 @@ case class ServiceDependencies(
}
object ServiceDependencies {
+ import play.api.libs.json.{__}
+ import play.api.libs.functional.syntax._
+
+ implicit val jdkr = (
+ Reads.pure("") // skip name field
+ ~ (__ \ "version").read[String]
+ ~ (__ \ "vendor" ).read[String]
+ ~ (__ \ "kind" ).read[String]
+ )(JDKVersion)
implicit val dependencyReads: Reads[ServiceDependency] = Json.using[Json.WithDefaultValues].reads[ServiceDependency]
- implicit val serviceDependenciesReads: Reads[ServiceDependencies] = Json.using[Json.WithDefaultValues].reads[ServiceDependencies]
+ implicit val serviceDependenciesReads: Reads[ServiceDependencies] = (
+ (__ \ "uri" ).read[String]
+ ~ (__ \ "name" ).read[String]
+ ~ (__ \ "version" ).readNullable[String]
+ ~ (__ \ "runnerVersion").read[String]
+ ~ (__ \ "java" ).read[JDKVersion]
+ ~ (__ \ "classpath" ).read[String]
+ ~ (__ \ "dependencies" ).read[Seq[ServiceDependency]]
+ ~ (__ \ "environment" ).readNullable[String]
+ )(ServiceDependencies.apply _)
}
diff --git a/app/views/DependenciesPage.scala.html b/app/views/DependenciesPage.scala.html
index f2c526220..cace548c7 100644
--- a/app/views/DependenciesPage.scala.html
+++ b/app/views/DependenciesPage.scala.html
@@ -36,7 +36,7 @@
}
-
JDK: @{serviceDependency.jdkVersion}
+
@{serviceDependency.java.kind}: @{serviceDependency.java.version} @{serviceDependency.java.vendor}
diff --git a/test/uk/gov/hmrc/cataloguefrontend/connector/ServiceDependenciesConnectorSpec.scala b/test/uk/gov/hmrc/cataloguefrontend/connector/ServiceDependenciesConnectorSpec.scala
index 9f73d0845..57ffaf36f 100644
--- a/test/uk/gov/hmrc/cataloguefrontend/connector/ServiceDependenciesConnectorSpec.scala
+++ b/test/uk/gov/hmrc/cataloguefrontend/connector/ServiceDependenciesConnectorSpec.scala
@@ -25,8 +25,10 @@ import org.scalatest.mockito.MockitoSugar
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder
+import play.api.libs.json.Json
import uk.gov.hmrc.cataloguefrontend.WireMockEndpoints
import uk.gov.hmrc.cataloguefrontend.connector.model.{Dependency, Version}
+import uk.gov.hmrc.cataloguefrontend.service.{DependenciesService, ServiceDependencies}
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.play.bootstrap.config.ServicesConfig
import uk.gov.hmrc.play.bootstrap.http.HttpClient
@@ -348,6 +350,51 @@ class ServiceDependenciesConnectorSpec
}
}
+ "JSON Reader" - {
+ "read json with java section" in {
+ import uk.gov.hmrc.cataloguefrontend.service.ServiceDependencies.serviceDependenciesReads
+ val json =""" {
+ "uri" : "https://artefactory/slugs/mobile-stub/mobile-stub_0.12.0_0.5.2.tgz",
+ "name" : "mobile-auth-stub",
+ "version" : "0.12.0",
+ "semanticVersion" : {
+ "major" : 0,
+ "minor" : 12,
+ "patch" : 0
+ },
+ "versionLong" : 12000,
+ "runnerVersion" : "0.5.2",
+ "classpath" : "",
+ "jdkVersion" : "1.8.0_191",
+ "dependencies" : [
+ {
+ "path" : "./mobile-auth-stub-0.12.0/lib/org.slf4j.slf4j-api-1.7.25.jar",
+ "version" : "1.7.25",
+ "group" : "org.slf4j",
+ "artifact" : "slf4j-api",
+ "meta" : "fromPom"
+ }
+ ],
+ "latest" : false,
+ "qa" : false,
+ "production" : false,
+ "development" : false,
+ "external test" : false,
+ "staging" : false,
+ "java" : {
+ "version" : "1.8.0_191",
+ "kind" : "JDK",
+ "vendor" : "OpenJDK"
+ }
+} """
+ val res = Json.fromJson[ServiceDependencies](Json.parse(json)).get
+
+ res.java.version shouldBe "1.8.0_191"
+ res.java.vendor shouldBe "OpenJDK"
+ res.java.kind shouldBe "JDK"
+ }
+
+ }
private trait Setup {
implicit val headerCarrier: HeaderCarrier = HeaderCarrier()
}
From 6200eaca2fbd6532c3af142102c1487249648c4d Mon Sep 17 00:00:00 2001
From: Christopher Turner
<23338096+christopherjturner@users.noreply.github.com>
Date: Tue, 13 Aug 2019 11:34:27 +0100
Subject: [PATCH 2/2] BDOG-302 revised java version model for ServiceDependency
---
.../service/DependenciesService.scala | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/app/uk/gov/hmrc/cataloguefrontend/service/DependenciesService.scala b/app/uk/gov/hmrc/cataloguefrontend/service/DependenciesService.scala
index 695a13b46..3a7457b9f 100644
--- a/app/uk/gov/hmrc/cataloguefrontend/service/DependenciesService.scala
+++ b/app/uk/gov/hmrc/cataloguefrontend/service/DependenciesService.scala
@@ -90,6 +90,9 @@ object DependenciesService {
dependencies.sortBy(serviceDependency => (serviceDependency.group, serviceDependency.artifact))
}
+
+case class ServiceJDKVersion(version: String, vendor: String, kind:String)
+
case class ServiceDependency(
path : String
, group : String
@@ -103,7 +106,7 @@ case class ServiceDependencies(
, name : String
, version : Option[String]
, runnerVersion: String
- , java : JDKVersion
+ , java : ServiceJDKVersion
, classpath : String
, dependencies : Seq[ServiceDependency]
, environment : Option[String] = None
@@ -117,15 +120,14 @@ case class ServiceDependencies(
}
object ServiceDependencies {
- import play.api.libs.json.{__}
+ import play.api.libs.json.__
import play.api.libs.functional.syntax._
implicit val jdkr = (
- Reads.pure("") // skip name field
- ~ (__ \ "version").read[String]
+ (__ \ "version").read[String]
~ (__ \ "vendor" ).read[String]
~ (__ \ "kind" ).read[String]
- )(JDKVersion)
+ )(ServiceJDKVersion)
implicit val dependencyReads: Reads[ServiceDependency] = Json.using[Json.WithDefaultValues].reads[ServiceDependency]
implicit val serviceDependenciesReads: Reads[ServiceDependencies] = (
@@ -133,7 +135,7 @@ object ServiceDependencies {
~ (__ \ "name" ).read[String]
~ (__ \ "version" ).readNullable[String]
~ (__ \ "runnerVersion").read[String]
- ~ (__ \ "java" ).read[JDKVersion]
+ ~ (__ \ "java" ).read[ServiceJDKVersion]
~ (__ \ "classpath" ).read[String]
~ (__ \ "dependencies" ).read[Seq[ServiceDependency]]
~ (__ \ "environment" ).readNullable[String]