Hi team!, can you please help me understand why I ...
# pact-jvm
r
Hi team!, can you please help me understand why I am getting this error, my builder is return V4Pact also ?
Copy code
java.lang.UnsupportedOperationException: Method createPact does not conform required method signature 'public au.com.dius.pact.core.model.V4Pact xxx(PactBuilder builder)'
 at au.com.dius.pact.consumer.junit.JUnitTestSupport.conformsToSignature(JUnitTestSupport.kt:35)
 at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.lookupPact(PactConsumerTestExt.kt:504)
 at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.setupPactForTest(PactConsumerTestExt.kt:270)
 at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.setupMockServerForProvider(PactConsumerTestExt.kt:248)
 at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.beforeTestExecution(PactConsumerTestExt.kt:223)
 at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
 at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
r
Does your method take a
PactBuilder
as the only parameter and return a
V4Pact
?
m
Can you please show us the code Rishav?
r
Yes rhol my method createpact takes Pact/builder and return V4Pact
here is my code Matt
Copy code
@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(providerName = "rules-api-bi", pactVersion = PactSpecVersion.V4)
class RulesApiConsumerTest {

    @Pact(consumer = "fanout-logs-bi")
    public V4Pact createPact(PactBuilder builder) {
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");

        // Create a sample Rule object
        PactDslJsonArray rule = ((PactDslJsonArray) ((PactDslJsonArray) new PactDslJsonBody()
                .booleanType("active", true)
                .stringType("createdBy")
                .datetime("createdAt")
                .stringType("updatedBy")
                .datetime("updatedAt")
                .stringType("deletedBy")
                .datetime("deletedAt")
                .uuid("ruleId")
                .stringType("name")
                .stringType("description")
                .booleanType("isCustomerRule", true)
                .stringType("customerId")
                .minArrayLike("dataTypes", 1, new PactDslJsonRootValue(), 1)
                .booleanType("shouldMatchAllRecords", true)
                .object("ruleCondition")
                    .stringType("additionalProp1")
                    .stringType("additionalProp2")
                    .stringType("additionalProp3")
                .closeObject())
                .stringType("connectionType")
                .stringType("outputTopic")
                .object("configuration")
                    .stringType("additionalProp1")
                    .stringType("additionalProp2")
                    .stringType("additionalProp3")
                .closeObject()
                .object("targetConfiguration")
                    .stringType("additionalProp1")
                    .stringType("additionalProp2")
                    .stringType("additionalProp3")
                .closeObject())
                .uuid("ruleDestinationId")
                .uuid("destinationAuthenticationId")
                .booleanType(true);

        return builder
            .usingLegacyDsl()
            .given("Rules exist")
            .uponReceiving("A request for rules with includeInactive=true")
                .path("/v2/rules")
                .method("GET")
                .query("includeInactive=false")
            .willRespondWith()
                .status(200)
                .headers(headers)
                .body(rule)
            .toPact(V4Pact.class);
    }

    @Test
    @PactTestFor(pactMethod = "createPact")
    void testRulesEndpoint(MockServer mockServer) {
        String baseUrl = mockServer.getUrl();
        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<Rule[]> response = restTemplate.getForEntity(baseUrl + "/v2/rules", Rule[].class);
        // Assert
        assertEquals(200, response.getStatusCode().value());   
    }
}
I also get this error
Copy code
java.lang.AssertionError: The following methods annotated with @Pact were not executed during the test: RulesApiConsumerTest.createPact
If these are currently a work in progress, add a @Disabled annotation to the method

        at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.afterAll(PactConsumerTestExt.kt:720)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Hey guys I think I fixed the issue, now the setup is working, but getting different error
I mark this ✅
Hey team!, still facing some issue any clue why getting this error ?