Example #1
0
 private AjaxContext getAjaxContext() {
   FacesContext context = FacesContextImpl.getCurrentInstance();
   if (context != null) {
     return AjaxContextImpl.getCurrentInstance(context);
   }
   return null;
 }
Example #2
0
  public String getReleaseResult2() {
    try {
      FacesContext currentContext = FacesContext.getCurrentInstance();
      ExternalContextImpl externalContext =
          new ExternalContextImpl(
              (ServletContext) currentContext.getExternalContext().getContext(),
              (HttpServletRequest) currentContext.getExternalContext().getRequest(),
              (HttpServletResponse) currentContext.getExternalContext().getResponse());
      LifecycleImpl lifecycle = new LifecycleImpl();

      FacesContextImpl context = new FacesContextImpl(externalContext, lifecycle);

      context.release();
      boolean exceptionThrown = false;
      try {
        context.getViewRoot();
      } catch (IllegalStateException ise) {
        exceptionThrown = true;
      }
      assertTrue(exceptionThrown);

      exceptionThrown = false;
      try {
        context.getResponseStream();
      } catch (IllegalStateException ise) {
        exceptionThrown = true;
      }

      exceptionThrown = false;
      try {
        context.getResponseWriter();
      } catch (IllegalStateException ise) {
        exceptionThrown = true;
      }
      assertTrue(exceptionThrown);

    } catch (NullPointerException exception) {
      exception.printStackTrace();
      fail();
    }

    return "PASSED";
  }
Example #3
0
  public String getReleaseResult1() {
    try {
      FacesContext currentContext = FacesContext.getCurrentInstance();
      ExternalContextImpl externalContext =
          new ExternalContextImpl(
              (ServletContext) currentContext.getExternalContext().getContext(),
              (HttpServletRequest) currentContext.getExternalContext().getRequest(),
              (HttpServletResponse) currentContext.getExternalContext().getResponse());
      LifecycleImpl lifecycle = new LifecycleImpl();

      FacesContextImpl context = new FacesContextImpl(externalContext, lifecycle);
      assertTrue(!context.isReleased());
      context.release();
      assertTrue(context.isReleased());

    } catch (NullPointerException exception) {
      exception.printStackTrace();
      fail();
    }

    return "PASSED";
  }
Example #4
0
  public String getRenderResult2() {
    try {
      FacesContext currentContext = FacesContext.getCurrentInstance();
      ExternalContextImpl externalContext =
          new ExternalContextImpl(
              (ServletContext) currentContext.getExternalContext().getContext(),
              (HttpServletRequest) currentContext.getExternalContext().getRequest(),
              (HttpServletResponse) currentContext.getExternalContext().getResponse());
      LifecycleImpl lifecycle = new LifecycleImpl();
      FacesContextImpl context = new FacesContextImpl(externalContext, lifecycle);

      /*
       * Actual test.
       */
      context.responseComplete();
      assertTrue(context.getResponseComplete());

    } catch (Exception exception) {
      exception.printStackTrace();
      fail();
    }
    return "PASSED";
  }
Example #5
0
  public String getRenderResult3() {
    try {
      FacesContext currentContext = FacesContext.getCurrentInstance();
      ExternalContextImpl externalContext =
          new ExternalContextImpl(
              (ServletContext) currentContext.getExternalContext().getContext(),
              (HttpServletRequest) currentContext.getExternalContext().getRequest(),
              (HttpServletResponse) currentContext.getExternalContext().getResponse());
      LifecycleImpl lifecycle = new LifecycleImpl();
      FacesContextImpl context = new FacesContextImpl(externalContext, lifecycle);

      /*
       * Actual test.
       */
      Application application = context.getApplication();
      UIViewRoot root = (UIViewRoot) application.createComponent(UIViewRoot.COMPONENT_TYPE);

      // if no UIViewRoot then null should be returned
      assertTrue(context.getRenderKit() == null);

      // if UIViewRoot is present but has no RenderKitID, null
      // should be rendered
      context.setViewRoot(root);
      assertTrue(context.getRenderKit() == null);

      // UIViewRoot is present, and has an ID for a non existent
      // RenderKit - null should be returned
      root.setRenderKitId("nosuchkit");
      assertTrue(context.getRenderKit() == null);

      // UIViewRoot with valid RenderKit id should return a RenderKit
      root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
      assertTrue(context.getRenderKit() != null);

    } catch (Exception exception) {
      exception.printStackTrace();
      fail();
    }
    return "PASSED";
  }