private ConsumerProviderPair executePactFragment(EventContext<Test> testEventContext, String currentProvider, PactVerification pactVerification) throws Throwable { final Object testInstance = testEventContext.getEvent().getTestInstance(); final TestClass testClass = testEventContext.getEvent().getTestClass(); Optional<PactMethod> possiblePactMethod = findPactMethod(currentProvider, testClass, pactVerification); if (!possiblePactMethod.isPresent()) { throw new UnsupportedOperationException("Could not find method with @Pact for the provider " + currentProvider); } PactMethod pactMethod = possiblePactMethod.get(); Pact pact = pactMethod.getPact(); PactDslWithProvider dslBuilder = ConsumerPactBuilder.consumer(pact.consumer()).hasPactWith(currentProvider); PactFragment pactFragment; try { pactFragment = (PactFragment) pactMethod.getMethod().invoke(testInstance, dslBuilder); } catch (Exception e) { throw new RuntimeException("Failed to invoke pact method", e); } VerificationResult result = runPactTest(testEventContext, pactFragment); validateResult(result, pactVerification); return new ConsumerProviderPair(pact.consumer(), currentProvider); }
private ConsumerProviderPair executePactFragment(EventContext<Test> testEventContext, String currentProvider, PactVerification pactVerification) throws Throwable { final Object testInstance = testEventContext.getEvent().getTestInstance(); final TestClass testClass = testEventContext.getEvent().getTestClass(); Optional<PactMethod> possiblePactMethod = findPactMethod(currentProvider, testClass, pactVerification); if (!possiblePactMethod.isPresent()) { throw new UnsupportedOperationException( "Could not find method with @Pact for the provider " + currentProvider); } PactMethod pactMethod = possiblePactMethod.get(); Pact pact = pactMethod.getPact(); PactDslWithProvider dslBuilder = ConsumerPactBuilder.consumer(pact.consumer()).hasPactWith(currentProvider); PactFragment pactFragment; try { pactFragment = (PactFragment) pactMethod.getMethod().invoke(testInstance, dslBuilder); } catch (Exception e) { throw new RuntimeException("Failed to invoke pact method", e); } VerificationResult result = runPactTest(testEventContext, pactFragment); validateResult(result, pactVerification); return new ConsumerProviderPair(pact.consumer(), currentProvider); }
private void executePacts(EventContext<Test> test, final Pacts pacts, final Field interactionField, final Field consumerField) { final TestClass testClass = test.getEvent().getTestClass(); final Object testInstance = test.getEvent().getTestInstance(); for (Pact pact : pacts.getPacts()) { RequestResponsePact requestResponsePact = (RequestResponsePact) pact; // Inject current consumer if (consumerField != null) { setField(testInstance, consumerField, pact.getConsumer()); } for (final RequestResponseInteraction interaction : requestResponsePact.getInteractions()) { executeStateChanges(interaction, testClass, testInstance); Target target = targetInstance.get(); if (target instanceof ArquillianTestClassAwareTarget) { ArquillianTestClassAwareTarget arquillianTestClassAwareTarget = (ArquillianTestClassAwareTarget) target; arquillianTestClassAwareTarget.setTestClass(testClass, testInstance); } if (target instanceof PactProviderExecutionAwareTarget) { PactProviderExecutionAwareTarget pactProviderExecutionAwareTarget = (PactProviderExecutionAwareTarget) target; pactProviderExecutionAwareTarget.setConsumer(pact.getConsumer()); pactProviderExecutionAwareTarget.setRequestResponseInteraction(interaction); } // Inject current interaction to test if (interactionField != null) { setField(testInstance, interactionField, interaction); } // run the test test.proceed(); } } }
private void executePacts(EventContext<Test> test, final Pacts pacts, final Field interactionField, final Field consumerField) { final TestClass testClass = test.getEvent().getTestClass(); final Object testInstance = test.getEvent().getTestInstance();