Skip to content

Commit

Permalink
reorganised shared classes (#191)
Browse files Browse the repository at this point in the history
* reorganised shared classes

* sort out a few more imports
  • Loading branch information
jbwheatley authored Oct 31, 2020
1 parent ff864e2 commit 85978df
Show file tree
Hide file tree
Showing 96 changed files with 1,051 additions and 1,017 deletions.
18 changes: 10 additions & 8 deletions pact-spec-tests/src/test/scala/pactspec/util/PactSpecLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package pactspec.util
import argonaut.Argonaut._
import argonaut.{CodecJson, Json}
import com.itv.scalapact.argonaut62.PactImplicits
import com.itv.scalapact.shared.utils.PactLogger
import com.itv.scalapact.shared.{InteractionRequest, InteractionResponse}

import scala.io.Source
import scala.language.implicitConversions
import com.itv.scalapact.shared.RightBiasEither._
import com.itv.scalapact.shared.PactLogger
import com.itv.scalapact.shared.utils.RightBiasEither._

object PactSpecLoader {

Expand All @@ -29,12 +29,14 @@ object PactSpecLoader {
"actual"
)

def fromResource(version: String, path: String): String =
def fromResource(version: String, path: String): String = {
//PactLogger.message("Loading spec: " + s"/pact-specification-version-$version/testcases$path")
Source
val source = Source
.fromURL(getClass.getResource(s"/pact-specification-version-$version/testcases$path"))
.getLines()
.mkString("\n")
val res = source.getLines().mkString("\n")
source.close()
res
}

def deserializeRequestSpec(json: String): Option[RequestSpec] =
SpecReader.jsonStringToRequestSpec(json) match {
Expand Down Expand Up @@ -100,12 +102,12 @@ object JsonBodySpecialCaseHelper {

val extractMatches: String => Either[String, Boolean] = json =>
json.parse
.map(j => (j.hcursor --\ "match").focus.flatMap(_.bool).exists(_ == true)) //Uses exists for 2.10 compt
.map(j => (j.hcursor --\ "match").focus.flatMap(_.bool).contains(true))
.leftMap(e => "Extracting 'match': " + e)

val extractComment: String => Either[String, String] = json =>
json.parse
.map(j => (j.hcursor --\ "comment").focus.flatMap(_.string).map(_.toString()).getOrElse("<missing comment>"))
.map(j => (j.hcursor --\ "comment").focus.flatMap(_.string).getOrElse("<missing comment>"))
.leftMap(e => "Extracting 'comment': " + e)

def extractInteractionRequestOrResponse[I]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.itv.scalapact.plugin.shared

import com.itv.scalapact.shared.ColourOutput._
import com.itv.scalapact.shared.utils.ColourOutput._
import com.itv.scalapact.shared._
import com.itv.scalapact.shared.typeclasses.{IPactReader, IPactWriter, IScalaPactHttpClientBuilder}
import com.itv.scalapact.shared.http.IScalaPactHttpClientBuilder
import com.itv.scalapact.shared.json.{IPactReader, IPactWriter}
import com.itv.scalapact.shared.utils.PactLogger
import com.itv.scalapactcore.publisher.{PublishFailed, PublishResult, PublishSuccess, Publisher}

import scala.concurrent.duration._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.itv.scalapact.plugin.shared

import com.itv.scalapact.shared.ColourOutput._
import com.itv.scalapact.shared.typeclasses.{IPactReader, IPactStubber, IPactWriter}
import com.itv.scalapact.shared.{PactLogger, ScalaPactSettings, SslContextMap}
import com.itv.scalapact.shared.{IPactStubber, ScalaPactSettings}
import com.itv.scalapact.shared.utils.ColourOutput._
import com.itv.scalapact.shared.http.SslContextMap
import com.itv.scalapact.shared.json.{IPactReader, IPactWriter}
import com.itv.scalapact.shared.utils.PactLogger
import com.itv.scalapactcore.common.LocalPactFileLoader._
import com.itv.scalapactcore.common.stubber.InteractionManager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.itv.scalapact.plugin.shared

import java.io.File

import com.itv.scalapact.shared.{BuildInfo, Pact, PactLogger, ScalaPactSettings}
import com.itv.scalapact.shared.ColourOutput._
import com.itv.scalapact.shared.json.{IPactReader, IPactWriter}
import com.itv.scalapact.shared.{BuildInfo, Pact, ScalaPactSettings}
import com.itv.scalapact.shared.utils.ColourOutput._
import com.itv.scalapact.shared.utils.PactLogger

import scala.io.Source
import com.itv.scalapact.shared.typeclasses.{IPactReader, IPactWriter}

import scala.util.Try

object ScalaPactTestCommand {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.itv.scalapact.plugin.shared

import com.itv.scalapact.shared.ColourOutput._
import com.itv.scalapact.shared.utils.ColourOutput._
import com.itv.scalapact.shared._
import com.itv.scalapact.shared.typeclasses.{IPactReader, IPactWriter, IScalaPactHttpClientBuilder}
import com.itv.scalapact.shared.ProviderStateResult.SetupProviderState
import com.itv.scalapact.shared.http.IScalaPactHttpClientBuilder
import com.itv.scalapact.shared.json.{IPactReader, IPactWriter}
import com.itv.scalapact.shared.utils.PactLogger
import com.itv.scalapactcore.verifier.Verifier

import scala.concurrent.duration._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ScalaPactVerifyCommandSpec extends FunSpec with Matchers {
)
)

val patternMatchedStates: PartialFunction[String, ProviderStateResult] = { case (_: String) => ProviderStateResult() }
val patternMatchedStates: PartialFunction[String, ProviderStateResult] = { case _: String => ProviderStateResult() }

val combined =
ScalaPactVerifyCommand.combineProviderStatesIntoTotalFunction(directPactStates, patternMatchedStates)
Expand Down Expand Up @@ -122,7 +122,7 @@ class ScalaPactVerifyCommandSpec extends FunSpec with Matchers {
var result = ""

val directPactStates: Seq[(String, SetupProviderState)] = Seq()
val patternMatchedStates: PartialFunction[String, ProviderStateResult] = { case (_: String) => ProviderStateResult() }
val patternMatchedStates: PartialFunction[String, ProviderStateResult] = { case _: String => ProviderStateResult() }

val combined =
ScalaPactVerifyCommand.combineProviderStatesIntoTotalFunction(directPactStates, patternMatchedStates)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.itv.scalapact.argonaut62

import argonaut._
import com.itv.scalapact.shared.ColourOutput._
import com.itv.scalapact.shared.{IJsonConversionFunctions, PactLogger}
import com.itv.scalapact.shared.utils.ColourOutput._
import com.itv.scalapact.shared.json.IJsonConversionFunctions
import com.itv.scalapact.shared.matchir.IrNodePath.IrNodePathEmpty
import com.itv.scalapact.shared.matchir.MatchIrConstants.{rootNodeLabel, unnamedNodeLabel}
import com.itv.scalapact.shared.matchir._
import com.itv.scalapact.shared.utils.PactLogger

object JsonConversionFunctions extends IJsonConversionFunctions {

Expand All @@ -13,7 +15,7 @@ object JsonConversionFunctions extends IJsonConversionFunctions {
jsonRootToIrNode(json, IrNodePathEmpty)
}

def jsonToIrNode(label: String, json: Json, pathToParent: IrNodePath): IrNode =
private def jsonToIrNode(label: String, json: Json, pathToParent: IrNodePath): IrNode =
json match {
case j: Json if j.isArray =>
IrNode(label, jsonArrayToIrNodeList(label, j, pathToParent)).withPath(pathToParent).markAsArray
Expand All @@ -34,7 +36,7 @@ object JsonConversionFunctions extends IJsonConversionFunctions {
IrNode(label, j.string.map(IrStringNode)).withPath(pathToParent)
}

def jsonObjectToIrNodeList(json: Json, pathToParent: IrNodePath): List[IrNode] =
private def jsonObjectToIrNodeList(json: Json, pathToParent: IrNodePath): List[IrNode] =
json.objectFieldsOrEmpty
.map(l => if (l.isEmpty) unnamedNodeLabel else l)
.map { l =>
Expand All @@ -44,11 +46,11 @@ object JsonConversionFunctions extends IJsonConversionFunctions {
}
.collect { case Some(s) => s }

def jsonArrayToIrNodeList(parentLabel: String, json: Json, pathToParent: IrNodePath): List[IrNode] =
private def jsonArrayToIrNodeList(parentLabel: String, json: Json, pathToParent: IrNodePath): List[IrNode] =
json.arrayOrEmpty.zipWithIndex
.map(j => jsonToIrNode(parentLabel, j._1, pathToParent <~ j._2))

def jsonRootToIrNode(json: Json, initialPath: IrNodePath): Option[IrNode] =
private def jsonRootToIrNode(json: Json, initialPath: IrNodePath): Option[IrNode] =
json match {
case j: Json if j.isArray =>
Option(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.itv.scalapact.argonaut62

import argonaut.Argonaut._
import argonaut._
import com.itv.scalapact.shared._
import argonaut.Parse
import com.itv.scalapact.shared
import argonaut.{Parse, _}
import com.itv.scalapact.shared.Notice.{AfterVerificationNotice, BeforeVerificationNotice, PendingStateNotice, SimpleNotice}
import com.itv.scalapact.shared.Pact.Links
import com.itv.scalapact.shared.VerificationProperties.{PendingStateVerificationProperties, SimpleVerificationProperties}
import com.itv.scalapact.shared._

import scala.util.{Failure, Success, Try}

Expand Down Expand Up @@ -152,7 +149,7 @@ object PactImplicits {
}
}

implicit lazy val verificationPropertiesDecoder: DecodeJson[VerificationProperties] = DecodeJson[shared.VerificationProperties] { cur =>
implicit lazy val verificationPropertiesDecoder: DecodeJson[VerificationProperties] = DecodeJson[VerificationProperties] { cur =>
cur.get[Option[Boolean]]("pending").flatMap {
case Some(pending) => cur.get[List[PendingStateNotice]]("notices").map(PendingStateVerificationProperties(pending, _))
case None => cur.get[List[SimpleNotice]]("notices").map(SimpleVerificationProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.itv.scalapact.argonaut62

import argonaut._
import com.itv.scalapact.shared._
import com.itv.scalapact.shared.json.IPactReader
import com.itv.scalapact.shared.matchir.IrNode
import com.itv.scalapact.shared.typeclasses.IPactReader

class PactReader extends IPactReader {
import PactImplicits._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.itv.scalapact.argonaut62

import argonaut.Argonaut._
import argonaut._
import com.itv.scalapact.shared.typeclasses.IPactWriter
import com.itv.scalapact.shared.{Pact, PactMetaData, PactsForVerificationRequest, VersionMetaData}
import com.itv.scalapact.shared.json.IPactWriter

class PactWriter extends IPactWriter {
import PactImplicits._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.itv.scalapact

import com.itv.scalapact.shared.typeclasses.{IPactReader, IPactWriter}
import com.itv.scalapact.shared.json.{IPactReader, IPactWriter}

package object argonaut62 {

implicit val pactReaderInstance: IPactReader =
new PactReader

implicit val pactWriterInstance: IPactWriter =
new PactWriter

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.itv.scalapact

import com.itv.scalapact.argonaut62.{PactReader, PactWriter}
import com.itv.scalapact.shared.typeclasses.{IPactReader, IPactWriter}
import com.itv.scalapact.shared.json.{IPactReader, IPactWriter}

package object json {
implicit val pactReaderInstance: IPactReader =
new PactReader

implicit val pactWriterInstance: IPactWriter =
new PactWriter

val JsonConversionFunctions: argonaut62.JsonConversionFunctions.type = argonaut62.JsonConversionFunctions
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.itv.scalapact.circe13

import com.itv.scalapact.shared.ColourOutput._
import com.itv.scalapact.shared.{IJsonConversionFunctions, PactLogger}
import com.itv.scalapact.shared.utils.ColourOutput._
import com.itv.scalapact.shared.json.IJsonConversionFunctions
import com.itv.scalapact.shared.matchir.IrNodePath.IrNodePathEmpty
import com.itv.scalapact.shared.matchir.MatchIrConstants.{rootNodeLabel, unnamedNodeLabel}
import com.itv.scalapact.shared.matchir._
import com.itv.scalapact.shared.utils.PactLogger
import io.circe._
import io.circe.parser._

Expand All @@ -14,7 +16,7 @@ object JsonConversionFunctions extends IJsonConversionFunctions {
jsonRootToIrNode(json, IrNodePathEmpty)
}

def jsonToIrNode(label: String, json: Json, pathToParent: IrNodePath): IrNode =
private def jsonToIrNode(label: String, json: Json, pathToParent: IrNodePath): IrNode =
json match {
case j: Json if j.isArray =>
IrNode(label, jsonArrayToIrNodeList(label, j, pathToParent)).withPath(pathToParent).markAsArray
Expand All @@ -35,7 +37,7 @@ object JsonConversionFunctions extends IJsonConversionFunctions {
IrNode(label, j.asString.map(IrStringNode)).withPath(pathToParent)
}

def jsonObjectToIrNodeList(json: Json, pathToParent: IrNodePath): List[IrNode] =
private def jsonObjectToIrNodeList(json: Json, pathToParent: IrNodePath): List[IrNode] =
json.hcursor.keys
.map(_.toSet)
.map(_.toList)
Expand All @@ -48,14 +50,14 @@ object JsonConversionFunctions extends IJsonConversionFunctions {
}
.collect { case Some(s) => s }

def jsonArrayToIrNodeList(parentLabel: String, json: Json, pathToParent: IrNodePath): List[IrNode] =
private def jsonArrayToIrNodeList(parentLabel: String, json: Json, pathToParent: IrNodePath): List[IrNode] =
json.asArray
.map(_.toList)
.getOrElse(Nil)
.zipWithIndex
.map(j => jsonToIrNode(parentLabel, j._1, pathToParent <~ j._2))

def jsonRootToIrNode(json: Json, initialPath: IrNodePath): Option[IrNode] =
private def jsonRootToIrNode(json: Json, initialPath: IrNodePath): Option[IrNode] =
json match {
case j: Json if j.isArray =>
Option(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.itv.scalapact.circe13

import com.itv.scalapact.shared.typeclasses.{IPactReader, IPactWriter}
import com.itv.scalapact.shared.json.{IPactReader, IPactWriter}

trait JsonInstances {
implicit val pactReaderInstance: IPactReader = new PactReader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.itv.scalapact.circe13

import com.itv.scalapact.shared.Notice.{AfterVerificationNotice, BeforeVerificationNotice, PendingStateNotice, SimpleNotice}
import com.itv.scalapact.shared.Pact.Links
import com.itv.scalapact.shared.VerificationProperties.{PendingStateVerificationProperties, SimpleVerificationProperties}
import com.itv.scalapact.shared.{ConsumerVersionSelector, PactForVerification, EmbeddedPactsForVerification, HALIndex, Interaction, InteractionRequest, InteractionResponse, LinkValues, MatchingRule, Pact, PactActor, PactMetaData, PactsForVerificationRequest, PactsForVerificationResponse, VerificationProperties, VersionMetaData}
import com.itv.scalapact.shared._
import io.circe.{Codec, Decoder, DecodingFailure, Encoder, Json, parser}
import io.circe.generic.semiauto.{deriveCodec, deriveDecoder, deriveEncoder}
import io.circe.syntax._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.itv.scalapact.circe13

import com.itv.scalapact.shared._
import com.itv.scalapact.shared.json.IPactReader
import com.itv.scalapact.shared.matchir.IrNode
import com.itv.scalapact.shared.typeclasses.IPactReader
import io.circe.Decoder
import io.circe.parser._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.itv.scalapact.circe13

import com.itv.scalapact.shared.typeclasses.IPactWriter
import com.itv.scalapact.shared.{Pact, PactMetaData, PactsForVerificationRequest, VersionMetaData}
import com.itv.scalapact.shared.json.IPactWriter
import io.circe.syntax._

class PactWriter extends IPactWriter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ package com.itv.scalapact

import com.itv.scalapact.circe13.JsonInstances

package object json extends JsonInstances {
val JsonConversionFunctions: circe13.JsonConversionFunctions.type = circe13.JsonConversionFunctions
}
package object json extends JsonInstances
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.itv.scalapactcore.common
import java.io.File

import com.itv.scalapact.shared.{Pact, ScalaPactSettings}
import com.itv.scalapact.shared.ColourOutput._
import com.itv.scalapact.shared.PactLogger
import com.itv.scalapact.shared.typeclasses.IPactReader
import com.itv.scalapact.shared.utils.ColourOutput._
import com.itv.scalapact.shared.json.IPactReader
import com.itv.scalapact.shared.utils.PactLogger

object LocalPactFileLoader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.itv.scalapactcore.common

import java.net.URLEncoder

import com.itv.scalapact.shared.ColourOutput._
import com.itv.scalapact.shared.utils.ColourOutput._
import com.itv.scalapact.shared._
import com.itv.scalapact.shared.typeclasses.{IPactReader, IPactWriter, IScalaPactHttpClient, IScalaPactHttpClientBuilder}
import com.itv.scalapact.shared.http.{HttpMethod, IScalaPactHttpClient, IScalaPactHttpClientBuilder, SimpleRequest, SimpleResponse}
import com.itv.scalapact.shared.json.{IPactReader, IPactWriter}
import com.itv.scalapact.shared.utils.{Helpers, PactLogger}
import com.itv.scalapactcore.common.PactBrokerHelpers._
import com.itv.scalapactcore.publisher.{PublishFailed, PublishResult, PublishSuccess}

Expand Down Expand Up @@ -198,7 +200,7 @@ class PactBrokerClient(
case Right(response) =>
if (response.is2xx) {
PactLogger.message(
s"Verification results published for provider ${result.pact.provider} and consumer ${result.pact.consumer}"
s"Verification results published for provider '${result.pact.provider.name}' and consumer '${result.pact.consumer.name}'"
)
} else {
PactLogger.error(s"Publish verification results failed with ${response.statusCode}".red)
Expand Down
Loading

0 comments on commit 85978df

Please sign in to comment.