Skip to content

Commit

Permalink
Merge pull request #809 from caelum/restartingWeldContainerEachTest
Browse files Browse the repository at this point in the history
trying to fix Travis instability
  • Loading branch information
Turini committed Sep 23, 2014
2 parents f3c2541 + 96b934a commit 3678824
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
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

0 comments on commit 3678824

Please sign in to comment.