Where communities thrive


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

    marcingrzejszczak on master

    Rewrite spring-cloud-contract-v… (compare)

  • 07:12
    marcingrzejszczak closed #1534
  • 07:12
    marcingrzejszczak milestoned #1534
  • 07:12
    marcingrzejszczak unlabeled #1534
  • 07:12
    marcingrzejszczak labeled #1534
  • 06:54
    marcingrzejszczak milestoned #1636
  • 06:54
    marcingrzejszczak labeled #1636
  • 06:54
    marcingrzejszczak unlabeled #1636
  • 06:54
    marcingrzejszczak unlabeled #1637
  • 06:54
    marcingrzejszczak labeled #1637
  • 06:53

    marcingrzejszczak on master

    Remove <at>Internal annotation … (compare)

  • 06:53
    marcingrzejszczak closed #1637
  • 06:53
    marcingrzejszczak closed #1636
  • 06:53
    marcingrzejszczak commented #1637
  • Apr 12 23:35
    shanman190 edited #1637
  • Apr 12 23:34
    shanman190 edited #1637
  • Apr 12 23:32
    spring-cloud-issues labeled #1637
  • Apr 12 23:31
    shanman190 edited #1637
  • Apr 12 23:30
    shanman190 opened #1637
  • Apr 12 14:38
    ryanjbaxter review_requested #1538
Miguel Fernández
@miguefl

Hi guys !! I have a weird error with Hoxton.SR9, spring boot 2.3.4.RELEASE and spring cloud contracts. I use gradle 6.4.1 and intelliJ. I have the dependency testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner'. With Hoxton.SR9 the contract library dependecies are 2.2.5. The problem is that with Hoxton.SR9 (contract 2.2.5) gradle downloads the dependencies but imports in test classes are broken. It's weird because I can see the classes that fails to import in the 2.2.5 library jar. If I switch to Hoxton.SR8 (contract 2.2.4) everything works as expected, imports works.

Has anyone ever experienced that kind of problem?

Thanks !!

Marcin Grzejszczak
@marcingrzejszczak
maybe you've downloaded a corrupt jar
try to manually delete it and redownload it
Miguel Fernández
@miguefl
Yes, maybe is something like that. It's weird because I've the same problems in the pipeline but... maybe the jar is corrupt in our nexus repository. I think we have a proxy repository. Thanks for the tip.
Marcin Grzejszczak
@marcingrzejszczak
:+1:
Miguel A. Alonso
@migalons
Hi All. I'm stuck trying to develop a contract test for a kafka producer. The error I have is this: java.lang.IllegalStateException: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'Events_Resources_publish' is expected to be of type 'org.springframework.messaging.PollableChannel' but was actually of type 'org.springframework.cloud.stream.messaging.DirectWithAttributesChannel'
Miguel A. Alonso
@migalons
My Base class:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {com.amdocs.msnext.boot.Boot.class})
@AutoConfigureMessageVerifier
@EmbeddedKafka(partitions = 1,
        topics = {"Events_Resources"},
        brokerPropertiesLocation = "classpath:/broker.properties")
@ActiveProfiles(profiles = "test")
public class AsyncBase {

    @Autowired
    INotifyEventCreated notifyCreated;
.....

    public void trigger() {
        notifyCreated.notify(eventDTO);
    }
}
My contract:
package contracts.printer.async

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

Contract.make {
    input {
        triggeredBy("trigger()")
    }

    outputMessage {
        sentTo("Events_Resources")
        body([
                foo: "example"
        ])
        headers {
            header('kafka_messageKey', 'key-example')
        }
    }
}
Srinivas
@Sriniva63328880_twitter
Hi all
Mick Hunter
@Mickelback00

I'm toying with SCC for non-JVM apps - I'm attempting to run the npm test from this repo: https://github.com/spring-cloud-samples/spring-cloud-contract-nodejs, but I get the following error:

Sc Contract Version [3.0.2-SNAPSHOT]
Application URL [http://host.docker.internal:9876]
Artifactory URL [http://host.docker.internal:8081/artifactory/libs-release-local]
Project Version [0.0.1.RELEASE]
Setting project name to [bookstore]
Running the build

ERROR: JAVA_HOME is set to an invalid directory: /root/.sdkman/candidates/java/current/

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Originally I assumed this was an issue with my local install of SDKMAN, but learning the Spring supported docker images also use this, I found the directory being called out in the error above matches the Dockerfile's line 19: https://github.com/spring-cloud/spring-cloud-contract/blob/bbb4db35838f62c8e6df7479e64a33bd875f765d/docker/spring-cloud-contract-stub-runner-docker/Dockerfile#L19

Thoughts?

George Theofanous
@ael1930

hey team.
quick question. I have an http response which contains a map. The key of the map could be any string and the value of the map could be any object. Is there a way to define that in the java dsl?
Tried something like this:

HashMap<String, Object> answerSet = new HashMap<>();
answerSet.put("question", response.anyAlphaNumeric().getServerValue());

which generates a random string value, but how do I do that for the key. And is there a better way to do so?

Marcin Grzejszczak
@marcingrzejszczak
nope you can't randomize a key
George Theofanous
@ael1930
thanks!
Marcin Grzejszczak
@marcingrzejszczak
np
DaftDuck
@daftduck22
Hi, we've run into a problem which I think is fixed by spring-cloud/spring-cloud-contract#1411 Do you know when it might be generally available?
Marcin Grzejszczak
@marcingrzejszczak
Should be tomorrow
2 replies
DaftDuck
@daftduck22
Thanks very much!
Marcin Grzejszczak
@marcingrzejszczak
np
GPradnya
@GPradnya
Hello, I am trying to use spring cloud contract examples. I am getting below error for the consumer project while running mvnw clean install. Can anyone help?
[ERROR] should_give_me_a_beer_when_im_old_enough Time elapsed: 0 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'streamBridgeUtils': Unsatisfied dependency expressed through field 'bindingService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bindingService' defined in class path resource [org/springframework/cloud/stream/config/BindingServiceConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.stream.binding.BindingService]: Factory method 'bindingService' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/validation/beanvalidation/CustomValidatorBean
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bindingService' defined in class path resource [org/springframework/cloud/stream/config/BindingServiceConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.stream.binding.BindingService]: Factory method 'bindingService' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/validation/beanvalidation/CustomValidatorBean
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.stream.binding.BindingService]: Factory method 'bindingService' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/validation/beanvalidation/CustomValidatorBean
Caused by: java.lang.NoClassDefFoundError: org/springframework/validation/beanvalidation/CustomValidatorBean
Marcin Grzejszczak
@marcingrzejszczak
most likely you have a mismatch in versions
GPradnya
@GPradnya
I am trying to build the projects by using java 8. I have changed the pom files for common, beer-contract, producer and consumer projects. I could build the producer successfuly
Marcin Grzejszczak
@marcingrzejszczak
maybe you have a corrupt jar
we don't have such issues when we're building the project
GPradnya
@GPradnya
Ok, Thank you
GPradnya
@GPradnya
I cleaned my maven repository and did clean install once again. The above problem is resolved now. Thanks for your help. Now, I am facing below error , could you help?
[ERROR] should_reject_a_beer_when_im_too_young Time elapsed: 0.429 s <<< ERROR!
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:0/check": connect: Address is invalid on local machine, or port is not valid on remote machine; nested exception is java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine
at com.example.BeerControllerTest.should_reject_a_beer_when_im_too_young(BeerControllerTest.java:66)
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:0/check": connect: Address is invalid on local machine, or port is not valid on remote machine; nested exception is java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine
at com.example.BeerControllerTest.should_reject_a_beer_when_im_too_young(BeerControllerTest.java:66)
Caused by: java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine
at com.example.BeerControllerTest.should_reject_a_beer_when_im_too_young(BeerControllerTest.java:66)
unkis
@unkis
Hello, i'm trying to use Spring Cloud Contract for events and I've built a small spring boot example project to play a little bit around. but I've an issue, my test is always green, but I've extra built-in errors. I've already created a question on StackOverflow. https://stackoverflow.com/questions/66669421/cdc-with-spring-cloud-contract-tests-always-green-despite-extra-built-in-errors . Can anybody help me and explain what do I wrong? thx.
unkis
@unkis
@marcingrzejszczak could you please help me with my question?
Marcin Grzejszczak
@marcingrzejszczak
2.2.7.RELEASE you mean?
DaftDuck
@daftduck22
Sorry yeah that's what I mean
Marcin Grzejszczak
@marcingrzejszczak
Cause it's not released
mohanrao
@mohanrao
i am trying to use spring cloud contract to create a mock server . is there any example out there
?
mohanrao
@mohanrao
@marcingrzejszczak any thoughts.. ? is it wrong to think to spring cloud contract to create a mock server ?
1 reply
Thomas Olsson
@thol01
@marcingrzejszczak sorry for the late reply (from jan 28). I Did try the the "producer_kotlin_ftw" example from the "spring-cloud-contract-samples" with Kotlin 1.4.30 and I also fails on generateClientStubs TASK. Seems like Cloud Contract is bound to a specific version of Kotlin.
7 replies
GPradnya
@GPradnya

I am writing test case for consumer side. I am getting below exception while running the test. Any help ?

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchStubRunner' defined in class path resource [org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.contract.stubrunner.BatchStubRunner]: Factory method 'batchStubRunner' threw exception; nested exception is java.lang.ClassCastException: org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsJsonPathHelper cannot be cast to com.github.jknack.handlebars.Helper
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:127) [spring-boot-test-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) [spring-test-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) [spring-test-5.1.3.RELEASE.jar:5.1.3.RELEASE]

1 reply
Piotr Kulasek
@kulasekp
1 reply
sachin-deshpande1
@sachin-deshpande1

Hi All
anyone used Spring Cloud Contract kafka tests for avro messages ?

Have explored below repo but unable to find suitable example.

https://github.com/spring-cloud-samples/spring-cloud-contract-samples/blob/3.0.x/consumer_kafka_middleware/src/test/java/com/example/ApplicationTests.java

2 replies
deepakemani-maersk
@deepakemani-maersk
image.png

hi Team,
We are trying to integrate SCC for Spring Kafka (using avro) . We have used test containers to create kafka and schema registry. We can see that in the trigger method it is able to create kafka topic, send message to the topic but the generated ContractVerifiertest case is failing due to NPE (attached the screenshot). Appreciate any pointers to resolve this issue

Added the below annotations on the Base class
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = { TestConfig.class, Application.class }, properties = "debug=true")
@Testcontainers
@AutoConfigureMessageVerifier
@ActiveProfiles("test")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)

2 replies
Laudman
@Laudman

Hello, I am trying write contract in groovy for my service but I stuck on one field

private Map<String, Object> templateData;

any one know how to correct write something like that?

P.S. I also wonder if it would be possible to write something like this:

private Map<@NotBlank String, @NotNull Object> templateData;
Marcin Grzejszczak
@marcingrzejszczak
I don't understand the question - it's a map so just define a map
Laudman
@Laudman
Sorry DSL confused me jus enought [:]. There was no question :-D
Laudman
@Laudman

So regarding DSL maybe you know how to do array of objects e.g:

class Document {
private String nodeId;
private String docName;
}

private List<Document> documents;

I tried :

documents: body([
                        value(
                                nodeId: $(anyNonBlankString()),
                                docName: ""
                        )
                ]

but it return me document:null

Marcin Grzejszczak
@marcingrzejszczak
Key can't be dynamic
Laudman
@Laudman

One more question I hope last one :-D
I have multi module project, in the root build I have generated-test-sources. All sub-modules have builds without this directory.
My issuee is that copyContracts task failed on submodule I got NullPointerException. I suppose it's related to this folder generated-test-sources but I am not sure.
Do you know how to skip copyContracts task for sub-modules builds? Or do you have idea what went wrong?

It is my contract configuration:

contracts {
    generatedTestJavaSourcesDir = project.file("${project.buildDir}/generated-test-sources/contracts")
    contractsDslDir = project.file("${project.rootDir}/src/test/resources/contracts")
    stubsOutputDir = project.file("${project.buildDir}/stubs")
    failOnNoContracts = false
}
Marcin Grzejszczak
@marcingrzejszczak
you can do -x copyContracts I guess? or copyContracts.enabled=false in the submodules
Laudman
@Laudman
Thank you now all is working :-)
Marcin Grzejszczak
@marcingrzejszczak
:+1:
Shannon Pamperl
@shanman190
Another possibility here is to apply the org.springframework.cloud.contract plugin only to modules where you expect contracts to exist. Then it wouldn't execute in any of the submodules as its likely unneeded there. This would mean not configuring the plugin within a subprojects, allprojects, or configure(List) blocks. Then in that case you wouldn't need to exlcude or disable the copyContracts task.