Search in sources :

Example 16 with InitializationError

use of org.junit.runners.model.InitializationError in project gerrit by GerritCodeReview.

the class ConfigSuite method runnersFor.

private static List<Runner> runnersFor(Class<?> clazz) {
    Method defaultConfig = getDefaultConfig(clazz);
    List<Method> configs = getConfigs(clazz);
    Map<String, org.eclipse.jgit.lib.Config> configMap = callConfigMapMethod(getConfigMap(clazz), configs);
    Field parameterField = getOnlyField(clazz, Parameter.class);
    checkArgument(parameterField != null, "No @ConfigSuite.Parameter found");
    Field nameField = getOnlyField(clazz, Name.class);
    List<Runner> result = Lists.newArrayListWithCapacity(configs.size() + 1);
    try {
        result.add(new ConfigRunner(clazz, parameterField, nameField, null, callConfigMethod(defaultConfig)));
        for (Method m : configs) {
            result.add(new ConfigRunner(clazz, parameterField, nameField, m.getName(), callConfigMethod(m)));
        }
        for (Map.Entry<String, org.eclipse.jgit.lib.Config> e : configMap.entrySet()) {
            result.add(new ConfigRunner(clazz, parameterField, nameField, e.getKey(), e.getValue()));
        }
        return result;
    } catch (InitializationError e) {
        System.err.println("Errors initializing runners:");
        for (Throwable t : e.getCauses()) {
            t.printStackTrace();
        }
        throw new RuntimeException(e);
    }
}
Also used : BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) Runner(org.junit.runner.Runner) InitializationError(org.junit.runners.model.InitializationError) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Field(java.lang.reflect.Field) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 17 with InitializationError

use of org.junit.runners.model.InitializationError in project pact-jvm by DiUS.

the class PactRunner method getPactSource.

protected PactLoader getPactSource(final TestClass clazz) throws InitializationError {
    final PactSource pactSource = clazz.getAnnotation(PactSource.class);
    final List<Annotation> pactLoaders = Arrays.stream(clazz.getAnnotations()).filter(annotation -> annotation.annotationType().getAnnotation(PactSource.class) != null).collect(toList());
    if ((pactSource == null ? 0 : 1) + pactLoaders.size() != 1) {
        throw new InitializationError("Exactly one pact source should be set");
    }
    try {
        if (pactSource != null) {
            final Class<? extends PactLoader> pactLoaderClass = pactSource.value();
            try {
                // Checks if there is a constructor with one argument of type Class.
                final Constructor<? extends PactLoader> contructorWithClass = pactLoaderClass.getDeclaredConstructor(Class.class);
                contructorWithClass.setAccessible(true);
                return contructorWithClass.newInstance(clazz.getJavaClass());
            } catch (NoSuchMethodException e) {
                LOGGER.error(e.getMessage(), e);
                return pactLoaderClass.newInstance();
            }
        } else {
            final Annotation annotation = pactLoaders.iterator().next();
            return annotation.annotationType().getAnnotation(PactSource.class).value().getConstructor(annotation.annotationType()).newInstance(annotation);
        }
    } catch (final InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        LOGGER.error("Error while creating pact source", e);
        throw new InitializationError(e);
    }
}
Also used : PactSource(au.com.dius.pact.provider.junit.loader.PactSource) Arrays(java.util.Arrays) PactBroker(au.com.dius.pact.provider.junit.loader.PactBroker) Logger(org.slf4j.Logger) Pact(au.com.dius.pact.model.Pact) LoggerFactory(org.slf4j.LoggerFactory) Description(org.junit.runner.Description) IOException(java.io.IOException) Constructor(java.lang.reflect.Constructor) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayList(java.util.ArrayList) HttpTarget(au.com.dius.pact.provider.junit.target.HttpTarget) TestTarget(au.com.dius.pact.provider.junit.target.TestTarget) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TestClass(org.junit.runners.model.TestClass) Annotation(java.lang.annotation.Annotation) PactLoader(au.com.dius.pact.provider.junit.loader.PactLoader) ParentRunner(org.junit.runners.ParentRunner) RunNotifier(org.junit.runner.notification.RunNotifier) InitializationError(org.junit.runners.model.InitializationError) PactFolder(au.com.dius.pact.provider.junit.loader.PactFolder) PactSource(au.com.dius.pact.provider.junit.loader.PactSource) Target(au.com.dius.pact.provider.junit.target.Target) InitializationError(org.junit.runners.model.InitializationError) Annotation(java.lang.annotation.Annotation) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with InitializationError

use of org.junit.runners.model.InitializationError in project drools-wb by kiegroup.

the class ScenarioRunnerService method run.

public TestScenarioResult run(final String identifier, final Scenario scenario, final KieModule module) {
    try {
        final HashMap<String, KieSession> ksessions = new HashMap<String, KieSession>();
        final String ksessionName = getKSessionName(scenario.getKSessions());
        ksessions.put(ksessionName, loadKSession(module, ksessionName));
        final AuditLogger auditLogger = new AuditLogger(ksessions);
        final ScenarioRunner4JUnit scenarioRunner = new ScenarioRunner4JUnit(scenario, ksessions, getMaxRuleFirings());
        run(identifier, scenarioRunner, defaultTestResultMessageEvent);
        return new TestScenarioResult(scenario, auditLogger.getLog());
    } catch (InitializationError initializationError) {
        throw new GenericPortableException(initializationError.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) InitializationError(org.junit.runners.model.InitializationError) GenericPortableException(org.guvnor.common.services.shared.exceptions.GenericPortableException) KieSession(org.kie.api.runtime.KieSession) ScenarioRunner4JUnit(org.drools.workbench.models.testscenarios.backend.ScenarioRunner4JUnit) TestScenarioResult(org.drools.workbench.screens.testscenario.model.TestScenarioResult)

Example 19 with InitializationError

use of org.junit.runners.model.InitializationError in project janusgraph by JanusGraph.

the class BerkeleyProcessStandardSuite method getTestList.

private static Class<?>[] getTestList() throws InitializationError {
    try {
        final Field field = ProcessStandardSuite.class.getDeclaredField("allTests");
        field.setAccessible(true);
        return (Class<?>[]) ArrayUtils.removeElement((Class<?>[]) field.get(null), TraversalInterruptionTest.class);
    } catch (ReflectiveOperationException e) {
        throw new InitializationError("Unable to create test list");
    }
}
Also used : Field(java.lang.reflect.Field) InitializationError(org.junit.runners.model.InitializationError) TraversalInterruptionTest(org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionTest)

Aggregations

InitializationError (org.junit.runners.model.InitializationError)19 ArrayList (java.util.ArrayList)4 Runner (org.junit.runner.Runner)4 IOException (java.io.IOException)3 ErrorReportingRunner (org.junit.internal.runners.ErrorReportingRunner)3 CucumberScenario (cucumber.runtime.model.CucumberScenario)2 Constructor (java.lang.reflect.Constructor)2 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 Test (org.junit.Test)2 AllDefaultPossibilitiesBuilder (org.junit.internal.builders.AllDefaultPossibilitiesBuilder)2 JUnitCore (org.junit.runner.JUnitCore)2 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)2 ParentRunner (org.junit.runners.ParentRunner)2 FrameworkMethod (org.junit.runners.model.FrameworkMethod)2 TestClass (org.junit.runners.model.TestClass)2 Pact (au.com.dius.pact.model.Pact)1 PactBroker (au.com.dius.pact.provider.junit.loader.PactBroker)1 PactFolder (au.com.dius.pact.provider.junit.loader.PactFolder)1 PactLoader (au.com.dius.pact.provider.junit.loader.PactLoader)1