Ich muss einen Maven-basierten Spring Cloud Contract 2.0.0.RELEASE-Abhängigkeit in ein Gradle-basiertes Projekt konvertieren. Hier ist pom.xml.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud-contract.version>2.0.0.RELEASE</spring-cloud-contract.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>${spring-cloud-contract.version}</version>
<extensions>true</extensions>
<configuration>
<packageWithBaseClasses>com.globallogic.springfluxdemo.cdc</packageWithBaseClasses>
<testMode>EXPLICIT</testMode>
</configuration>
</plugin>
</plugins>
</build>
Aber mit Gradle Init habe ich das Maven-Projekt in Gradle One konvertiert. Aber es funktioniert nicht gut. Später habe ich das Vertrags-Plugin in build.gradle hinzugefügt. Hier ist build.gradle.
apply plugin: 'io.spring.dependency-management'
apply plugin: 'spring-cloud-contract'
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Edgware.SR4'
}
}
contracts {
testMode = "EXPLICIT"
baseClassForTests = 'com.startwithjava.springwebfluxcontract.cdc'
}
}
Im Vertrag groovy dsl
import org.springframework.cloud.contract.spec.Contract
Contract.make {
description "Get Person Object"
request {
method GET()
url value("/mono")
headers {
contentType(applicationJson())
header('''Accept''', '''application/json''')
}
}
response {
status 200
bodyMatchers{
jsonPath('$.id', byType())
jsonPath('$.name', byType())
}
headers { contentType(applicationJson()) }
body (''' {
"id": 1,
"name": "Raj"
}''')
}
}
Aber angesichts des Problems während des Gradle-Builds heißt es, dass der Status 401 anstelle von 200 zurückgegeben wird.
Es gab einige Fehlkonfigurationen für baseClassForTests unter Vertrag. Ich habe das Paket anstelle von classname platziert.
contracts{
testMode = 'EXPLICIT'
baseClassForTests = 'com.startwithjava.springwebfluxcontract.cdc.PersonRestBase'
}
Dieser Artikel stammt aus dem Internet. Bitte geben Sie beim Nachdruck die Quelle an.
Bei Verstößen wenden Sie sich bitte [email protected] Löschen.
Lass mich ein paar Worte sagen