2017-07-06 31 views
0

我无法创建Pact文件。 面对NoHttpResponseException:127.0.0.1:56314未能回应。 我能够成功生成协议文件,但在我做了Maven-> clean之后,我面临着一系列问题。 请让我知道可能是什么原因,我现在如何解决它?由于NoHttpResponseException导致Pact文件创建失败:127.0。*。*。***未能回复

我的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\":" + " \"[email protected]\" " 
         + " \"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\":" + " \"[email protected]\" " 
           + " \"loginPhoneNumber\": \"8934234\"" + " \"password\": \"defaultpassword\"}", 
         ContentType.APPLICATION_JSON).getStatusLine().getStatusCode(), 
       201); 


    } 
} 
+0

能否请您显示异常跟踪,你是看见了什么?您试图将哪个目录输出到pact文件? –

+0

@J_A_X - 我可以通过更改Junit版本来解决此问题! – PaChSu

+0

您能否回答您自己的问题,并确切地解决问题?你更改哪个版本的Junit版本? –

回答

0

我不得不降级JUnit版本4.9

+0

哪个版本的Junit不工作? –

+0

4.11和5.1不起作用。 – PaChSu

+0

你介意在这里创建一个问题吗? https://github.com/DiUS/pact-jvm –

相关问题