Search in sources :

Example 6 with FacesContext

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();
}
Also used : FacesContext(javax.faces.context.FacesContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with FacesContext

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);
}
Also used : FacesContext(javax.faces.context.FacesContext) ViewHandler(javax.faces.application.ViewHandler) Application(javax.faces.application.Application) UIViewRoot(javax.faces.component.UIViewRoot) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with FacesContext

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);
}
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)

Example 9 with FacesContext

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);
}
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)

Example 10 with FacesContext

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);
}
Also used : FacesContext(javax.faces.context.FacesContext) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) List(java.util.List) Date(java.util.Date) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FacesContext (javax.faces.context.FacesContext)361 NodeRef (org.alfresco.service.cmr.repository.NodeRef)61 Node (org.alfresco.web.bean.repository.Node)44 UserTransaction (javax.transaction.UserTransaction)43 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)28 IOException (java.io.IOException)27 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)27 ExternalContext (javax.faces.context.ExternalContext)26 SelectItem (javax.faces.model.SelectItem)26 QName (org.alfresco.service.namespace.QName)25 FacesMessage (javax.faces.application.FacesMessage)24 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Map (java.util.Map)21 ResourceBundle (java.util.ResourceBundle)20 HttpServletResponse (javax.servlet.http.HttpServletResponse)19 MapNode (org.alfresco.web.bean.repository.MapNode)18 UIViewRoot (javax.faces.component.UIViewRoot)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 Serializable (java.io.Serializable)15