使用POST方法发送服务的json有效负载并使用HttpTarget创建PACT提供程序测试

时间:2019-01-12 15:15:01

标签: consumer pact-jvm

我有一个带有POST方法的springboot服务,并接受json负载。我能够为此服务创建协议文件,但是我无法通过实际服务验证此协议文件,因为我正在使用的HttpTarget方法没有发送json负载的方法。请告知。

package se.ff.bsc;
import au.com.dius.pact.provider.junit.PactRunner;
import au.com.dius.pact.provider.junit.Provider;
import au.com.dius.pact.provider.junit.State;
import au.com.dius.pact.provider.junit.loader.PactFolder;
import au.com.dius.pact.provider.junit.target.HttpTarget;
import au.com.dius.pact.provider.junit.target.Target;
import au.com.dius.pact.provider.junit.target.TestTarget;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.runner.RunWith;

import java.util.Map;

@RunWith(PactRunner.class) // Say JUnit to run tests with custom Runner
@Provider("UserServicePOST") // Set up name of tested provider
@PactFolder("../pacts") // Point where to find pacts

public class MobileWsContactTestPOST {


    @State("user wants to create a new user with firstName as Hidayath") // Method will be run before testing interactions that require "with-data" state
    public void hammerSmith() {
        System.out.println("user wants to create a new user with firstName as Hidayath" );
    }


    @TestTarget // Annotation denotes Target that will be used for tests
    public final Target target = new HttpTarget("http","localhost",8081,""); // Out-of-the-box implementation of Target (for more information take a look at Test Target section)
    //public final String target1= new MobileWsClientPOST().postUserDetails();


}

0 个答案:

没有答案