use of javax.faces.context.FacesContext in project ART-TIME by Artezio.
the class ContextUtilTest method testGetFacesContext.
@Test
public void testGetFacesContext() {
PowerMock.mockStatic(FacesContext.class);
FacesContext facesContext = createMock(FacesContext.class);
expect(FacesContext.getCurrentInstance()).andReturn(facesContext);
PowerMock.replayAll(FacesContext.class);
FacesContext actual = ContextUtil.getFacesContext();
PowerMock.verifyAll();
}
use of javax.faces.context.FacesContext in project ART-TIME by Artezio.
the class EffortsBeanTest method testResetComponentsTree.
@Test
public void testResetComponentsTree() throws Exception {
FacesContext facesContext = createMock(FacesContext.class);
Application application = createMock(Application.class);
ViewHandler viewHandler = createMock(ViewHandler.class);
UIViewRoot viewRoot = createMock(UIViewRoot.class);
String viewId = "viewId";
setField(effortsBean, "facesContext", facesContext);
expect(facesContext.getApplication()).andReturn(application);
expect(application.getViewHandler()).andReturn(viewHandler);
expect(facesContext.getViewRoot()).andReturn(viewRoot);
expect(viewRoot.getViewId()).andReturn(viewId);
expect(viewHandler.createView(facesContext, viewId)).andReturn(viewRoot);
facesContext.setViewRoot(viewRoot);
replay(facesContext, application, viewHandler, viewRoot);
effortsBean.resetComponentsTree();
verify(facesContext, application, viewHandler, viewRoot);
}
use of javax.faces.context.FacesContext in project ART-TIME by Artezio.
the class EffortsBeanTest method testGetGrouping_GroupingIsNullCookieIsNull.
@Test
public void testGetGrouping_GroupingIsNullCookieIsNull() throws NoSuchFieldException {
EffortsGrouping defaultGrouping = BY_PROJECTS;
FacesContext facesContext = createMock(FacesContext.class);
ExternalContext externalContext = createMock(ExternalContext.class);
HttpServletRequest httpServletRequest = createMock(HttpServletRequest.class);
HttpServletResponse httpServletResponse = createMock(HttpServletResponse.class);
Cookie[] cookies = new Cookie[0];
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 = defaultGrouping;
EffortsGrouping actual = effortsBean.getGrouping();
assertEquals(expected, actual);
}
use of javax.faces.context.FacesContext in project ART-TIME by Artezio.
the class EffortsBeanTest method testGetGrouping_GroupingIsNullCookieIsNotNull.
@Test
public void testGetGrouping_GroupingIsNullCookieIsNotNull() throws NoSuchFieldException {
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);
replay(facesContext, externalContext, httpServletRequest);
EffortsGrouping expected = BY_PROJECTS;
EffortsGrouping actual = effortsBean.getGrouping();
assertEquals(expected, actual);
}
use of javax.faces.context.FacesContext in project ART-TIME by Artezio.
the class PeriodValidatorTest method testValidate_ifNotValid.
@Test(expected = ValidatorException.class)
public void testValidate_ifNotValid() throws Exception {
Date date1 = sdf.parse("1-01-2015");
Date date2 = sdf.parse("31-01-2015");
ConstraintViolation<Object> violation = createMock(ConstraintViolation.class);
Set<ConstraintViolation<Object>> violations = new HashSet<ConstraintViolation<Object>>();
violations.add(violation);
periodValidator = createMockBuilder(PeriodValidator.class).addMockedMethod("getStartComponent", UIComponent.class).addMockedMethod("createBeanValidator", FacesContext.class).addMockedMethod("showErrorsForStart", UIComponent.class, UIComponent.class, List.class).createMock();
expect(periodValidator.getStartComponent(component)).andReturn(input);
expect(input.getValue()).andReturn(date1);
expect(periodValidator.createBeanValidator(facesContext)).andReturn(validator);
expect(validator.validate(anyObject())).andReturn(violations);
expect(violation.getMessage()).andReturn("Validation error!!!");
input.setValid(false);
periodValidator.showErrorsForStart(eq(input), eq(component), anyObject(List.class));
replay(periodValidator, input, validator, violation);
periodValidator.validate(facesContext, component, date2);
verify(periodValidator, input, validator, violation);
}
Aggregations