Search in sources :

Example 26 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project spring-framework by spring-projects.

the class SpringJUnit4ClassRunnerTests method getSpringTimeoutViaMetaAnnotationWithOverride.

@Test
public void getSpringTimeoutViaMetaAnnotationWithOverride() throws Exception {
    SpringJUnit4ClassRunner runner = new SpringJUnit4ClassRunner(getClass());
    long timeout = runner.getSpringTimeout(new FrameworkMethod(getClass().getDeclaredMethod("springTimeoutWithMetaAnnotationAndOverride")));
    assertEquals(42, timeout);
}
Also used : FrameworkMethod(org.junit.runners.model.FrameworkMethod) Test(org.junit.Test)

Example 27 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod 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 28 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod 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)

Example 29 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project tomee by apache.

the class TomEEEmbeddedSingleRunner method rules.

@Override
protected List<MethodRule> rules(final Object test) {
    final List<MethodRule> rules = super.rules(test);
    rules.add(new MethodRule() {

        @Override
        public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
            return new Statement() {

                @Override
                public void evaluate() throws Throwable {
                    start(test);
                    getRunner().composerInject(target);
                    base.evaluate();
                }
            };
        }
    });
    return rules;
}
Also used : MethodRule(org.junit.rules.MethodRule) Statement(org.junit.runners.model.Statement) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 30 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project sling by apache.

the class PerformanceRunner method computePerformanceTests.

/**
     * Compute performance tests
     *
     * @return the list containing the performance test methods
     * @throws Exception
     */
protected Collection<? extends FrameworkMethod> computePerformanceTests() throws Exception {
    List<FrameworkMethod> tests = new LinkedList<FrameworkMethod>();
    List<Object> testObjects = new ArrayList<Object>();
    List<Object> testObjectsTmp = new ArrayList<Object>();
    ParameterizedTestList testCenter = new ParameterizedTestList();
    // Retrieve the test objects included in the Performance test suite
    for (FrameworkMethod method : getTestClass().getAnnotatedMethods(PerformanceTestSuite.class)) {
        Object targetObject = getTestClass().getJavaClass().newInstance();
        if (method.getMethod().getReturnType().equals(ParameterizedTestList.class)) {
            testCenter = (ParameterizedTestList) method.getMethod().invoke(targetObject);
            testObjectsTmp = testCenter.getTestObjectList();
            // Iterate through all the test cases and see if they have a factory
            for (Object testObject : testObjectsTmp) {
                Method[] factoryMethods = getSpecificMethods(testObject.getClass(), PerformanceTestFactory.class);
                // If we have a factory method, get all the instance objects returned by this factory
                if (factoryMethods.length > 0) {
                    // Make sure there's only one factory method
                    if (factoryMethods.length > 1) {
                        throw new IllegalStateException("There should be at most one PerformanceTestFactory method");
                    }
                    Method factoryMethod = factoryMethods[0];
                    // Execute the method (statically)
                    Object instances = factoryMethod.invoke(testObject);
                    // If the factory returned an array, make a list
                    if (instances.getClass().isArray()) {
                        instances = Arrays.asList((Object[]) instances);
                    }
                    // If the factory returned a single element, put it in a list
                    if (!(instances instanceof Iterable<?>)) {
                        instances = Collections.singletonList(instances);
                    }
                    testObjects.addAll((List) instances);
                } else {
                    testObjects.add(testObject);
                }
            }
        } else {
            throw new InitializationError("Wrong signature for the @PerformanceTestSuite method");
        }
    }
    // Retrieve the methods before running the methods from the test suite
    List<FrameworkMethod> beforeSuiteMethods = getTestClass().getAnnotatedMethods(BeforeSuite.class);
    if (beforeSuiteMethods.size() > 1) {
        throw new InitializationError("Only one @BeforeSuite method is allowed for a @PerformanceSuite");
    }
    // Retrieve the methods before running the methods from the test suite
    List<FrameworkMethod> afterSuiteMethods = getTestClass().getAnnotatedMethods(AfterSuite.class);
    if (afterSuiteMethods.size() > 1) {
        throw new InitializationError("Only one @AfterSuite method is allowed for a @PerformanceSuite");
    }
    PerformanceSuiteState current = null;
    boolean suiteAlreadyRegistered = false;
    for (PerformanceSuiteState suiteState : suitesState) {
        if (suiteState.testSuiteName.equals(testCenter.getTestSuiteName())) {
            suiteAlreadyRegistered = true;
            suiteState.incrementNumberOfTestMethodsInSuite();
            current = suiteState;
            break;
        }
    }
    // Create a new PerformanceSuiteState object
    PerformanceSuiteState newSuite = new PerformanceSuiteState(testCenter.getTestSuiteName());
    if (!suiteAlreadyRegistered) {
        if (beforeSuiteMethods.size() == 1) {
            newSuite.setBeforeSuiteMethod(beforeSuiteMethods.get(0).getMethod());
        }
        if (afterSuiteMethods.size() == 1) {
            newSuite.setAfterSuiteMethod(afterSuiteMethods.get(0).getMethod());
        }
        current = newSuite;
        newSuite.setTargetObjectSuite(getTestClass().getJavaClass().newInstance());
    }
    // contained in the PerformanceSuite
    if (!testObjects.isEmpty()) {
        for (Object testObject : testObjects) {
            // retrieve the test methods from the test classes
            Method[] testMethods = getSpecificMethods(testObject.getClass(), PerformanceTest.class);
            for (Method method : testMethods) {
                FrameworkPerformanceMethod performaceTestMethod = new FrameworkPerformanceMethod(method, testObject, current, reportLevel, referenceMethod);
                tests.add(performaceTestMethod);
            }
            if (!suiteAlreadyRegistered) {
                newSuite.incrementNumberOfTestMethodsInSuite();
            }
        }
        // add the new suite to the list of suites
        suitesState.add(newSuite);
    }
    // performance test suite
    for (FrameworkMethod method : getTestClass().getAnnotatedMethods(PerformanceTest.class)) {
        Object targetObject = getTestClass().getJavaClass().newInstance();
        FrameworkPerformanceMethod performanceTestMethod = new FrameworkPerformanceMethod(method.getMethod(), targetObject, current, reportLevel, referenceMethod);
        tests.add(performanceTestMethod);
    }
    return tests;
}
Also used : InitializationError(org.junit.runners.model.InitializationError) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod) LinkedList(java.util.LinkedList) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Aggregations

FrameworkMethod (org.junit.runners.model.FrameworkMethod)59 ArrayList (java.util.ArrayList)15 Statement (org.junit.runners.model.Statement)13 TestClass (org.junit.runners.model.TestClass)13 Test (org.junit.Test)11 Method (java.lang.reflect.Method)10 MethodRule (org.junit.rules.MethodRule)5 Fail (org.junit.internal.runners.statements.Fail)4 RunBefores (org.junit.internal.runners.statements.RunBefores)4 TestRule (org.junit.rules.TestRule)4 Parameterized (org.junit.runners.Parameterized)3 Interaction (au.com.dius.pact.model.Interaction)2 ConsumerInfo (au.com.dius.pact.provider.ConsumerInfo)2 ProviderInfo (au.com.dius.pact.provider.ProviderInfo)2 ProviderVerifier (au.com.dius.pact.provider.ProviderVerifier)2 Provider (au.com.dius.pact.provider.junit.Provider)2 TargetRequestFilter (au.com.dius.pact.provider.junit.TargetRequestFilter)2 BounceMemberRule (com.hazelcast.test.bounce.BounceMemberRule)2 EmptyStatement (com.hazelcast.util.EmptyStatement)2 URL (java.net.URL)2