GithubHelp home page GithubHelp logo

usr42 / pact-jvm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pact-foundation/pact-jvm

0.0 0.0 0.0 6.45 MB

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.

Home Page: https://docs.pact.io

License: Apache License 2.0

Groovy 39.92% Java 35.43% Clojure 0.43% Kotlin 16.45% Scala 7.75% Dockerfile 0.03%

pact-jvm's People

Contributors

abubics avatar bbarke avatar benjamindebeerst avatar bethesque avatar ehmkah avatar fitzoh avatar georgepapas avatar groboclown avatar jcreixell avatar jeffreymyers avatar jon-ruckwood avatar kenbot avatar kirillartamonov-tomtom avatar lordofthejars avatar marcpa00 avatar mefellows avatar ohubaut avatar pkubowicz avatar raceconditions avatar siddhuwarrier avatar slu-it avatar snewsbutton avatar thetrav avatar thombergs avatar timothyjones avatar tmszdmsk avatar tobivogel avatar venksub avatar xuefengwu avatar yokotaso avatar

Watchers

 avatar  avatar

pact-jvm's Issues

Consider: use KPactResult type as return

Consideration:
Don't directly return a RequestResponsePact but a kPact owned type (let's call it KPactResult here) with a toPact() method.

This KPactResult should be a data class like type which allows to copy or maybe even mutate it's state (Design decision: immutable or not).

This would allow something like:

val pact = KPact between "Some Consumer" and "Some Provider" isDefinedBy {
    given providerState "a certain state on the provider" then {
        whenever receiving "a request for something" withPath "/hello" and {
            method("POST")
            body("{\"name\": \"harry\"}")
        } thenRespondWith {
            status(200)
            body("{\"hello\": \"harry\"}")
        }
    }
}

// mutable
pact.consumer = "other Consumer"
// immutable
pact.copy(consumer = "other Consumer")

// first proposals, maybe there are better ways and terminologies

//replace given block
pact.definition.given["a certain state on the provider"] = {
        whenever receiving "a request for something" withPath "/hello" and {
            method("POST")
            body("{\"name\": \"harry\"}")
        } thenRespondWith {
            status(400)
            body("ERROR")
        }
}

//add new given block
pact.definition +=  given providerState "2nd state" then {
        whenever receiving "a request for something" withPath "/hello" and {
            method("POST")
            body("{\"name\": \"harry\"}")
        } thenRespondWith {
            status(200)
            body("{\"hello\": \"harry\"}")
        }
    }

The trade-off is that you have to call .toPact() to get the RequestResponsePact

val pact: RequestResponsePact = KPact between "Some Consumer" and "Some Provider" isDefinedBy {
    given providerState "a certain state on the provider" then {
        whenever receiving "a request for something" withPath "/hello" and {
            method("POST")
            body("{\"name\": \"harry\"}")
        } thenRespondWith {
            status(200)
            body("{\"hello\": \"harry\"}")
        }
    }
}.toPact()

Maybe using Generics could help here?

Consider: Support nested block and flat call structure

Support nested block and flat call structure with invoke method (see Kotlin in Action 11.3.3).

            KPact.consumer("Some Consumer").hasPactWith("Some Provider") {
                given("a certain state on the provider") {
                    whenever("a request for something").withPath("/hello") {
                        method("POST")
                        body("{\"name\": \"harry\"}")
                    } thenRespondWith {
                        status(200)
                        body("{\"hello\": \"harry\"}")
                    }
            }

vs

            KPact.consumer("Some Consumer").hasPactWith("Some Provider")
                    .given("a certain state on the provider").whenever("a request for something")
                    .withPath("/hello") {
                        method("POST")
                        body("{\"name\": \"harry\"}")
                    } thenRespondWith {
                        status(200)
                        body("{\"hello\": \"harry\"}")
                    }
            }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.