Пример #1
0
  public void testNoneScope() throws Exception {
    // Testing value ref scope
    TestBean testBean = new TestBean();
    testBean.setOne("one");
    boolean exceptionThrown = false;

    //  valueref in request scope
    //  managed bean in none scope
    // this should fail
    getFacesContext().getExternalContext().getRequestMap().put("TestRefBean", testBean);

    ManagedBeanInfo.ManagedProperty property =
        new ManagedBeanInfo.ManagedProperty("one", null, "#{TestRefBean.one}", null, null);
    List<ManagedBeanInfo.ManagedProperty> list = new ArrayList<ManagedBeanInfo.ManagedProperty>(1);
    list.add(property);
    ManagedBeanInfo bean = new ManagedBeanInfo(beanName, beanName, "none", null, null, list, null);
    BeanManager beanManager = ApplicationAssociate.getCurrentInstance().getBeanManager();
    beanManager.register(bean);

    exceptionThrown = false;
    try {
      beanManager.create(beanName, getFacesContext());
      fail("Should have thrown FacesException");
    } catch (FacesException ex) {
      exceptionThrown = true;
    }
    assertTrue(exceptionThrown);

    // cleanup
    getFacesContext().getExternalContext().getRequestMap().remove("TestRefBean");

    //  valueref in none scope
    //  managed bean in none scope
    // this should pass
    ValueExpression valueExpression1 =
        ELUtils.createValueExpression("#{testBean.customerBean.name}");
    exceptionThrown = false;
    try {
      valueExpression1.getValue(getFacesContext().getELContext());
    } catch (FacesException ex) {
      exceptionThrown = true;
    }
    assertTrue(!exceptionThrown);
  }
Пример #2
0
  public void testValueRefProperty() throws Exception {

    TestBean testBean = new TestBean();
    testBean.setOne("one");
    getFacesContext().getExternalContext().getSessionMap().put("TestRefBean", testBean);

    ManagedBeanInfo.ManagedProperty property =
        new ManagedBeanInfo.ManagedProperty("one", null, "#{TestRefBean.one}", null, null);
    List<ManagedBeanInfo.ManagedProperty> list = new ArrayList<ManagedBeanInfo.ManagedProperty>(1);
    list.add(property);
    ManagedBeanInfo bean =
        new ManagedBeanInfo(beanName, beanName, "session", null, null, list, null);
    BeanManager beanManager = ApplicationAssociate.getCurrentInstance().getBeanManager();
    beanManager.register(bean);

    // testing with a property set
    assertNotNull(testBean = (TestBean) beanManager.create(beanName, getFacesContext()));

    // make sure bean instantiated properly. Get property back from bean.
    assertTrue(testBean.getOne().equals("one"));
  }
Пример #3
0
  public void testValueRefScope() throws Exception {
    // Testing value ref scope

    TestBean testBean = new TestBean();
    testBean.setOne("one");
    boolean exceptionThrown = false;

    // testing with:
    //  valueref in application scope
    //  managed bean in session scope
    getFacesContext().getExternalContext().getApplicationMap().put("TestRefBean", testBean);

    ManagedBeanInfo.ManagedProperty property =
        new ManagedBeanInfo.ManagedProperty("one", null, "#{TestRefBean.one}", null, null);
    List<ManagedBeanInfo.ManagedProperty> list = new ArrayList<ManagedBeanInfo.ManagedProperty>(1);
    list.add(property);
    ManagedBeanInfo bean =
        new ManagedBeanInfo(beanName, beanName, "session", null, null, list, null);
    BeanManager beanManager = ApplicationAssociate.getCurrentInstance().getBeanManager();
    beanManager.register(bean);

    // testing with a property set
    assertNotNull(testBean = (TestBean) beanManager.create(beanName, getFacesContext()));

    // make sure bean instantiated properly. Get property back from bean.
    assertTrue(testBean.getOne().equals("one"));

    // testing with:
    //  valueref in request scope
    //  managed bean in application scope
    getFacesContext().getExternalContext().getApplicationMap().remove("TestRefBean");
    getFacesContext().getExternalContext().getRequestMap().put("TestRefBean", testBean);

    bean = new ManagedBeanInfo(beanName, beanName, "application", null, null, list, null);
    beanManager.register(bean);

    exceptionThrown = false;
    try {
      // testing with a property set
      beanManager.create(beanName, getFacesContext());
      fail("Should have thrown FacesException");
    } catch (FacesException ex) {
      exceptionThrown = true;
    }
    assertTrue(exceptionThrown);

    // cleanup
    getFacesContext().getExternalContext().getRequestMap().remove("TestRefBean");

    // testing with:
    //  valueref in session scope
    //  managed bean in no scope
    getFacesContext().getExternalContext().getSessionMap().put("TestRefBean", testBean);

    bean = new ManagedBeanInfo(beanName, beanName, "none", null, null, list, null);
    beanManager.register(bean);

    exceptionThrown = false;
    try {
      beanManager.create(beanName, getFacesContext());
      fail("Should have thrown FacesException");
    } catch (FacesException ex) {
      exceptionThrown = true;
    }
    assertTrue(exceptionThrown);
  }