Pact JVM还需要安装scala和scala相关的依赖项吗?

时间:2017-09-27 16:21:55

标签: pact

执行PACT JVM测试用例时,出现以下错误。实际上在此错误之前,还有另一个scala错误,在添加一个scala依赖项之后,该问题已解决,但是来了这个。

    java.lang.NoClassDefFoundError: scala/Product$class
    at au.com.dius.pact.model.RequestMatching.<init>(RequestMatching.scala:7)
    at au.com.dius.pact.model.RequestMatching$.apply(RequestMatching.scala:7)
    at au.com.dius.pact.model.RequestMatching.apply(RequestMatching.scala)
    at au.com.dius.pact.consumer.BaseMockServer.<init>(MockHttpServer.kt:61)
    at au.com.dius.pact.consumer.MockHttpServer.<init>(MockHttpServer.kt:202)
    at au.com.dius.pact.consumer.MockHttpServerKt.mockServer(MockHttpServer.kt:34)
    at au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest(ConsumerPactRunner.kt:12)
    at au.com.dius.pact.consumer.ConsumerPactTestMk2.testPact(ConsumerPactTestMk2.java:26)

这是我的代码: `public class ContractTest扩展了ConsumerPactTestMk2 {

    @Rule
    public PactProviderRuleMk2 mockProvider = new PactProviderRuleMk2("test_provider", "localhost", 5055, this);

    @Override
    @Pact(provider="test_provider", consumer="test_consumer")
    protected RequestResponsePact createPact(PactDslWithProvider builder) {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("testreqheader", "testreqheadervalue");

        JSONObject updateJsonObj = new JSONObject();
        JSONObject updateVersion = new JSONObject();
        updateVersion.put("version", "1.4");
        updateJsonObj.put("update", updateVersion);
        return builder.given("test state 1") // NOTE: Using provider states are optional, you can leave it out
                .uponReceiving("ExampleJavaConsumerPactTest test interaction")
                    .path("/hostService/hosts/1")
                    .method("PUT")
                    .body(updateJsonObj)
                .willRespondWith()
                    .status(200)
                    .body(updateJsonObj)
                .given("test state 2") // NOTE: Using provider states are optional, you can leave it out
                .uponReceiving("ExampleJavaConsumerPactTest second test interaction")
                    .method("GET")
                    .path("/hostService/hosts/1")
                    .body("")
                .willRespondWith()
                    .status(200)
                    .body("")
                .toPact();
    }

    @Override
    protected String providerName() {
        return "test_provider";
    }

    @Override
    protected String consumerName() {
        return "test_consumer";
    }

    @Override
    protected void runTest(MockServer mockServer) throws IOException {
        HttpClient httpClient = HttpClients.createDefault();        
        HttpPut putReq = new HttpPut(mockServer.getUrl());
        HttpGet getReq = new HttpGet(mockServer.getUrl());

        HttpResponse response = httpClient.execute(getReq);     
        Assert.assertEquals(response.getStatusLine().getStatusCode(), 200);

        response = httpClient.execute(putReq);
        Assert.assertEquals(getVersion(response.getEntity().toString()), "1.3"); 
    }

`

1 个答案:

答案 0 :(得分:1)

它看起来像版本3.5.5 are a little broken的依赖项。目前,您有两种选择:

  1. 通过降级到版本3.5.4

  2. 来解决它
  3. 明确包含缺少的依赖项。对我来说,这是: