我从pact和micronaut开始,我想运行一个pact文件。我发现的示例是用Spring Boot编写的,所以我想知道什么是micronaut项目的“翻译”。专门用于运行Pact文件
我在Micronaut中的Consumer类是:
public class HelloControllerTest {
@Rule
public PactProviderRuleMk2 provider = new PactProviderRuleMk2("StudentProvider", "localhost", 8112, this);
@Pact(consumer = "StudentClient")
public RequestResponsePact createPact(PactDslWithProvider builder) {
Map<String, String> headers = new HashMap();
headers.put("Content-Type", "application/json");
DslPart result = new PactDslJsonBody()
.stringType("id", "Student1")
.stringType("fistName","Ranga Karanam")
.stringType("lastName","Hiker, Programmer and Architect")
.asBody();
return builder
.given("There is a Student with ID Student1")
.uponReceiving("A Student with ID Student1 and firstName Ranga Karanam")
.path("/student/Student1")
.method("GET")
.willRespondWith()
.status(200)
.headers(headers)
.body(result).toPact();
}
@Test
@PactVerification()
public void doTest() {
System.out.println(provider.getPort());
HelloController helloController = new HelloController(provider.getPort());
helloController.getUser("Student1");
}
}
Spring引导示例,一个运行Pact文件的类
@RunWith(SpringRestPactRunner.class)
@Provider("user-service")
@PactFolder("pacts")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ContractTest {
@TestTarget
public final Target target = new SpringBootHttpTarget();
@State("User 1 exists")
public void user1Exists() {
// nothing to do, real service is used
}
}
这就是我在micronaut中创建的:
@ExtendWith(MicronautJunit5Extension.class)
@MicronautTest
@Provider("StudentProvider")
@PactFolder("pacts")
public class StudentContractTest {
@TestTarget
public final Target target = new HttpTarget(8111);
@State("There is a Student with ID Student1")
public void student1() {
System.out.println("There is a Student with ID Student1" );
}
}
“翻译”是否有意义? 我应该如何在micronaut中指定一个webEnvironmnent?