Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 26 14:26
    vgropp closed #1717
  • Sep 26 14:26
    vgropp commented #1717
  • Sep 24 07:26
    marcingrzejszczak unlabeled #1717
  • Sep 24 07:26
    marcingrzejszczak labeled #1717
  • Sep 24 07:25
    marcingrzejszczak commented #1717
  • Sep 24 07:13
    spring-cloud-issues labeled #1717
  • Sep 24 07:12
    vgropp opened #1717
  • Sep 21 16:41

    spring-builds on 3.0.x

    Update SNAPSHOT to 3.0.4 Going back to snapshots Bumping versions to 3.0.5-SNAPS… (compare)

  • Sep 21 16:07

    spring-builds on v3.0.4

    Update SNAPSHOT to 3.0.4 (compare)

  • Sep 20 08:10

    marcingrzejszczak on main

    Fix handling of ClientDslProper… Merge remote-tracking branch 'o… (compare)

  • Sep 20 08:09

    marcingrzejszczak on 3.0.x

    Fix handling of ClientDslProper… (compare)

  • Sep 20 08:09
    marcingrzejszczak closed #1716
  • Sep 20 08:09
    marcingrzejszczak milestoned #1716
  • Sep 20 08:09
    marcingrzejszczak labeled #1716
  • Sep 20 08:09
    marcingrzejszczak unlabeled #1716
  • Sep 20 08:04
    neptoon edited #1716
  • Sep 20 07:24
    spring-cloud-issues labeled #1716
  • Sep 20 07:23
    neptoon opened #1716
  • Sep 16 21:00
    marcingrzejszczak commented #815
  • Sep 16 20:53
    tn185070 commented #815
Zane XiaoYe
@Zane-XY
The problem is the hardcoded value may fail the validation. And block the rest of the test execution.
Marcin Grzejszczak
@marcingrzejszczak
Ok, I'm explaining it the last time - you can hardcode the token in such a way that the validation will pass. If that's for some reason not acceptable for you then the answer is that OOB we don't support generation of things on the stubs side. You can however register your own WireMock extension https://docs.spring.io/spring-cloud-contract/docs/current/reference/html/advanced.html#customization-wiremock that will alter the response in whatever way you want.
Zane XiaoYe
@Zane-XY
Ok thanks! Marcin!
Marcin Grzejszczak
@marcingrzejszczak
np
Zane XiaoYe
@Zane-XY

I’m testing the Kafka Message Verifier.
My Kafka record type is ProducerRecord<byte[], org.apache.avro.generic.GenericRecord> record
The generated verification test has the below line,

ContractVerifierMessage response = contractVerifierMessaging.receive(“test-topic",
                    contract(this, “test-topic-contract.yml"));

when I debug to this line I found the reponse payload attribute is a String "org.apache.avro.generic.GenericRecord@54db0281”.
But what I was expecting is a org.apache.avro.generic.GenericRecord.
I have configured the correct key, value deserializers. It seems it has call the toString() method of GenericRecord.

Zane XiaoYe
@Zane-XY
I solved the above problem by providing a new customized deserializer.
3 replies
Daniel Wilkowski
@Danon

@marcingrzejszczak Hello, Marcin, cześć! :)

I'm trying to detect compatibility breaks between my contracts. Basically, I have a contract with fields, standard stuff. Now, I edit one field, from string to integer. I adjust my producer and consumer of course, so the tests still pass, but I changed the contract. I'd like to detect it somehow. Is there a way to do it?

Or maybe if I take two files A.yaml and B.yaml, is there a way to compare them contract-wise? Obviously, if I change the order of the fields in the declaration, that's not a breaking change, but removing a field is.

How would you do it?

1 reply
Zane XiaoYe
@Zane-XY
@marcingrzejszczak If I only made some changes to the contract, how do I quickly re-generate the stubs or tests?
I know there’s a maven task, but it seems I have to mvn clean install -DskipTests each time, otherwise, it doesn’t overwrite the previously generated tests.
Zane XiaoYe
@Zane-XY
Seems <incrementalContractTests>false</incrementalContractTests> is what I need
Marcin Grzejszczak
@marcingrzejszczak
yup
Zane XiaoYe
@Zane-XY

@marcingrzejszczak
If I run each test case individualy, it can pass.
but if I run them using maven together, only 1 test case can succeed.
I get

Caused by: java.io.IOException: Failed to bind to /0.0.0.0:8089
Caused by: java.net.BindException: Address already in use

I use a fixed port in the subs like

stubrunner.ids=xxx:xxx-api-integration:0.0.1-SNAPSHOT:stubs:8089

because in my application I also need to configure the JaxRS client using a pre-known port.
my questions

  • why each test case doesn’t close the port and cause the conflicts?
  • is there any way to reference the random port created by @AutoConfigureStubRunner from application.properties?
6 replies
Zane XiaoYe
@Zane-XY
I think I had found some of the answers, something like http://localhost:${stubrunner.runningstubs.some-service.port}
Zane XiaoYe
@Zane-XY
can producer generate the verification test from a remote repo?
I want to have a dedicated contract repo.
both consumer and producer can read & write to this repo. But the producer verfication test I want to be generated inside producer’s code repo only.
Zane XiaoYe
@Zane-XY
if I use <contractsRepositoryUrl>git://git://git@github.com:spring-cloud-samples/spring-cloud-contract-nodejs-contracts-git.git</contractsRepositoryUrl>
how can I set the ssh key used to access the git repo?
Marcin Grzejszczak
@marcingrzejszczak
you can't set the key - you can set up an agent and we can reuse that agent
Zane XiaoYe
@Zane-XY
what do you mean by agent?
Marcin Grzejszczak
@marcingrzejszczak
# to run the agent
eval `ssh-agent`
# to store the pass in the agent
ssh-add ~/.ssh/id_rsa
Zane XiaoYe
@Zane-XY
does this work for Jenkins?
Marcin Grzejszczak
@marcingrzejszczak
you'd have to call those methods and ensure that you have the keys set up on a worker
Zane XiaoYe
@Zane-XY
yeah, but I guess that doesn’t work, because the Jenkins jobs are running on some random pods, I can’t reply on the environment settings.
Marcin Grzejszczak
@marcingrzejszczak
you could inject the key via env var and echo it to a file
or a secret
Zane XiaoYe
@Zane-XY
worth a try
Zane XiaoYe
@Zane-XY

when you trigger a message stub by label, what happens behind scenes?
does the stubrunner only invoke the outputMessage {} section in the contract or the input {…} is also executed?

this.trigger.trigger("triggerMessage");

Contract.make {
    label("triggerMessage")
    input {
        triggeredBy("triggerMessage()")
    }
    outputMessage {
        sentTo("topic1")
        body([
                foo: "example"
        ])
        headers {
            header('kafka_messageKey', 'key-example')
        }
    }
}
I’m also curious how the message stub is working, since I didn’t find any generated code inside the stubs, the stubs are only the contract definitions. how does SCC sent the message to the topic defined inside the contract?
Marcin Grzejszczak
@marcingrzejszczak
on the stub side it's doing only output message
unless there's input triggered by message - if that's the case you need to manually send a message to that input and we will send the message to the output
Pavel Ivanov
@a1ternative6556_twitter

Hi everyone,
I have to implement java DSL contract tests. Unfortunately, I can not find how to check minOccurence\maxOccurence for some fields.

byType(): The value taken from the producer’s response in the provided JSON path needs to be of the same type as the type defined in the body of the response in the contract. byType can take a closure, in which you can set minOccurrence and maxOccurrence.

How it applicable for java DSL? Can please anyone help with it?

Marcin Grzejszczak
@marcingrzejszczak
can you show us some code an show what the problem is?
Pavel Ivanov
@a1ternative6556_twitter

can you show us some code an show what the problem is?

I see how to check minOccurence for some json field in yaml DSL contract. I.e.:

  • path: $.body.attrLvl1.attrLvl2
    type: by_type
    minOccurrence: 1

I can implement check for type in java DSL like:
r.bodyMatchers(m -> {
m.jsonPath("$.body.attrLvl1.attrLvl2", m.byType());
})

How for java DSL contract I can realize check for minOccurence() as similar for yaml DSL contract?

Marcin Grzejszczak
@marcingrzejszczak
3 replies
Zane XiaoYe
@Zane-XY
I have a shared contract repo. From the consumer side, the consumer firstly clones the contracts to the local, and points the reporoot to the cloned contract repo.
which url should I use?
git://file:///shared-contract.git or stubs://file:///shared-contract
I never succeed using git://file:///, what’s the difference?
17 replies
Dominik Meister
@neptoon

Hi. Not sure whether I stumbled upon a bug in the conversion from Groovy DSL to Wiremock stubs, or whether I'm just doing it wrong :) In my use case I need to have a fixed value for a cookie in the server side tests, but for client side mocks I want to allow any alphanumeric value:

        cookies {
            cookie "Foo": $(client(anyAlphaNumeric()), server("bar"))
        }

This results in the following Wiremock JSON:

    "cookies" : {
      "Foo" : {
        "equalTo" : "ClientDslProperty{\nclientValue=[a-zA-Z0-9]+, \n\tserverValue=krMcWesAHFw28vG6RfyD}"
      }
    },

which obviously is not correct :) I would have expected:

   "cookies" : {
      "Foo" : {
        "matches" : "[a-zA-Z0-9]+"
      }
    },

It works if I don't use different values for server and client side:

        cookies {
            cookie "Foo": $(anyAlphaNumeric())
        }
Marcin Grzejszczak
@marcingrzejszczak
most likely a bug
Dominik Meister
@neptoon
OK thx, I'll open a bug report then :)
Marcin Grzejszczak
@marcingrzejszczak
maybe even better - a pr ? :D
Dominik Meister
@neptoon
yeah, I'm already having a look ;) Any hints where to start searching for it?
Dominik Meister
@neptoon
:thumbsup:
Marcin Grzejszczak
@marcingrzejszczak
or wait
this is wrong in the stub?
Dominik Meister
@neptoon
I see. I'll give it a try then :)
Marcin Grzejszczak
@marcingrzejszczak
protected ContentPattern<?> convertToValuePattern(Object o) {
                Object object = MapConverter.transformToClientValues(o);
        if (object instanceof Pattern || object instanceof RegexProperty) {
            return WireMock.matching(new RegexProperty(object).pattern());
        }
        else if (object instanceof OptionalProperty) {
            return WireMock.matching(((OptionalProperty) object).optionalPattern());
        }
        else if (object instanceof MatchingStrategy) {
            MatchingStrategy value = (MatchingStrategy) object;
            switch (value.getType()) {
            case NOT_MATCHING:
                return WireMock.notMatching(value.getClientValue().toString());
            case ABSENT:
                return WireMock.absent();
            case EQUAL_TO:
                return WireMock.equalTo(clientBody(value.getClientValue(), contentType).toString());
            case CONTAINS:
                return WireMock.containing(clientBody(value.getClientValue(), contentType).toString());
            case MATCHING:
                return WireMock.matching(clientBody(value.getClientValue(), contentType).toString());
            case EQUAL_TO_JSON:
                return WireMock.equalToJson(clientBody(value.getClientValue(), contentType).toString());
            case EQUAL_TO_XML:
                return WireMock.equalToXml(clientBody(value.getClientValue(), contentType).toString());
            case BINARY_EQUAL_TO:
                return WireMock.binaryEqualTo((byte[]) clientBody(value.getClientValue(), contentType));
            default:
                throw new UnsupportedOperationException("Unknown matching strategy " + value.getType());
            }
        }
this should fix it. Could you fix this for 3.0.x branch and write a test for that please?
7 replies
Dominik Meister
@neptoon
:thumbsup: