Make PactVerification value not mandatory #58

Closed
lordofthejars opened this Issue Jan 4, 2017 · 0 comments

Projects

None yet

1 participant

@lordofthejars
Member
Issue Overview

When you want to write a consumer test method you need to specify that the method tests a consumer contract by using @PactVerification annotation and setting which provider you are verifying.

In case of using @Pact annotation at class level, this information is redundant (the value of the annotation) so it could be retrieved from there instead of forcing users to set it again.

Expected Behaviour
@RunWith(Arquillian.class)
@Pact(provider="test_provider", consumer="test_consumer")
public class ClientGatewayTest {

    @Deployment
    public static JavaArchive createDeployment() {
        return ShrinkWrap.create(JavaArchive.class).addClasses(ClientGateway.class);
    }

    public PactFragment createFragment(PactDslWithProvider builder) {

        Map<String, String> header = new HashMap<>();
        header.put("Content-Type", "application/json");

        Map<String, Object> stateParams = new HashMap<>();
        stateParams.put("name", "Alexandra");

        return builder
                .given("test state", stateParams)
                .uponReceiving("ConsumerTest test interaction")
                .path("/")
                .method("GET")
                .willRespondWith()
                .status(200)
                .headers(header)
                .body("{\"responsetest\": true, \"name\": \"harry\"}")
                .toFragment();
    }

    @EJB
    ClientGateway clientGateway;

    @Test
    @PactVerification
    public void should_return_message() throws IOException {
        assertThat(clientGateway.getMessage(), is("{\"responsetest\": true, \"name\": \"harry\"}"));
    }
}
Current Behaviour
@RunWith(Arquillian.class)
@Pact(provider="test_provider", consumer="test_consumer")
public class ClientGatewayTest {

    @Deployment
    public static JavaArchive createDeployment() {
        return ShrinkWrap.create(JavaArchive.class).addClasses(ClientGateway.class);
    }

    public PactFragment createFragment(PactDslWithProvider builder) {

        Map<String, String> header = new HashMap<>();
        header.put("Content-Type", "application/json");

        Map<String, Object> stateParams = new HashMap<>();
        stateParams.put("name", "Alexandra");

        return builder
                .given("test state", stateParams)
                .uponReceiving("ConsumerTest test interaction")
                .path("/")
                .method("GET")
                .willRespondWith()
                .status(200)
                .headers(header)
                .body("{\"responsetest\": true, \"name\": \"harry\"}")
                .toFragment();
    }

    @EJB
    ClientGateway clientGateway;

    @Test
    @PactVerification("test_provider")
    public void should_return_message() throws IOException {
        assertThat(clientGateway.getMessage(), is("{\"responsetest\": true, \"name\": \"harry\"}"));
    }
}
@lordofthejars lordofthejars self-assigned this Jan 4, 2017
@lordofthejars lordofthejars added this to the 1.0.0.Alpha5 milestone Jan 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment