Search in sources :

Example 41 with ExternalContext

use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.

the class ContextUtilTest method testGetFromFlash.

@Test
public void testGetFromFlash() {
    PowerMock.mockStatic(FacesContext.class);
    Flash flash = createMock(Flash.class);
    FacesContext facesContext = createMock(FacesContext.class);
    ExternalContext externalContext = createMock(ExternalContext.class);
    expect(FacesContext.getCurrentInstance()).andReturn(facesContext);
    expect(facesContext.getExternalContext()).andReturn(externalContext);
    expect(externalContext.getFlash()).andReturn(flash);
    expect(flash.get("key")).andReturn("value");
    PowerMock.replayAll(FacesContext.class, facesContext, externalContext, flash);
    Object actual = ContextUtil.getFromFlash("key");
    PowerMock.verifyAll();
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) Flash(javax.faces.context.Flash) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 42 with ExternalContext

use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.

the class ContextUtilTest method testPutIntoFlash.

@Test
public void testPutIntoFlash() {
    PowerMock.mockStatic(FacesContext.class);
    Flash flash = createMock(Flash.class);
    FacesContext facesContext = createMock(FacesContext.class);
    ExternalContext externalContext = createMock(ExternalContext.class);
    expect(FacesContext.getCurrentInstance()).andReturn(facesContext);
    expect(facesContext.getExternalContext()).andReturn(externalContext);
    expect(externalContext.getFlash()).andReturn(flash);
    expect(flash.put("key", "value")).andReturn("value");
    PowerMock.replayAll(FacesContext.class, facesContext, externalContext, flash);
    ContextUtil.putIntoFlash("key", "value");
    PowerMock.verifyAll();
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) Flash(javax.faces.context.Flash) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 43 with ExternalContext

use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.

the class ContextUtilTest method testGetFlash.

@Test
public void testGetFlash() {
    PowerMock.mockStatic(FacesContext.class);
    Flash flash = createMock(Flash.class);
    FacesContext facesContext = createMock(FacesContext.class);
    ExternalContext externalContext = createMock(ExternalContext.class);
    expect(FacesContext.getCurrentInstance()).andReturn(facesContext);
    expect(facesContext.getExternalContext()).andReturn(externalContext);
    expect(externalContext.getFlash()).andReturn(flash);
    PowerMock.replayAll(FacesContext.class, facesContext, externalContext);
    Flash actual = ContextUtil.getFlash();
    PowerMock.verifyAll();
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) Flash(javax.faces.context.Flash) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 44 with ExternalContext

use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.

the class ContextUtilTest method testGetExternalContext.

@Test
public void testGetExternalContext() {
    PowerMock.mockStatic(FacesContext.class);
    FacesContext facesContext = createMock(FacesContext.class);
    ExternalContext externalContext = createMock(ExternalContext.class);
    expect(FacesContext.getCurrentInstance()).andReturn(facesContext);
    expect(facesContext.getExternalContext()).andReturn(externalContext);
    PowerMock.replayAll(FacesContext.class);
    ExternalContext actual = ContextUtil.getExternalContext();
    PowerMock.verifyAll();
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 45 with ExternalContext

use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.

the class EffortsBeanTest method testExtractEffortsGroupingFromCookie.

@Test
public void testExtractEffortsGroupingFromCookie() throws Exception {
    FacesContext facesContext = createMock(FacesContext.class);
    ExternalContext externalContext = createMock(ExternalContext.class);
    HttpServletRequest httpServletRequest = createMock(HttpServletRequest.class);
    HttpServletResponse httpServletResponse = createMock(HttpServletResponse.class);
    Cookie[] cookies = new Cookie[] { new Cookie("efforts_grouping", BY_PROJECTS.toString()) };
    setField(effortsBean, "facesContext", facesContext);
    expect(facesContext.getExternalContext()).andReturn(externalContext).anyTimes();
    expect(externalContext.getRequest()).andReturn(httpServletRequest);
    expect(externalContext.getResponse()).andReturn(httpServletResponse);
    expect(httpServletRequest.getCookies()).andReturn(cookies).anyTimes();
    replay(facesContext, externalContext, httpServletRequest);
    EffortsGrouping expected = BY_PROJECTS;
    EffortsGrouping actual = Whitebox.invokeMethod(effortsBean, "extractEffortsGroupingFromCookie");
    assertEquals(expected, actual);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Cookie(javax.servlet.http.Cookie) FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ExternalContext (javax.faces.context.ExternalContext)58 FacesContext (javax.faces.context.FacesContext)28 Test (org.junit.Test)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 HashMap (java.util.HashMap)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 Map (java.util.Map)7 IOException (java.io.IOException)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 File (java.io.File)4 Method (java.lang.reflect.Method)4 Locale (java.util.Locale)4 FacesException (javax.faces.FacesException)4 Flash (javax.faces.context.Flash)4 InvocationContext (javax.interceptor.InvocationContext)4 ExceptionQueuedEvent (javax.faces.event.ExceptionQueuedEvent)3 ExceptionQueuedEventContext (javax.faces.event.ExceptionQueuedEventContext)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2