Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to fix Travis instability #809

Merged
merged 2 commits into from
Sep 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
*/
package br.com.caelum.vraptor;

import javax.enterprise.inject.spi.CDI;

import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
Expand All @@ -31,14 +32,10 @@
public class WeldJunitRunner extends BlockJUnit4ClassRunner {

private Class<?> clazz;
private static WeldContainer weldContainer;

static {
weldContainer = new Weld().initialize();
}

public WeldJunitRunner(Class<?> testClass) throws InitializationError {
super(testClass);
new Weld().initialize();
this.clazz = testClass;
}

Expand All @@ -47,17 +44,14 @@ public WeldJunitRunner(Class<?> testClass) throws InitializationError {
*/
@Override
protected Object createTest() throws Exception {
return currentInstance(clazz);
return CDI.current().select(clazz).get();
}

@Override
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
currentInstance(Contexts.class).startRequestScope();
Contexts contexts = CDI.current().select(Contexts.class).get();
contexts.startRequestScope();
super.runChild(method, notifier);
currentInstance(Contexts.class).stopRequestScope();
}

private <T> T currentInstance(Class<T> clazz) {
return weldContainer.instance().select(clazz).get();
contexts.stopRequestScope();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package br.com.caelum.vraptor.ioc;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Event;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Specializes;
Expand All @@ -30,7 +31,7 @@
import br.com.caelum.vraptor.http.UrlToControllerTranslator;
import br.com.caelum.vraptor.observer.RequestHandlerObserver;

@Specializes
@Specializes @ApplicationScoped
class MockRequestHandlerObserver extends RequestHandlerObserver{
private boolean vraptorStackCalled;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.HashMap;
import java.util.Map;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.jboss.weld.context.AbstractSharedContext;
Expand All @@ -27,6 +28,7 @@
import org.jboss.weld.context.bound.BoundSessionContext;
import org.jboss.weld.context.bound.MutableBoundRequest;

@ApplicationScoped
public class Contexts {

@Inject
Expand Down