Code Monkey home page Code Monkey logo

spring-cloud-contract's Introduction

Spring Cloud Connectors

Spring Cloud Connectors provides a simple abstraction that JVM-based applications can use to discover information about the cloud environment on which they are running, connect to services, and have discovered services registered as Spring beans. It provides out-of-the-box support for discovering common services on Heroku and Cloud Foundry cloud platforms, and it supports custom service definitions through Java Service Provider Interfaces (SPI).

Note
This project is in maintenance mode, in favor of the newer Java CFEnv project. We will continue to release security-related updates but will not address enhancement requests.

Learn more

Build

The project is built with Gradle. The Gradle wrapper allows you to build the project on multiple platforms and even if you do not have Gradle installed; run it in place of the gradle command (as ./gradlew) from the root of the main project directory.

To compile the project and run tests

./gradlew build

To build a JAR

./gradlew jar

To generate Javadoc API documentation

./gradlew api

To list all available tasks

./gradlew tasks

Contributing

Spring Cloud is released under the non-restrictive Apache 2.0 license, and follows a very standard Github development process, using Github tracker for issues and merging pull requests into master. If you want to contribute even something trivial please do not hesitate, but follow the guidelines below.

Sign the Contributor License Agreement

Before we accept a non-trivial patch or pull request we will need you to sign the Contributor License Agreement. Signing the contributor’s agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. Active contributors might be asked to join the core team, and given the ability to merge pull requests.

Code of Conduct

This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].

Code Conventions and Housekeeping

None of these is essential for a pull request, but they will all help. They can also be added after the original pull request but before a merge.

  • Use the Spring Framework code format conventions. If you use Eclipse you can import formatter settings using the eclipse-code-formatter.xml file from the Spring Cloud Build project. If using IntelliJ, you can use the Eclipse Code Formatter Plugin to import the same file.

  • Make sure all new .java files to have a simple Javadoc class comment with at least an @author tag identifying you, and preferably at least a paragraph on what the class is for.

  • Add the ASF license header comment to all new .java files (copy from existing files in the project)

  • Add yourself as an @author to the .java files that you modify substantially (more than cosmetic changes).

  • Add some Javadocs and, if you change the namespace, some XSD doc elements.

  • A few unit tests would help a lot as well — someone has to do it.

  • If no-one else is using your branch, please rebase it against the current master (or other target branch in the main project).

  • When writing a commit message please follow these conventions, if you are fixing an existing issue please add Fixes gh-XXXX at the end of the commit message (where XXXX is the issue number).

spring-cloud-contract's People

Contributors

anatoliy-balakirev avatar artemptushkin avatar axelhodler avatar bertzzie avatar boothen avatar dependabot-preview[bot] avatar dependabot[bot] avatar dominick1993 avatar dsyer avatar eddumelendez avatar javiersvg avatar jkubrynski avatar johannesdorn avatar marcingrzejszczak avatar mariuszs avatar mzielinski avatar neptoon avatar olgamaciaszek avatar onobc avatar ryanjbaxter avatar shanman190 avatar snyk-bot avatar spencergibb avatar spring-builds avatar spring-operator avatar stessy avatar szpak avatar tkopczynski avatar tysewyn avatar zhmaeff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-cloud-contract's Issues

Change default layout of stubs jar files

I think the current layout is too flat, since once a jar is unpacked or inserted on a classpath there is no way to tell the origin of the contracts and mappings. My proposal is /META-INF/[mappings,contracts]/<groupId>/<artifactId>/<version>/* instead of /[mappings,contracts]/*. Note that WireMock already knows natively how to register stubs from a directory containing /mappings/** (that's why we want that at the top of the path).

P.S. I know we don't add stubs to any classpath in the stub runner, but it's a jar file in a Maven repo, so it's easy to do, and could be used to run Wiremock "manually" without the stub runner.

Use Spring CLI to run stubs locally

For the case where the consumer wants to prototype the API it would be good for them to immediately install and run stubs from the contracts.

E.g. installing

spring cloud contract install /Users/path/to/contracts/ 'groupid.a.b.c' 'artifactid.d.e.f' '1.0.0.BUILD-SNAPSHOT'

E.g. running

spring cloud contract run /Users/path/to/contracts/ 'groupid.a.b.c' 'artifactid.d.e.f' '1.0.0.BUILD-SNAPSHOT'

Response DSL does not seem to support plain text on server side

From @making on May 4, 2016 6:44

I'd like to test plain text response but it does not support regex, optional, execute and so on.

For example,

io.codearte.accurest.dsl.GroovyDsl.make {
    request {
        method 'GET'
        urlPath '/'
    }
    response {
        status 200
        body(value(
                client('123'),
                server(regex('[0-9]+'))
        ))
        headers {
            header('Content-Type': 'text/plain;charset=ISO-8859-1')
        }
    }
}

generates

    @Test
    public void validate_shouldSayHello() throws Exception {
        // given:
            MockMvcRequestSpecification request = given();

        // when:
            ResponseOptions response = given().spec(request)
                    .get("/");

        // then:
            assertThat(response.statusCode()).isEqualTo(200);
            assertThat(response.header("Content-Type")).isEqualTo("text/plain;charset=ISO-8859-1");
        // and:
            Object responseBody = (response.getBody().asString());
            assertThat(responseBody).isEqualTo("[0-9]+"); // .matches(...) is expected 😩 
    }

Of course, JSON response works well

io.codearte.accurest.dsl.GroovyDsl.make {
    request {
        method 'GET'
        urlPath '/'
    }
    response {
        status 200
        body(id : value(
                client('123'),
                server(regex('[0-9]+'))
        ))
        headers {
            header('Content-Type': 'application/json;charset=UTF-8')
        }
    }
}

generates

    @Test
    public void validate_shouldSayHello() throws Exception {
        // given:
            MockMvcRequestSpecification request = given();

        // when:
            ResponseOptions response = given().spec(request)
                    .get("/");

        // then:
            assertThat(response.statusCode()).isEqualTo(200);
            assertThat(response.header("Content-Type")).isEqualTo("application/json;charset=UTF-8");
        // and:
            DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
            assertThatJson(parsedJson).field("id").matches("[0-9]+"); // 😀
    }

Copied from original issue: Codearte/accurest#263

Add starters

Some common combinations of dependencies can be supported via starters, in the usual Spring Boot way. In particular the wiremock and stub runner combos. See #39.

Update the docs and blog

Feedback from @fitzoh:

So you’re introduced to those blocks, then you scroll down a page or two, then they’re referenced again
It says they’re injected, so the first thing I do is look for a variable containing them which has been injected
So I scroll back and forth a couple times (across a lot of real estate), then realize that it’s value is included in the strings
But you need to look closely to see what maps to what
As there’s no example in the block that says “This thing is from the consumer block referenced earlier"
It could use some annotated lines to more clearly specify that “this thing is a result of that thing"
Here’s an example of what I have in mind from some internal pact documentation I wrote

https://files.gitter.im/spring-cloud/spring-cloud-contract/Screen-Shot-2016-07-25-at-1.23.57-PM.png

Add automated support for consumer contracts

Consumers could publish their expectations (contracts to a repo). If a consumer (let's call him barClient) wants a server (groupid : a.b.c, artifactid: fooServer) to behave in a certain manner he could push the contract to some Git repository (e.g. under the folder /a/b/c/fooServer/barClient-expectations) or publish the jar (e.g. a.b.c:barClient:fooServer-expectations-stubs).

Then the server side could provide the URL of the repo or switch to JAR based approach to download the contracts / find the proper folder (e.g. groupId/artifactId) and generate the tests for those expectations. Only after the tests pass can the server publish its stubs. Also if your tests fail you will know ultimately which consumer you break.

cc @olivergierke

No support for reqex on whole server's response body

From @mchmielarz on February 24, 2016 20:42

It would be quite useful to have possibility to do regular expression on whole response body returning for server side. Here is my case:

io.codearte.accurest.dsl.GroovyDsl.make {
    request {
        method('POST')
        url(PATH)
        headers {
            header("Content-Type": FORM_CONTENT_TYPE)
        }
        body(
                """field=${value(client("something"), server("else"))}"""
        )
    }
    response {
        status 400
        body (value(client("Processing failed with 400 status."), server(regex(".*400.*"))))
    }
}

I want to return 400 in a body of the client stub. And that's ok actually. On the other hand for server tests I'm able to generate such status by sending malformed request. In this case body will contain some standard HTML with 400 added somewhere in between. Regex in such case will free me from pasting whole HTML in stub definition.

Copied from original issue: Codearte/accurest#199

Regex don't work for ints in String JSON

We're doing the hacks to convert regex from GString into a placeholder and then we try to convert them back as JSONs. Everything works fine if we have string values with regex. The problem occurs when using ints and creating stubs.

Example

org.springframework.cloud.contract.spec.Contract.make {
        request {
          method 'POST'
          url '/check'
          body("""
          {
          "name":"${value(consumer(regex('[a-zA-Z]+')))}",
          "age": ${value(consumer(regex('[3-9][0-9]|2[2-9]')))}
        }
        """
          )
        }
        response {
          status 200
          body( """{
              "status": "OK"
            }"""
          )
          headers {
            header 'Content-Type', 'application/json'
          }
        }
      }

gets temporarily converted to:

          {
          "name":"REGEXP>>[a-zA-Z]+<<",
          "age": REGEXP>>[3-9][0-9]|2[2-9]<<
        }

This part can't be parsed as JSON.

Things to look at:

Improve support for arrays in body

From @mzielinski on April 10, 2016 11:1

Assume that we have below response from server

{
   "exp": 2459982033,
   "user_name": "admin",
   "authorities": [
       "ROLE_ADMIN"
   ],
   "client_id": "ui",
   "scope": [
       "read",
       "write"
   ]
}

I would like to check wheather scope array is not empty. I do not care about specific values. Currently I am not able to do it. For sure we should improve support for arrays in body, maybe this task will be a good place to think about it.

Copied from original issue: Codearte/accurest#217

Incorrect array size check generated

From @hator on July 5, 2016 15:14

For input:

response {
    status 200
    body( content: [
        value(
            id: 'article_accurest::1',
            tags: ['tag1', 'tag2', 'tag3']
        ), value (
            id: 'article_accurest::2',
            tags: ['tag1', 'tag2', 'tag3']
        )
])}

Generated:

DocumentContext parsedJson = JsonPath.parse(response.body.asString())
assertThatJson(parsedJson).array("content").array("tags").hasSize(3)

The problem is that using Json path <$.content[*].tags[*]> all elements of all tags arrays are counted giving total of 6 instead of 3. This of course causes tests to fail.

Copied from original issue: Codearte/accurest#293

Don't use autoconfig for stub runner etc.

I think it will lead to problems at some point if we use regular autoconfig to install features in tests (they might leak into the app at runtime in an IDE for instance). It's better to use a custom annotation or something (e.g. see @ImportAutoConfiguration etc. in Spring Boot 1.4).

Handling of optional parameters from request body when generating wiremock stubs

From @cbuleandra on March 21, 2015 21:32

It is not currently possible to use the Groovy DSL for creating stub definitions with request bodies that accept optional parameters. It would be nice if something like this could be defined using the Groovy DSL:

${$(client(~/('loanNumber': '[0-9]+')?/), server('"loanNumber": 321'))}

This should then result in the following stub definition:

"bodyPatterns": [
    { "matches": "\\{(\"loanNumber\":\"[0-9]+\")?\\}" }
]

I guess nothing should have to change on the acceptance tests generation part.

What do you think? If you're ok with this idea, I could start working on a pull request in the following days.

Copied from original issue: Codearte/accurest#42

execute doesn't work in URL

From @jakubnabrdalik on July 5, 2016 13:21

In my contract I do "get" on a resource, but I have no hard-coded id. I need to have a generated id (object created before test and saved to mongo) so I can run tests concurrently without interference. During runtime the id is available in the base class, but I cannot hardcode it in the contract Groovy. So in other words, I need to execute a method, in URL part, like this:

org.springframework.cloud.contract.spec.Contract.make {
    request {
        method 'GET'
        url $(client(regex('/api/articles/.*')), server(execute('getArticleId()')))
        headers {
            header 'Content-Type': 'application/json;charset=UTF-8'
        }
    }

But instead of creating a call to getArticleId() this snippet generates a toString on ExecutionProperty, like so:

def validate_shouldFetchArticle() throws Exception {
        given:
            def request = given()
                    .header('Content-Type', 'application/json;charset=UTF-8')

        when:
            def response = given().spec(request)
            .get("org.springframework.cloud.contract.spec.internal.ExecutionProperty@26d445e9")

Can you make it possible to use "execute" in url as well? The documentation doesn't give that example but also suggests it should be possible.

Copied from original issue: Codearte/accurest#292

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.