/** * Creates a mock provider by the given name * @param provider Provider name to mock * @param host Host to bind to. Defaults to localhost * @param port Port to bind to. Defaults to a random port. * @param pactVersion Pact specification version * @param target Target test to apply this rule to. */ public PactProviderRule(String provider, String host, Integer port, PactSpecVersion pactVersion, Object target) { this.provider = provider; this.target = target; if (host == null && port == null) { config = MockProviderConfig.createDefault(pactVersion); } else { config = MockProviderConfig.httpConfig(host, port, pactVersion); } }
public PactRule(String host, int port, Object target) { config = MockProviderConfig.httpConfig(host, port, PactSpecVersion.V3); this.target = target; }
public PactRule(String host, Object target) { config = MockProviderConfig.createDefault(host, PactSpecVersion.V3); this.target = target; }
@Test public void testPact() throws Throwable { PactFragment fragment = createFragment(ConsumerPactBuilder.consumer(consumerName()).hasPactWith(providerName())); final MockProviderConfig config = MockProviderConfig.createDefault(getSpecificationVersion()); VerificationResult result = fragment.runConsumer(config, config1 -> runTest(config1.url())); if (!result.equals(PACT_VERIFIED)) { if (result instanceof PactError) { throw ((PactError)result).error(); } if (result instanceof UserCodeFailed) { throw ((UserCodeFailed<RuntimeException>)result).error(); } if (result instanceof PactMismatch) { PactMismatch mismatch = (PactMismatch) result; throw new PactMismatchException(mismatch); } } }
public PactRule(String host, int port, Object target) { config = MockProviderConfig.httpConfig(host, port, PactSpecVersion.V3); this.target = target; }
public PactRule(Object target) { config = MockProviderConfig.createDefault(PactSpecVersion.V3); this.target = target; }
@Test public void testPact() throws Throwable { PactFragment fragment = createFragment(ConsumerPactBuilder.consumer(consumerName()).hasPactWith(providerName())); final MockProviderConfig config = MockProviderConfig.createDefault(getSpecificationVersion()); VerificationResult result = fragment.runConsumer(config, config1 -> runTest(config1.url())); if (!result.equals(PACT_VERIFIED)) { if (result instanceof PactError) { throw ((PactError)result).error(); } if (result instanceof UserCodeFailed) { throw ((UserCodeFailed<RuntimeException>)result).error(); } if (result instanceof PactMismatch) { PactMismatch mismatch = (PactMismatch) result; throw new PactMismatchException(mismatch); } } }
/** * Creates a mock provider by the given name * @param provider Provider name to mock * @param host Host to bind to. Defaults to localhost * @param port Port to bind to. Defaults to a random port. * @param pactVersion Pact specification version * @param target Target test to apply this rule to. */ public PactProviderRule(String provider, String host, Integer port, PactSpecVersion pactVersion, Object target) { this.provider = provider; this.target = target; if (host == null && port == null) { config = MockProviderConfig.createDefault(pactVersion); } else { config = MockProviderConfig.httpConfig(host, port, pactVersion); } }
public BaseProviderRule(Object target, String provider, String hostInterface, Integer port, PactSpecVersion pactVersion) { this.target = target; this.provider = provider; config = MockProviderConfig.httpConfig(StringUtils.isEmpty(hostInterface) ? MockProviderConfig.LOCALHOST : hostInterface, port == null ? 0 : port, pactVersion); }
public PactRule(String host, Object target) { config = MockProviderConfig.createDefault(host, PactSpecVersion.V3); this.target = target; }
public void create(@Observes BeforeClass beforeClass, PactConsumerConfiguration pactConsumerConfiguration) { if (pactConsumerConfiguration.isHttps()) { if (pactConsumerConfiguration.getPort() < 1) { final MockProviderConfig value = MockHttpsProviderConfig .createDefault(pactConsumerConfiguration.getHost(), pactConsumerConfiguration.getPactSpecVersion()); configInstanceProducer.set(value); } else { final MockProviderConfig value = MockHttpsProviderConfig .httpsConfig(pactConsumerConfiguration.getHost(), pactConsumerConfiguration.getPort(), pactConsumerConfiguration.getPactSpecVersion()); configInstanceProducer.set(value); } } else { if (pactConsumerConfiguration.getPort() < 1) { final MockProviderConfig value = MockProviderConfig.createDefault(pactConsumerConfiguration.getHost(), pactConsumerConfiguration.getPactSpecVersion()); configInstanceProducer.set(value); } else { final MockProviderConfig value = MockProviderConfig.httpConfig(pactConsumerConfiguration.getHost(), pactConsumerConfiguration.getPort(), pactConsumerConfiguration.getPactSpecVersion()); configInstanceProducer.set(value); } } } }
public BaseProviderRule(Object target, String provider, String hostInterface, Integer port, PactSpecVersion pactVersion) { this.target = target; this.provider = provider; config = MockProviderConfig.httpConfig(StringUtils.isEmpty(hostInterface) ? MockProviderConfig.LOCALHOST : hostInterface, port == null ? 0 : port, pactVersion); }
public PactRule(Object target) { config = MockProviderConfig.createDefault(PactSpecVersion.V3); this.target = target; }
public void create(@Observes BeforeClass beforeClass, PactConsumerConfiguration pactConsumerConfiguration) { if (pactConsumerConfiguration.isHttps()) { if (pactConsumerConfiguration.getPort() < 1) { final MockProviderConfig value = MockHttpsProviderConfig .createDefault(pactConsumerConfiguration.getHost(), pactConsumerConfiguration.getPactSpecVersion()); configInstanceProducer.set(value); } else { final MockProviderConfig value = MockHttpsProviderConfig .httpsConfig(pactConsumerConfiguration.getHost(), pactConsumerConfiguration.getPort(), pactConsumerConfiguration.getPactSpecVersion()); configInstanceProducer.set(value); } } else { if (pactConsumerConfiguration.getPort() < 1) { final MockProviderConfig value = MockProviderConfig.createDefault(pactConsumerConfiguration.getHost(), pactConsumerConfiguration.getPactSpecVersion()); configInstanceProducer.set(value); } else { final MockProviderConfig value = MockProviderConfig.httpConfig(pactConsumerConfiguration.getHost(), pactConsumerConfiguration.getPort(), pactConsumerConfiguration.getPactSpecVersion()); configInstanceProducer.set(value); } } }
@Test public void testPact() throws Throwable { RequestResponsePact pact = createPact(ConsumerPactBuilder.consumer(consumerName()).hasPactWith(providerName())); final MockProviderConfig config = MockProviderConfig.createDefault(getSpecificationVersion()); PactVerificationResult result = runConsumerTest(pact, config, this::runTest); if (!result.equals(PactVerificationResult.Ok.INSTANCE)) { if (result instanceof PactVerificationResult.Error) { PactVerificationResult.Error error = (PactVerificationResult.Error) result; if (error.getMockServerState() != PactVerificationResult.Ok.INSTANCE) { throw new AssertionError("Pact Test function failed with an exception, possibly due to " + error.getMockServerState(), ((PactVerificationResult.Error) result).getError()); } else { throw new AssertionError("Pact Test function failed with an exception: " + error.getError().getMessage(), error.getError()); } } else { throw new PactMismatchesException(result); } } }
@Test public void testPact() throws Throwable { RequestResponsePact pact = createPact(ConsumerPactBuilder.consumer(consumerName()).hasPactWith(providerName())); final MockProviderConfig config = MockProviderConfig.createDefault(getSpecificationVersion()); PactVerificationResult result = runConsumerTest(pact, config, this::runTest); if (!result.equals(PactVerificationResult.Ok.INSTANCE)) { if (result instanceof PactVerificationResult.Error) { PactVerificationResult.Error error = (PactVerificationResult.Error) result; if (error.getMockServerState() != PactVerificationResult.Ok.INSTANCE) { throw new AssertionError("Pact Test function failed with an exception, possibly due to " + error.getMockServerState(), ((PactVerificationResult.Error) result).getError()); } else { throw new AssertionError("Pact Test function failed with an exception: " + error.getError().getMessage(), error.getError()); } } else { throw new PactMismatchesException(result); } } }