Package au.com.dius.pact.consumer

Source Code of au.com.dius.pact.consumer.ConsumerPactTest

package au.com.dius.pact.consumer;

import au.com.dius.pact.model.PactFragment;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

public abstract class ConsumerPactTest {
    public static PactVerification.VerificationResult pactVerified = PactVerification.PactVerified$.MODULE$;

    protected abstract PactFragment createFragment(ConsumerPactBuilder.PactDslWithProvider builder);
    protected abstract String providerName();
    protected abstract String consumerName();

    protected abstract void runTest(String endpoint);

    @Test
    public void testPact() {
        PactFragment fragment = createFragment(ConsumerPactBuilder.consumer(consumerName()).hasPactWith(providerName()));

        Integer port = (Integer) MockProviderConfig.randomPort().get();
        final MockProviderConfig config = new MockProviderConfig(port, "localhost");

        PactVerification.VerificationResult result = fragment.runConsumer(config,
                new Runnable() {
                    public void run() {
                        try {
                            runTest(config.url());
                        } catch(Exception e) {
                            fail("error thrown"+e);
                        }
                    }
                });
        assertEquals(pactVerified, result);
    }
}
TOP

Related Classes of au.com.dius.pact.consumer.ConsumerPactTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.