Search in sources :

Example 1 with Provider

use of au.com.dius.pact.provider.junit.Provider in project pact-jvm by DiUS.

the class AmqpTarget method getProviderInfo.

protected ProviderInfo getProviderInfo() {
    Provider provider = testClass.getAnnotation(Provider.class);
    ProviderInfo providerInfo = new ProviderInfo(provider.value());
    providerInfo.setVerificationType(PactVerification.ANNOTATED_METHOD);
    providerInfo.setPackagesToScan(packagesToScan);
    PactBroker annotation = testClass.getAnnotation(PactBroker.class);
    PactFolder folder = testClass.getAnnotation(PactFolder.class);
    if (annotation != null && annotation.host() != null) {
        List list = providerInfo.hasPactsFromPactBroker(annotation.protocol() + "://" + annotation.host() + (annotation.port() != null ? ":" + annotation.port() : ""));
        providerInfo.setConsumers(list);
    } else if (folder != null && folder.value() != null) {
        try {
            PactFolderLoader folderLoader = new PactFolderLoader(folder);
            Map<Pact, File> pactFileMap = folderLoader.loadPactsWithFiles(providerInfo.getName());
            providerInfo.setConsumers(pactFileMap.entrySet().stream().map(e -> new ConsumerInfo(e.getKey().getConsumer().getName(), e.getValue())).collect(Collectors.toList()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return providerInfo;
}
Also used : PactBroker(au.com.dius.pact.provider.junit.loader.PactBroker) Pact(au.com.dius.pact.model.Pact) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) MethodClosure(org.codehaus.groovy.runtime.MethodClosure) URL(java.net.URL) PactVerification(au.com.dius.pact.provider.PactVerification) IOException(java.io.IOException) HashMap(java.util.HashMap) Interaction(au.com.dius.pact.model.Interaction) PactFolderLoader(au.com.dius.pact.provider.junit.loader.PactFolderLoader) Provider(au.com.dius.pact.provider.junit.Provider) Collectors(java.util.stream.Collectors) File(java.io.File) URLClassLoader(java.net.URLClassLoader) List(java.util.List) ProviderVerifier(au.com.dius.pact.provider.ProviderVerifier) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) Map(java.util.Map) PactFolder(au.com.dius.pact.provider.junit.loader.PactFolder) Collections(java.util.Collections) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) PactFolderLoader(au.com.dius.pact.provider.junit.loader.PactFolderLoader) PactBroker(au.com.dius.pact.provider.junit.loader.PactBroker) PactFolder(au.com.dius.pact.provider.junit.loader.PactFolder) List(java.util.List) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Provider(au.com.dius.pact.provider.junit.Provider)

Example 2 with Provider

use of au.com.dius.pact.provider.junit.Provider in project pact-jvm by DiUS.

the class HttpTarget method getProviderInfo.

protected ProviderInfo getProviderInfo() {
    Provider provider = testClass.getAnnotation(Provider.class);
    final ProviderInfo providerInfo = new ProviderInfo(provider.value());
    providerInfo.setPort(port);
    providerInfo.setHost(host);
    providerInfo.setProtocol(protocol);
    providerInfo.setPath(path);
    providerInfo.setInsecure(insecure);
    if (testClass != null) {
        final List<FrameworkMethod> methods = testClass.getAnnotatedMethods(TargetRequestFilter.class);
        if (!methods.isEmpty()) {
            providerInfo.setRequestFilter((Consumer<HttpRequest>) httpRequest -> methods.forEach(method -> {
                try {
                    method.invokeExplosively(testTarget, httpRequest);
                } catch (Throwable t) {
                    throw new AssertionError("Request filter method " + method.getName() + " failed with an exception", t);
                }
            }));
        }
    }
    return providerInfo;
}
Also used : HttpRequest(org.apache.http.HttpRequest) SystemPropertyResolver(au.com.dius.pact.provider.junit.sysprops.SystemPropertyResolver) FrameworkMethod(org.junit.runners.model.FrameworkMethod) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) ValueResolver(au.com.dius.pact.provider.junit.sysprops.ValueResolver) URL(java.net.URL) HashMap(java.util.HashMap) Interaction(au.com.dius.pact.model.Interaction) Provider(au.com.dius.pact.provider.junit.Provider) HttpRequest(org.apache.http.HttpRequest) Consumer(java.util.function.Consumer) List(java.util.List) ProviderVerifier(au.com.dius.pact.provider.ProviderVerifier) TestClass(org.junit.runners.model.TestClass) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) Map(java.util.Map) TargetRequestFilter(au.com.dius.pact.provider.junit.TargetRequestFilter) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Provider(au.com.dius.pact.provider.junit.Provider)

Example 3 with Provider

use of au.com.dius.pact.provider.junit.Provider in project pact-jvm by DiUS.

the class MockMvcTarget method getProviderInfo.

@Override
protected ProviderInfo getProviderInfo() {
    Provider provider = testClass.getAnnotation(Provider.class);
    final ProviderInfo providerInfo = new ProviderInfo(provider.value());
    if (testClass != null) {
        final List<FrameworkMethod> methods = testClass.getAnnotatedMethods(TargetRequestFilter.class);
        if (!methods.isEmpty()) {
            providerInfo.setRequestFilter((Consumer<HttpRequest>) httpRequest -> methods.forEach(method -> {
                try {
                    method.invokeExplosively(testTarget, httpRequest);
                } catch (Throwable t) {
                    throw new AssertionError("Request filter method " + method.getName() + " failed with an exception", t);
                }
            }));
        }
    }
    return providerInfo;
}
Also used : HttpRequest(org.apache.http.HttpRequest) java.util(java.util) FrameworkMethod(org.junit.runners.model.FrameworkMethod) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) MethodClosure(org.codehaus.groovy.runtime.MethodClosure) URL(java.net.URL) MvcProviderVerifier(au.com.dius.pact.provider.spring.MvcProviderVerifier) MockMvcBuilders.standaloneSetup(org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup) PactVerification(au.com.dius.pact.provider.PactVerification) BaseTarget(au.com.dius.pact.provider.junit.target.BaseTarget) Interaction(au.com.dius.pact.model.Interaction) Provider(au.com.dius.pact.provider.junit.Provider) HttpRequest(org.apache.http.HttpRequest) MockMvc(org.springframework.test.web.servlet.MockMvc) Consumer(java.util.function.Consumer) URLClassLoader(java.net.URLClassLoader) ProviderVerifier(au.com.dius.pact.provider.ProviderVerifier) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) RequestResponseInteraction(au.com.dius.pact.model.RequestResponseInteraction) TargetRequestFilter(au.com.dius.pact.provider.junit.TargetRequestFilter) Target(au.com.dius.pact.provider.junit.target.Target) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Provider(au.com.dius.pact.provider.junit.Provider)

Aggregations

Interaction (au.com.dius.pact.model.Interaction)3 ConsumerInfo (au.com.dius.pact.provider.ConsumerInfo)3 ProviderInfo (au.com.dius.pact.provider.ProviderInfo)3 ProviderVerifier (au.com.dius.pact.provider.ProviderVerifier)3 Provider (au.com.dius.pact.provider.junit.Provider)3 URL (java.net.URL)3 PactVerification (au.com.dius.pact.provider.PactVerification)2 TargetRequestFilter (au.com.dius.pact.provider.junit.TargetRequestFilter)2 URLClassLoader (java.net.URLClassLoader)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Consumer (java.util.function.Consumer)2 HttpRequest (org.apache.http.HttpRequest)2 MethodClosure (org.codehaus.groovy.runtime.MethodClosure)2 FrameworkMethod (org.junit.runners.model.FrameworkMethod)2 Pact (au.com.dius.pact.model.Pact)1 RequestResponseInteraction (au.com.dius.pact.model.RequestResponseInteraction)1 PactBroker (au.com.dius.pact.provider.junit.loader.PactBroker)1 PactFolder (au.com.dius.pact.provider.junit.loader.PactFolder)1