0

When i use @ViewAccsessScoped beans from CODI i get the following error, when using Arquillian for testing my beans.

org.jboss.arquillian.test.spi.ArquillianProxyException: org.jboss.weld.context.ContextNotActiveException : WELD-001303 No active contexts for scope type org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ViewAccessScoped

is there anyway to get this to work?

//Trind

Trind
  • 1,583
  • 4
  • 18
  • 38

2 Answers2

0

You can check GroupedConversationContext#isActive to know if it's an issue with your setup or an issue with Arquillian. They just use the standard JSF API for doing the check.

Dar Whi
  • 822
  • 5
  • 14
0

I tried to mock the FacesContext and got it working no idea if this is the best approch however. I used Mockito to when doing the mocks.

    FacesContext mock = null;

    final Map<Object, Object> attributes = new HashMap<Object, Object>();

    public void mockFacesContext() {

        if (mock == null) {
            mock = Mockito.mock(FacesContext.class);

            try {
                Method m = FacesContext.class.getDeclaredMethod(
                        "setCurrentInstance", FacesContext.class);
                m.setAccessible(true);
                m.invoke(FacesContext.class, mock);

            } catch (Exception e) {
                e.printStackTrace();
            }

            Mockito.when(mock.getAttributes()).thenReturn(attributes);

            ExternalContext ext = Mockito.mock(ExternalContext.class);
            Mockito.when(ext.getSession(false)).thenReturn(
                    Mockito.mock(HttpSession.class));

            Mockito.when(mock.getExternalContext()).thenReturn(ext);

            UIViewRoot uiViewRoot = Mockito.mock(UIViewRoot.class);
            Mockito.when(uiViewRoot.getViewId()).thenReturn("/test");
            Mockito.when(uiViewRoot.getLocale()).thenReturn(new Locale("se"));
            Mockito.when(mock.getViewRoot()).thenReturn(uiViewRoot);

            Application application = Mockito.mock(Application.class);
            Mockito.when(application.getSupportedLocales()).thenReturn(
                    Mockito.mock(Iterator.class));

            Mockito.when(mock.getApplication()).thenReturn(application);

        }
        return mock;
    }
Trind
  • 1,583
  • 4
  • 18
  • 38