quarkiverse / quarkus-pact

Pact is a widely-recommended framework for consumer-driven contract testing. This Quarkus extension gives the best Pact integration with Quarkus.
https://pact.io/
Apache License 2.0
11 stars 6 forks source link

Only request/response interactions can be used with an HTTP test target #185

Closed l2c0r3 closed 4 months ago

l2c0r3 commented 4 months ago

Hello everyone

I have created a contract from the message consumer:

Now I would like to have it checked the produced messages.

For that I wrote following Test:

@QuarkusTest
@TestProfile(SignatureTestProfile.class)
@Provider("SignPdfProvider")
@Consumer("signPdfConsumer")
@PactFolder("pacts")
public class SignPdfJmsProviderContractTest {

    @Inject
    Messageproducer messageproducer;

    @PactVerifyProvider("a signPdfRequest Message")
    void testASignPdfRequestMessage(PactVerificationContext context) {
        context.verifyInteraction();
        messageproducer.produceMessage();
    }

    @TestTemplate
    @ExtendWith(PactVerificationInvocationContextProvider.class)
    void pactVerificationTestTemplate(PactVerificationContext context) {
        context.verifyInteraction();
    }
}

However, I get the following error message:

java.lang.UnsupportedOperationException: Only request/response interactions can be used with an HTTP test target at au.com.dius.pact.provider.junit5.HttpTestTarget.prepareRequest(TestTarget.kt:98) at au.com.dius.pact.provider.junit5.PactVerificationExtension.beforeTestExecution(PactVerificationExtension.kt:136) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeTestExecutionCallbacks$5(TestMethodTestDescriptor.java:191)

Dependencies:

Many thanks for your support

l2c0r3 commented 4 months ago

Found the solution. Unfortunately, it is not a Quarkus test (https://github.com/pact-foundation/pact-jvm/issues/1506)

@Provider("SignPdfProvider")
@Consumer("signPdfConsumer")
@PactFolder("pacts")
@ExtendWith(MockitoExtension.class)
public class SignPdfJmsProviderContractTest {
    @Mock
    ...
    @InjectMocks
    SignPdfService signPdfService;

    @BeforeEach
    void before(PactVerificationContext context) {
        context.setTarget(new MessageTestTarget());
    }

    @TestTemplate
    @ExtendWith(PactVerificationInvocationContextProvider.class)
    void pactVerificationTestTemplate(PactVerificationContext context) {
        context.verifyInteraction();
    }

    @PactVerifyProvider("a signPdfRequest Message")
    public String testASignPdfRequestMessage() {
         // return Body of JMS Message
    }
}