Search in sources :

Example 1 with IInjectorProvider

use of org.eclipse.xtext.junit4.IInjectorProvider in project xtext-eclipse by eclipse.

the class InjectorProviders method getOrCreateInjectorProvider.

public static IInjectorProvider getOrCreateInjectorProvider(TestClass testClass) {
    InjectWith injectWith = testClass.getJavaClass().getAnnotation(InjectWith.class);
    if (injectWith != null) {
        Class<? extends IInjectorProvider> klass = injectWith.value();
        IInjectorProvider injectorProvider = injectorProviderClassCache.get(klass);
        if (injectorProvider == null) {
            try {
                injectorProvider = klass.getDeclaredConstructor().newInstance();
                injectorProviderClassCache.put(klass, injectorProvider);
            } catch (Exception e) {
                throwUncheckedException(e);
            }
        }
        return injectorProvider;
    }
    return null;
}
Also used : InjectWith(org.eclipse.xtext.junit4.InjectWith) IInjectorProvider(org.eclipse.xtext.junit4.IInjectorProvider)

Example 2 with IInjectorProvider

use of org.eclipse.xtext.junit4.IInjectorProvider in project xtext-eclipse by eclipse.

the class AbstractParallelScenarioRunner method childrenInvoker.

@Override
protected Statement childrenInvoker(final RunNotifier notifier) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            WrappingInjectorProvider wrapped = getOrCreateInjectorProvider();
            wrapped.setupRegistry();
            try {
                prepareChildren(notifier);
            } finally {
                wrapped.restoreRegistry();
            }
            IInjectorProvider delegate = wrapped.getDelegate();
            if (delegate instanceof IRegistryConfigurator) {
                IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) delegate;
                registryConfigurator.setupRegistry();
                try {
                    runChildren(notifier);
                } finally {
                    registryConfigurator.restoreRegistry();
                }
            } else {
                runChildren(notifier);
            }
        }
    };
}
Also used : IInjectorProvider(org.eclipse.xtext.junit4.IInjectorProvider) Statement(org.junit.runners.model.Statement) IRegistryConfigurator(org.eclipse.xtext.junit4.IRegistryConfigurator)

Example 3 with IInjectorProvider

use of org.eclipse.xtext.junit4.IInjectorProvider in project xtext-eclipse by eclipse.

the class AbstractParallelScenarioRunner method process.

@Override
protected void process(String data) throws Exception {
    IInjectorProvider delegate = getOrCreateInjectorProvider().getDelegate();
    ScenarioProcessor processor = delegate.getInjector().getInstance(getProcessorClass());
    String preProcessed = processor.preProcess(data);
    if (preProcessed == null) {
        throw new AssumptionViolatedException("Input is filtered by the pre processing step: " + data);
    }
    doProcess(preProcessed, processor);
}
Also used : ScenarioProcessor(org.eclipse.xtext.junit4.smoketest.ScenarioProcessor) IInjectorProvider(org.eclipse.xtext.junit4.IInjectorProvider) AssumptionViolatedException(org.junit.AssumptionViolatedException)

Example 4 with IInjectorProvider

use of org.eclipse.xtext.junit4.IInjectorProvider in project xtext-eclipse by eclipse.

the class AbstractScenarioRunner method methodBlock.

@Override
protected Statement methodBlock(final FrameworkMethod method) {
    IInjectorProvider injectorProvider = getOrCreateInjectorProvider();
    final IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) injectorProvider;
    registryConfigurator.setupRegistry();
    final Statement methodBlock = superMethodBlock(method);
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            try {
                try {
                    methodBlock.evaluate();
                    throw new AssumptionViolatedException("Method " + method.getName() + " did parse any input");
                } finally {
                    registryConfigurator.restoreRegistry();
                }
            } catch (TestDataCarrier testData) {
                process(testData.getData());
            }
        }
    };
}
Also used : IInjectorProvider(org.eclipse.xtext.junit4.IInjectorProvider) AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) IRegistryConfigurator(org.eclipse.xtext.junit4.IRegistryConfigurator)

Example 5 with IInjectorProvider

use of org.eclipse.xtext.junit4.IInjectorProvider in project xtext-eclipse by eclipse.

the class AbstractScenarioRunner method process.

protected void process(String data) throws Exception {
    IInjectorProvider delegate = getOrCreateInjectorProvider().getDelegate();
    if (delegate instanceof IRegistryConfigurator) {
        IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) delegate;
        registryConfigurator.setupRegistry();
        try {
            ScenarioProcessor processor = delegate.getInjector().getInstance(processorClass);
            String preProcessed = processor.preProcess(data);
            if (preProcessed == null) {
                throw new AssumptionViolatedException("Input is filtered by the pre processing step: " + data);
            }
            doProcess(preProcessed, processor);
        } finally {
            registryConfigurator.restoreRegistry();
        }
    }
}
Also used : ScenarioProcessor(org.eclipse.xtext.junit4.smoketest.ScenarioProcessor) IInjectorProvider(org.eclipse.xtext.junit4.IInjectorProvider) AssumptionViolatedException(org.junit.AssumptionViolatedException) IRegistryConfigurator(org.eclipse.xtext.junit4.IRegistryConfigurator)

Aggregations

IInjectorProvider (org.eclipse.xtext.junit4.IInjectorProvider)5 IRegistryConfigurator (org.eclipse.xtext.junit4.IRegistryConfigurator)3 AssumptionViolatedException (org.junit.AssumptionViolatedException)3 ScenarioProcessor (org.eclipse.xtext.junit4.smoketest.ScenarioProcessor)2 Statement (org.junit.runners.model.Statement)2 InjectWith (org.eclipse.xtext.junit4.InjectWith)1