JSON файл pact не генерируется после прохождения теста (pact jvm и весенняя загрузка) - PullRequest
0 голосов
/ 05 апреля 2020

Я пытаюсь сгенерировать файл Pact. Тест проходит успешно. Тем не менее, действительно понимаю, почему файл договора Pact не генерируется. Можете ли вы помочь? Ниже приведен мой тестовый код:

public class DeliveryConsumerTest {

@Rule
public PactProviderRuleMk2 mockProvider = new PactProviderRuleMk2("delivery_provider", "localhost",8083, this);
private RestTemplate restTemplate = new RestTemplate();

@Pact(consumer = "delivery_consumer")
public RequestResponsePact createPact(PactDslWithProvider builder) {
    Map<String, String> headers = new HashMap<>();
    headers.put("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE);


    PactDslJsonBody bodyResponse = new PactDslJsonBody()
            .integerType("id", 1)
            .stringType("deliveryNumber", "PO473134")
            .stringType("orderNumber", "4513415")
            .integerType("supplierId", 0)
            .stringType("fulfillmentType", "FT")
            .stringType("healthState", "HEALTHY");

    return builder.given("get delivery list by id")
            .uponReceiving("a request to get delivery")
            .path("/producer/api/v1/delivery/1")
            .body(bodyResponse)
            .method("GET")
            .willRespondWith()
            .headers(headers)
            .status(200)
            .body(bodyResponse)
            .toPact();
}

@Test
@PactVerification("delivery-provider")
public void testGetDeliveryVerificationConsumer() {

    try {
        HttpResponse httpResponse = Request.Get(mockProvider.getConfig().url() + "/producer/api/v1/delivery/1").execute().returnResponse();
        String json = EntityUtils.toString(httpResponse.getEntity());
        System.out.println("json=" + json);
        JSONObject jsonObject = new JSONObject(json);
        String deliveryNumber = jsonObject.get("deliveryNumber").toString();
        System.out.println();
        assertEquals("PO473134", deliveryNumber);

        System.out.println(System.getProperty("pactDirectory"));


    } catch (Exception e) {
        e.printStackTrace();
    }


}

}

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd "> org.springframework.boot spring-boot-starter-parent 2.2.6.RELEASE 4.0.0 доставка-потребитель-потребитель-доставка-API

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <pact-jvm-consumer-junit_2.12.version>3.5.20</pact-jvm-consumer-junit_2.12.version>
    <java.version>1.8</java.version>
    <pact.version>3.5.24</pact.version>
</properties>


<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.module</groupId>
        <artifactId>jackson-module-kotlin</artifactId>
        <version>2.9.7</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>au.com.dius</groupId>
        <artifactId>pact-jvm-consumer-junit_2.12</artifactId>
        <version>${pact-jvm-consumer-junit_2.12.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.4.12</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
        <groupId>au.com.dius</groupId>
        <artifactId>pact-jvm-provider-maven_2.12</artifactId>
        <version>3.6.7</version>
        <configuration>
            <pactDirectory>${project.build.directory}/pacts</pactDirectory>
            <pactBrokerUrl>localhost:80</pactBrokerUrl>
        </configuration>
    </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18</version>
            <configuration>
                <systemPropertyVariables>
                    <pact.rootDir>${project.build.directory}/pacts</pact.rootDir>
                    <buildDirectory>${project.build.directory}</buildDirectory>
                </systemPropertyVariables>
            </configuration>
        </plugin>
    </plugins>
</build>

...