0

我无法创建 Pact 文件。面对 NoHttpResponseException : 127.0.0.1:56314 未能响应。我能够成功生成协议文件,但是在执行 Maven->clean 之后,我遇到了一系列问题。请让我知道可能是什么原因,我现在该如何解决?

我的 POM 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>Customer</groupId>
  <artifactId>Auth_Api_Consumer</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>Auth_Api_Consumer</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
        <dependency>
            <groupId>au.com.dius</groupId>
            <artifactId>pact-jvm-consumer-junit_2.11</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>fluent-hc</artifactId>
            <version>4.5.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.0</version>
        </dependency>


    </dependencies>
</project>

我的契约测试文件:

package Customer.Auth_Api_Consumer;

import java.io.IOException;

import org.apache.http.entity.ContentType;
import org.junit.Rule;
import org.junit.Test;
import Utilities.ApplicationConstants;
import au.com.dius.pact.consumer.Pact;
import au.com.dius.pact.consumer.PactProviderRuleMk2;
import au.com.dius.pact.consumer.PactVerification;
import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
import au.com.dius.pact.model.RequestResponsePact;
import junit.framework.Assert;

public class Authorisation_API_Test {
    @Rule
    public PactProviderRuleMk2 provider = new PactProviderRuleMk2(ApplicationConstants.Provider_EcCustomer, this);

    @Pact(provider = ApplicationConstants.Provider_EcCustomer, consumer = ApplicationConstants.Consumer_EcCart)
    public RequestResponsePact createFragment(PactDslWithProvider builder) {

        return builder.given("Provider State:Verify that the user Vijay exists")
                .uponReceiving("Verify Valid User Login").path("/hue-ec-customer/v1/customers/userlogin/verify")
                .method("POST")
                .body("{\"customerGroupId\": \"3ee05990-5022-11e7-a2ea-e7a96dab751e\", \"login\": \"vijay\", \"password\": \"testing\" }")
                .willRespondWith().status(200)
                .given("Provider State:Verify that the user Vijay exists")
                .uponReceiving("Verify Invalid User Login").path("/hue-ec-customer/v1/customers/userlogin/verify")
                .method("POST")
                .body("{\"customerGroupId\": \"3ee05990-5022-11e7-a2ea-e7a96dab751e\", \"login\": \"vijay\", \"password\": \"123456\" }")
                .willRespondWith().status(401).
                uponReceiving("Create User")
                .path("hue-ec-customer/v1/customers/userlogin/create").method("POST")
                .body("{\"customerGroupId\": \"3ee05990-5022-11e7-a2ea-e7a96dab751e\","
                        + " \"userId\": \"tehuser\", \"loginEmailAddress\":" + " \"teh.sm@mail.com\" "
                        + " \"loginPhoneNumber\": \"8934234\"" + " \"password\": \"defaultpassword\"}")
                .willRespondWith().status(201)
                .toPact();
    }

    @Test
    @PactVerification(ApplicationConstants.Provider_EcCustomer)
    public void runTest() throws IOException {
        System.out.println("Mock Server started at : " + provider.getUrl());
        System.out.println(new Client(provider.getUrl()).postBody("/hue-ec-customer/v1/customers/userlogin/verify",
                        "{\"customerGroupId\": \"3ee05990-5022-11e7-a2ea-e7a96dab751e\","
                                + " \"login\": \"vijay\", \"password\": \"testing\" }",
                        ContentType.APPLICATION_JSON)
                .getStatusLine().getStatusCode());
        Assert.assertEquals(200, new Client(provider.getUrl())
                .postBody("/hue-ec-customer/v1/customers/userlogin/verify",
                        "{\"customerGroupId\": \"3ee05990-5022-11e7-a2ea-e7a96dab751e\","
                                + " \"login\": \"vijay\", \"password\": \"testing\" }",
                        ContentType.APPLICATION_JSON)
                .getStatusLine().getStatusCode());
        Assert.assertEquals(new Client(provider.getUrl())
                .postBody("/hue-ec-customer/v1/customers/userlogin/verify",
                        "{\"customerGroupId\": \"3ee05990-5022-11e7-a2ea-e7a96dab751e\","
                                + " \"login\": \"vijay\", \"password\": \"123456\" }",
                        ContentType.APPLICATION_JSON)
                .getStatusLine().getStatusCode(), 401);

        Assert.assertEquals(
                new Client(provider.getUrl()).postBody("/hue-ec-customer/v1/customers/userlogin/create",
                        "{\"customerGroupId\": \"3ee05990-5022-11e7-a2ea-e7a96dab751e\","
                                + " \"userId\": \"tehuser\", \"loginEmailAddress\":" + " \"teh.sm@mail.com\" "
                                + " \"loginPhoneNumber\": \"8934234\"" + " \"password\": \"defaultpassword\"}",
                        ContentType.APPLICATION_JSON).getStatusLine().getStatusCode(),
                201);


    }
}
4

1 回答 1

0

我不得不将 Junit 版本降级到 4.9

于 2017-10-03T08:45:58.830 回答