Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 04:00

    spring-buildmaster on gh-pages

    Sync docs from master to gh-pag… (compare)

  • 02:33

    spring-buildmaster on gh-pages

    Sync docs from 2.1.x to gh-pages (compare)

  • 01:40

    spring-buildmaster on gh-pages

    Sync docs from 1.2.x to gh-pages (compare)

  • 01:00

    spring-buildmaster on gh-pages

    Sync docs from master to gh-pag… (compare)

  • 00:27

    spring-buildmaster on gh-pages

    Sync docs from 2.0.x to gh-pages (compare)

  • Aug 20 22:00

    spring-buildmaster on gh-pages

    Sync docs from master to gh-pag… (compare)

  • Aug 20 14:31
    CircleCI fixed: spring-cloud build (#8786) in https://github.com/spring-cloud/spring-cloud-contract
    • Add test scenarios to JUnit5. Fixes gh-887. (#1177)
      (60809445ffe6f58be005c1c2c9e9fa22ca04a967 by GitHub)
  • Aug 20 14:11
    codecov[bot] commented #1177
  • Aug 20 14:09

    OlgaMaciaszek on 2.1.x

    Add test scenarios to JUnit5. F… (compare)

  • Aug 20 14:09
    OlgaMaciaszek closed #1177
  • Aug 20 14:08
    codecov[bot] commented #1177
  • Aug 20 14:08
    codecov[bot] commented #1177
  • Aug 20 14:08
    CircleCI success: spring-cloud build (#8785) in https://github.com/spring-cloud/spring-cloud-contract
    • Add test scenarios to JUnit5. Fixes gh-887.
      (01e7c5fcbc1166b291d70a1069f8d4ab07efef5d by Olga Maciaszek-Sharma)
  • Aug 20 13:58
    marcingrzejszczak milestoned #1177
  • Aug 20 13:29
    OlgaMaciaszek labeled #1177
  • Aug 20 13:29
    OlgaMaciaszek review_requested #1177
  • Aug 20 13:29
    OlgaMaciaszek opened #1177
  • Aug 20 13:28

    OlgaMaciaszek on feature-gh-887-add-test-scenarios-to-junit5

    Add test scenarios to JUnit5. F… (compare)

  • Aug 20 13:26

    OlgaMaciaszek on fix-gh-1091-handle-arrays-with-matchers-for-all-fields

    (compare)

  • Aug 20 11:56
    marcingrzejszczak labeled #1176
Marcin Grzejszczak
@marcingrzejszczak
there has already been a question about it
pascalwilbrink
@pascalwilbrink
Thanks :)
pascalwilbrink
@pascalwilbrink
which dependencies do i need for it?
i have these:
testCompile('org.springframework.cloud:spring-cloud-starter-contract-verifier')
testCompile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner"
testCompile("org.springframework.cloud:spring-cloud-contract-pact:${verifierVersion}")
Marcin Grzejszczak
@marcingrzejszczak
you don't need stub runner to run it, it's in the verifier dep. And yes, you need the pact one too
pascalwilbrink
@pascalwilbrink
ok, thanks
pascalwilbrink
@pascalwilbrink
@marcingrzejszczak , i'm trying to implement the Pact converter, but it says that the "ToFileContractsTransformer" could not be found. it should be in the verifier dependency right?
think i found it, i have the 2.0.1 dependency
pascalwilbrink
@pascalwilbrink

I got an exception when trying to convert the dsls:

UnsupportedOperationException("use the object(String name) form");

The BodyConverter.groovy throws this exception:

if (v instanceof Map) {
            if (!isRoot) {
                p = p.object()
            }
            processMap(v as Map, p as PactDslJsonBody, dslPropertyValueExtractor)
            if (!isRoot) {
                p = p.closeObject()
            }
        }

It occurs when i have a nested JSON object.
for example:

{
  "id": 1,
  "name": "John Doe",
  "address": {
      "id": 2,
      "city": "Amsterdam"
  }
}
Marcin Grzejszczak
@marcingrzejszczak
nadavg54
@nadavg54
Hello. I got this weird circular dependency in Spring boot. I have a fiegnClient which just extend the another service published api. In addition I got an applicationListener that listens on ContextRefreshEvent, and when this event happens it calls some class that calls another class that eventually calls feign client.
Because the fiegn client also depent on the application listener then I get the circular dependency
but why is feign dependent on the application listener?!!
nadavg54
@nadavg54
okie so the problem was solved by using @EventListener rather then ApplicationListener.. have no clue why..
Olga Maciaszek-Sharma
@OlgaMaciaszek
Hello @nadavg54 how is this related to Spring Cloud Contract?
Tom Donohue
@monodot
Hi! I'm trying to set up producer-side testing with a Pact broker, following the producer_pact example. But when I run mvn clean install it generates a class which depends on SpringCloudContractAssertions. The test class won't compile because it's Groovy. How can I set this up? I'm using Maven.. :)
Marcin Grzejszczak
@marcingrzejszczak
Old version of contract plugin and deps
Are you setting them manually?
Tom Donohue
@monodot
Yep - was setting the version manually. But looking into the release train BOMs now. Thanks @marcingrzejszczak
Marcin Grzejszczak
@marcingrzejszczak
Cool!
Den22
@Den22

@marcingrzejszczak hi!
Could you please help with error on generating producer tests.
Here is a code I have in a contracts with a class ShouldReturnMetadataObject.groovy:

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    description 'Should return metadata'
    request {
        method 'GET'
        urlPath('/metadata/object') {
            queryParameters {
                parameter "serviceName": $(consumer(nonBlank()), producer("testService"))
                parameter "id": $(consumer(nonBlank()), producer("testId"))
            }
        }
    }

    response {
        status 200
        headers {
            contentType applicationOctetStream()
        }
        body(fileAsBytes('sample.txt'))
    }
}

which was successfully generated in a stub:

{
  "id" : "3b26a60c-f160-4196-8638-c0bff2c13495",
  "request" : {
    "urlPath" : "/metadata/object",
    "method" : "GET",
    "queryParameters" : {
      "serviceName" : {
        "matches" : "^\\s*\\S[\\S\\s]*"
      },
      "id" : {
        "matches" : "^\\s*\\S[\\S\\s]*"
      }
    }
  },
  "response" : {
    "status" : 200,
    "base64Body" : "dGVzdCBjb250ZW50",
    "headers" : {
      "Content-Type" : "application/octet-stream"
    },
    "transformers" : [ "response-template" ]
  },
  "uuid" : "3b26a60c-f160-4196-8638-c0bff2c13495"
}

and in tests in contracts repo build :

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

        // when:
            ResponseOptions response = given().spec(request)
                    .queryParam("serviceName","testService")
                    .queryParam("id","testId")
                    .get("/metadata/object");

        // then:
            assertThat(response.statusCode()).isEqualTo(200);
            assertThat(response.header("Content-Type")).matches("application/octet-stream.*");
        // and:
            assertThat(response.getBody().asByteArray()).isEqualTo(fileToBytes(this, "shouldReturnMetadataObject_response_sample.txt"));
    }

but when I try to generate this tests sources on service side the error appeares:

groovy.lang.MissingMethodException: No signature of method: ShouldReturnMetadataObject.fileAsBytes() is applicable for argument types: (java.lang.String) values: [sample.txt]

the contract versions spring-cloud-contract-spec is 2.1.1.RELEASE
Thanks in advance!

Marcin Grzejszczak
@marcingrzejszczak
wrong versions of plugin and spec imo
which version of the plugin do you have?
What do you mean by but when I try to generate this tests sources on service side the error appeares: ?
Den22
@Den22

I mean that I do clean install on producer service side

[ERROR] Failed to execute goal org.springframework.cloud:spring-cloud-contract-maven-plugin:2.0.0.RELEASE:generateTests (generate-tests) on project myservice-metadata-service-contract-tests: Execution generate-tests of goal org.springframework.cloud:spring-cloud-contract-maven-plugin:2.0.0.RELEASE:generateTests failed: groovy.lang.MissingMethodException: No signature of method: ShouldReturnMetadataObject.fileAsBytes() is applicable for argument types: (java.lang.String) values: [sample.txt] -> [Help 1]

Do you mean this version: org.springframework.cloud:spring-cloud-contract-maven-plugin:2.0.0.RELEASE?

Marcin Grzejszczak
@marcingrzejszczak
yes. How can you use Spring Cloud Contract version in 2.1.1 but plugin in 2.0.0 ? Please use the same version in both
Den22
@Den22

Thanks a lot - now it works!
but I have another issue with tests now:
when I run mvn clean install on producer service I have an error:

java.lang.IllegalStateException: java.io.FileNotFoundException: shouldReturnMetadataObject_response_sample.txt
    at c.META_INF.com_myservice_contracts.metadata_service.34430_SNAPSHOT.contracts.src.main.resources.contracts.metadata_service.rest.ApiTest.validate_shouldReturnMetadataObject(ApiTest.java:73)

but after that in target/genereted-test-sources/contracts/../rest there is a ApiTest and a file with name shouldReturnMetadataObject_response_sample.txt
and when I run this test it is passed.
So it looks like when maven plugin tryes to run this test exactly after generating ApiTest file shouldReturnMetadataObject_response_sample.txt is not generated at that moment.
Is this a known issue or a bug?

Marcin Grzejszczak
@marcingrzejszczak
so which version did you pick?
Den22
@Den22
2.1.1
here you have an example of a working case of file as bytes
you can check that project to see if you're doing sth similar
the latest version is 2.1.2 AFAIR so you can try to upgrade
if you do things in the same way and it still doesn't work then it's a bug
I see that the package / folder looks scary so maybe that's the problem
c.META_INF.com_myservice_contracts.metadata_service.34430_SNAPSHOT.contracts.src.main.resources.contracts.metadata_service.rest.ApiTest
Den22
@Den22

The only difference with your code is in returned content type - it is applicationOctetStream

response {
        status 200
        headers {
            contentType applicationOctetStream()
        }
        body(fileAsBytes("sample.txt"))
    }

Used 2.1.2 and error is the same:

[INFO] Running c.META_INF.com_company_contracts.myservice_metadata_service.34430_SNAPSHOT.contracts.src.main.resources.contracts.myservice_metadata_service.rest.ApiTest
[ERROR] Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.433 s <<< FAILURE! - in c.META_INF.com_company_contracts.myservice_metadata_service.34430_SNAPSHOT.contracts.src.main.resources.contracts.myservice_metadata_service.rest.ApiTest
[ERROR] validate_shouldReturnMetadataObject(c.META_INF.com_company_contracts.myservice_metadata_service.34430_SNAPSHOT.contracts.src.main.resources.contracts.myservice_metadata_service.rest.ApiTest)  Time elapsed: 0.074 s  <<< ERROR!
java.lang.IllegalStateException: java.io.FileNotFoundException: shouldReturnMetadataObject_response_sample.txt
    at c.META_INF.com_company_contracts.myservice_metadata_service.34430_SNAPSHOT.contracts.src.main.resources.contracts.myservice_metadata_service.rest.ApiTest.validate_shouldReturnMetadataObject(ApiTest.java:73)
Caused by: java.io.FileNotFoundException: shouldReturnMetadataObject_response_sample.txt
    at c.META_INF.com_company_contracts.myservice_metadata_service.34430_SNAPSHOT.contracts.src.main.resources.contracts.myservice_metadata_service.rest.ApiTest.validate_shouldReturnMetadataObject(ApiTest.java:73)
Arthur Kazemi
@bidadh
@marcingrzejszczak Sorry I haven't had a chance to create the repository and it might take more time since I'm very busy but I'd like to share that with you. What else could we do ?
Marcin Grzejszczak
@marcingrzejszczak
You could try to debug it and check if actually the packages are the same as the folder structure
Marcin Grzejszczak
@marcingrzejszczak
This message was deleted
@/all once the snapshots following this PR (spring-cloud/spring-cloud-contract#1152) will be built. You'll be able to generate stubs at runtime on demand. That means that as consumers, if you have contracts, by adding a switch, you'll be able to generate and rub stubs even if the producer hasn't uploaded those. This can be useful when you know what you're doing and don't / can't wait for the producer team to finish their side of the implementation
Marcin Grzejszczak
@marcingrzejszczak
Sid
@siddharth-pandey

Hi all, I have recently started to use spring cloud contract and trying to have the contracts, stubs in a separate repository. As per the guide, if I try contractsDslDir = "${project.rootDir}/src/main/resources/contracts"I get the following exception: Cannot cast object '/Users/sid/Documents/Projects/sample-contracts/src/main/resources/contracts' with class 'org.codehaus.groovy.runtime.GStringImpl' to class 'java.io.File' contractsDslDir is of type File.

Am I missing anything? Because the external repo set up requires everything to be in main/resources/contract, the default location need to be changed.

Sid
@siddharth-pandey
I've just tried contractsDslDir = file("${project.rootDir}/src/main/resources/contracts") and it works. If this is the right usage then the doc needs to be updated here: https://cloud.spring.io/spring-cloud-contract/2.0.x/multi/multi__spring_cloud_contract_verifier_setup.html#gradle-project.
Marcin Grzejszczak
@marcingrzejszczak
Can you file the issue or send the pr to fix this please?
Sid
@siddharth-pandey
@marcingrzejszczak Hi, I've raised this as an issue spring-cloud/spring-cloud-contract#1164, I have asked a question about the resolution there, thanks :)
Sid
@siddharth-pandey
Also, do we have a working sample of producer, consumer projects getting contracts/stubs from external repository?
Sid
@siddharth-pandey
great thanks @marcingrzejszczak