spring-cloud-contract icon indicating copy to clipboard operation
spring-cloud-contract copied to clipboard

Spring project with Cloud Contract and PACT not auto-generating the Provider test class

Open rodrigow opened this issue 3 years ago • 6 comments

Describe the bug Started a new Spring Gradle project from spring: Gradle/Java17/Spring Web/Spring cloud contract provider. Created Pact Broker server locally. Added a "Consumer" test. Configured Contracts to have PACT Broker server. Running ./gradlew contractTest downloads the JSON but no auto-generated classes in the $build folder.

Using the ./gradlew contractTest -d (for debug logs) I can see that there are some messages from the ContractFileScanner:

2022-05-04T12:19:22.263-0300 [DEBUG] [org.gradle.api.Task] 12:19:22.235 [main] DEBUG org.springframework.cloud.contract.verifier.file.ContractFileScanner - File [$file] wasn't ignored but no converter was applicable. The file is a directory [${file.isDirectory()}]
12:19:22.236 [main] DEBUG org.springframework.cloud.contract.verifier.file.ContractFileScanner - File [$file] wasn't ignored but no converter was applicable. The file is a directory [${file.isDirectory()}]
12:19:22.237 [main] DEBUG org.springframework.cloud.contract.verifier.file.ContractFileScanner - File [$file] wasn't ignored but no converter was applicable. The file is a directory [${file.isDirectory()}]
12:19:22.237 [main] DEBUG org.springframework.cloud.contract.verifier.file.ContractFileScanner - File [$file] wasn't ignored but no converter was applicable. The file is a directory [${file.isDirectory()}]
12:19:22.237 [main] DEBUG org.springframework.cloud.contract.verifier.file.ContractFileScanner - File [$file] wasn't ignored but no converter was applicable. The file is a directory [${file.isDirectory()}]
12:19:22.237 [main] DEBUG org.springframework.cloud.contract.verifier.file.ContractFileScanner - File [$file] wasn't ignored but no converter was applicable. The file is a directory [${file.isDirectory()}]
12:19:22.237 [main] DEBUG org.springframework.cloud.contract.verifier.file.ContractFileScanner - File [$file] wasn't ignored but no converter was applicable. The file is a directory [${file.isDirectory()}]
12:19:22.237 [main] DEBUG org.springframework.cloud.contract.verifier.file.ContractFileScanner - File [$file] wasn't ignored but no converter was applicable. The file is a directory [${file.isDirectory()}]
12:19:22.237 [main] DEBUG org.springframework.cloud.contract.verifier.file.ContractFileScanner - File [$file] wasn't ignored but no converter was applicable. The file is a directory [${file.isDirectory()}]
12:19:22.237 [main] DEBUG org.springframework.cloud.contract.verifier.TestGenerator - Found the following contracts []

Properties: .TestGeneratorApplication {"testFramework":"JUNIT5","testMode":"MOCKMVC","basePackageForTests":null,"baseClassForTests":"com.rodrigow.demo.contract.BaseTestClass","nameSuffixForTests":null,"ruleClassForTests":null,"excludedFiles":[],"includedFiles":[],"ignoredFiles":[],"imports":[],"staticImports":[],"contractsDslDir":"/Users/rodrigow/code/demoSCCPact/build/stubs/META-INF/com.rodrigow.demo.sccwithpact/greeting-service/1.0/contracts","generatedTestSourcesDir":"/Users/rodrigow/code/demoSCCPact/build/generated-test-sources/contractTest/java","generatedTestResourcesDir":"/Users/rodrigow/code/demoSCCPact/build/generated-test-resources/contractTest","stubsOutputDir":null,"stubsSuffix":"stubs","assertJsonSize":false,"includedContracts":".*","includedRootFolderAntPattern":"**/","packageWithBaseClasses":null,"baseClassMappings":{},"excludeBuildFolders":false,"failOnInProgress":true}

Sample Instructions to create the Pact Server locally alongside with the code are hosted in https://github.com/rodrigow/spring-cloud-contract-with-pact-sample

rodrigow avatar May 04 '22 17:05 rodrigow

Have you added Pact converter to the classpath? Check this part of the docs https://docs.spring.io/spring-cloud-contract/docs/current/reference/html/howto.html#how-to-pact-producer

marcingrzejszczak avatar May 25 '22 09:05 marcingrzejszczak

I believe you are referring to the spring-cloud-contract-pact, right? It is there. Please let me know if you are not referring to this dependency.

In time: The code snippet of 7.4. Pact for Producers seems to be missing. I've found it in another "location", 7.4. Pact for Producers

rodrigow avatar May 25 '22 13:05 rodrigow

Yeah that was the part I was referring to. I need to see a reproducer. Without it it's hard to even wonder what could possibly be wrong.

marcingrzejszczak avatar May 25 '22 13:05 marcingrzejszczak

I'm not sure what a "reproducer" would be. Were you able to download the project and run the ./gradlew contractTest ?

rodrigow avatar May 25 '22 13:05 rodrigow

Wow, I need to change my glasses - I haven't noticed that you provided a sample. :facepalm:

marcingrzejszczak avatar May 25 '22 14:05 marcingrzejszczak

No need to apologize, maybe I should have been more clear about the sample...

rodrigow avatar May 25 '22 14:05 rodrigow

Closing due to age of the question. If you would like us to look at this issue, please comment and we will look at re-opening the issue.

spring-cloud-issues avatar Nov 25 '22 09:11 spring-cloud-issues