public void testScopedLookup() {
    TestBean testBean = new TestBean();
    InnerBean newInner, oldInner = new InnerBean();
    testBean.setInner(oldInner);
    VariableResolver variableResolver = getFacesContext().getApplication().getVariableResolver();
    Object result = null;
    getFacesContext().getExternalContext().getSessionMap().remove("TestBean");

    //
    // Get tests
    //

    // application
    getFacesContext().getExternalContext().getApplicationMap().put("TestBean", testBean);
    result = variableResolver.resolveVariable(getFacesContext(), "TestBean");
    assertTrue(result == testBean);
    getFacesContext().getExternalContext().getApplicationMap().remove("TestBean");
    // session
    getFacesContext().getExternalContext().getSessionMap().put("TestBean", testBean);
    result = variableResolver.resolveVariable(getFacesContext(), "TestBean");
    assertTrue(result == testBean);
    getFacesContext().getExternalContext().getSessionMap().remove("TestBean");

    // session
    getFacesContext().getExternalContext().getRequestMap().put("TestBean", testBean);

    result = variableResolver.resolveVariable(getFacesContext(), "TestBean");
    assertTrue(result == testBean);
    getFacesContext().getExternalContext().getRequestMap().remove("TestBean");
  }
Esempio n. 2
0
  public void testMixedBeanPositive() throws Exception {
    ValueExpression vb = ELUtils.createValueExpression("#{threeBeanSaladPositive}");
    TestBean bean = (TestBean) vb.getValue(getFacesContext().getELContext());
    assertEquals("request request session session none none", bean.getProp());

    vb = ELUtils.createValueExpression("#{threeBeanSaladPositive.prop}");
    assertEquals(bean.getProp(), (String) vb.getValue(getFacesContext().getELContext()));
  }
Esempio n. 3
0
  public void testMixedBean() throws Exception {
    ValueExpression vb = ELUtils.createValueExpression("#{mixedBean}");
    TestBean bean = (TestBean) vb.getValue(getFacesContext().getELContext());
    assertEquals("mixed value Bobby \" \\  \\\" Orr", bean.getProp());

    vb = ELUtils.createValueExpression("#{mixedBean.prop}");
    assertEquals(bean.getProp(), (String) vb.getValue(getFacesContext().getELContext()));
  }
Esempio n. 4
0
  public void testMapTypeProperty() throws Exception {

    Map<String, String> entry = new HashMap(1, 1.0f);
    entry.put("name", "23");
    ManagedBeanInfo.MapEntry mapEntry =
        new ManagedBeanInfo.MapEntry("java.lang.String", "java.lang.Integer", entry);

    List<ManagedBeanInfo.ManagedProperty> properties =
        new ArrayList<ManagedBeanInfo.ManagedProperty>(1);
    ManagedBeanInfo.ManagedProperty property =
        new ManagedBeanInfo.ManagedProperty("mapProperty", null, null, mapEntry, null);
    properties.add(property);

    ManagedBeanInfo bean =
        new ManagedBeanInfo(beanName, beanName, "request", null, null, properties, 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.
    HashMap mapProperty = (HashMap) testBean.getMapProperty();

    assertTrue(mapProperty.get("name") instanceof Integer);

    Integer integer = new Integer("23");
    assertTrue(mapProperty.get("name").equals(integer));
  }
Esempio n. 5
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);
  }
Esempio n. 6
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"));
  }
Esempio n. 7
0
  public void testIndexProperty() throws Exception {
    List<String> values = new ArrayList<String>(2);
    values.add("foo");
    values.add("bar");
    ManagedBeanInfo.ListEntry listEntry = new ManagedBeanInfo.ListEntry(null, values);

    List<ManagedBeanInfo.ManagedProperty> properties =
        new ArrayList<ManagedBeanInfo.ManagedProperty>(2);
    ManagedBeanInfo.ManagedProperty property =
        new ManagedBeanInfo.ManagedProperty("indexProperties", null, null, null, listEntry);
    properties.add(property);

    property =
        new ManagedBeanInfo.ManagedProperty("indexPropertiesNull", null, null, null, listEntry);
    properties.add(property);

    ManagedBeanInfo bean =
        new ManagedBeanInfo(beanName, beanName, "request", null, null, properties, 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.
    ArrayList props = (ArrayList) testBean.getIndexProperties();
    assertTrue(props.get(5).equals("foo"));
    assertTrue(props.get(6).equals("bar"));

    // setter shouldn't be called if bean getter returns List
    assertTrue(!testBean.getListSetterCalled());

    // setter should be called if bean getter returned null
    assertTrue(testBean.getListNullSetterCalled());

    // make sure scope is stored properly
    BeanBuilder builder = beanManager.getBuilder(beanName);
    assertTrue(builder.getScope() == ELUtils.Scope.REQUEST);
  }
Esempio n. 8
0
  public void testMapProperty() throws Exception {

    Map<String, String> entry = new HashMap(1, 1.0f);
    entry.put("name", "Justyna");
    ManagedBeanInfo.MapEntry mapEntry = new ManagedBeanInfo.MapEntry(null, null, entry);

    List<ManagedBeanInfo.ManagedProperty> properties =
        new ArrayList<ManagedBeanInfo.ManagedProperty>(2);
    ManagedBeanInfo.ManagedProperty property =
        new ManagedBeanInfo.ManagedProperty("mapProperty", null, null, mapEntry, null);
    properties.add(property);

    property = new ManagedBeanInfo.ManagedProperty("mapPropertyNull", null, null, mapEntry, null);
    properties.add(property);

    ManagedBeanInfo bean =
        new ManagedBeanInfo(beanName, beanName, "request", null, null, properties, 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.
    HashMap mapProperty = (HashMap) testBean.getMapProperty();
    assertTrue(((String) mapProperty.get("name")).equals("Justyna"));

    // setter shouldn't be called if bean getter returns Map
    assertTrue(!testBean.getMapPropertySetterCalled());

    // setter should be called if bean getter returned null
    assertTrue(testBean.getMapPropertyNullSetterCalled());

    // make sure scope is stored properly
    BeanBuilder builder = beanManager.getBuilder(beanName);
    assertTrue(builder.getScope() == ELUtils.Scope.REQUEST);
  }
Esempio n. 9
0
  public void testSimpleNumericProperty() throws Exception {
    // If a property value is "" ensure numeric properties
    // are set to 0.
    List<ManagedBeanInfo.ManagedProperty> list = new ArrayList<ManagedBeanInfo.ManagedProperty>(1);

    boolean testBoolean = true;
    ManagedBeanInfo.ManagedProperty property =
        new ManagedBeanInfo.ManagedProperty(
            "boolProp", null, Boolean.toString(testBoolean), null, null);
    list.add(property);

    property = new ManagedBeanInfo.ManagedProperty("byteProp", null, "", null, null);
    list.add(property);

    property = new ManagedBeanInfo.ManagedProperty("charProp", null, "", null, null);
    list.add(property);

    property = new ManagedBeanInfo.ManagedProperty("doubleProp", null, "", null, null);
    list.add(property);

    property = new ManagedBeanInfo.ManagedProperty("floatProp", null, "", null, null);
    list.add(property);

    property = new ManagedBeanInfo.ManagedProperty("intProp", null, "", null, null);
    list.add(property);

    property = new ManagedBeanInfo.ManagedProperty("longProp", null, "", null, null);
    list.add(property);

    property = new ManagedBeanInfo.ManagedProperty("shortProp", null, "", null, null);
    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()));

    assertTrue(testBean.getByteProp() == 0);
    assertTrue(testBean.getCharProp() == 0);
    assertTrue(testBean.getDoubleProp() == 0);
    assertTrue(testBean.getFloatProp() == 0);
    assertTrue(testBean.getIntProp() == 0);
    assertTrue(testBean.getLongProp() == 0);
    assertTrue(testBean.getShortProp() == 0);
  }
Esempio n. 10
0
  public void testSimpleProperty() throws Exception {
    ManagedBeanInfo.ManagedProperty property =
        new ManagedBeanInfo.ManagedProperty("one", null, "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"));

    // make sure scope is stored properly
    BeanBuilder builder = beanManager.getBuilder(beanName);
    assertTrue(builder.getScope() == ELUtils.Scope.SESSION);
  }
Esempio n. 11
0
  public void testIndexTypeProperty() throws Exception {
    List<String> val = new ArrayList<String>(1);
    val.add("23");
    ManagedBeanInfo.ListEntry listEntry = new ManagedBeanInfo.ListEntry("java.lang.Integer", val);
    ManagedBeanInfo.ManagedProperty property =
        new ManagedBeanInfo.ManagedProperty(
            "indexIntegerProperties", "java.lang.Integer", null, null, listEntry);
    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.
    ArrayList properties = (ArrayList) testBean.getIndexIntegerProperties();
    assertTrue(properties.get(1) instanceof Integer);

    Integer integer = new Integer("23");
    assertTrue(properties.get(2).equals(integer));
  }
Esempio n. 12
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);
  }
Esempio n. 13
0
  public void testPrimitiveProperty() throws Exception {

    List<ManagedBeanInfo.ManagedProperty> list = new ArrayList<ManagedBeanInfo.ManagedProperty>(1);

    boolean testBoolean = true;
    ManagedBeanInfo.ManagedProperty property =
        new ManagedBeanInfo.ManagedProperty(
            "boolProp", null, Boolean.toString(testBoolean), null, null);
    list.add(property);

    byte testByte = 100;
    property =
        new ManagedBeanInfo.ManagedProperty(
            "byteProp", null, Byte.valueOf(testByte).toString(), null, null);
    list.add(property);

    char testChar = 'z';
    property =
        new ManagedBeanInfo.ManagedProperty(
            "charProp", null, Character.valueOf(testChar).toString(), null, null);
    list.add(property);

    double testDouble = 11.278D;
    property =
        new ManagedBeanInfo.ManagedProperty(
            "doubleProp", null, Double.valueOf(testDouble).toString(), null, null);
    list.add(property);

    float testFloat = 45.789F;
    property =
        new ManagedBeanInfo.ManagedProperty(
            "floatProp", null, Float.valueOf(testFloat).toString(), null, null);
    list.add(property);

    int testInt = 42;
    property =
        new ManagedBeanInfo.ManagedProperty(
            "intProp", null, Integer.valueOf(testInt).toString(), null, null);
    list.add(property);

    long testLong = 3147893289L;
    property =
        new ManagedBeanInfo.ManagedProperty(
            "longProp", null, Long.valueOf(testLong).toString(), null, null);
    list.add(property);

    short testShort = 25432;
    property =
        new ManagedBeanInfo.ManagedProperty(
            "shortProp", null, Short.valueOf(testShort).toString(), null, null);
    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.getBoolProp() == testBoolean);
    assertTrue(testBean.getByteProp() == testByte);
    assertTrue(testBean.getCharProp() == testChar);
    assertTrue(testBean.getDoubleProp() == testDouble);
    assertTrue(testBean.getFloatProp() == testFloat);
    assertTrue(testBean.getIntProp() == testInt);
    assertTrue(testBean.getLongProp() == testLong);
    assertTrue(testBean.getShortProp() == testShort);

    // make sure scope is stored properly
    BeanBuilder builder = beanManager.getBuilder(beanName);
    assertTrue(builder.getScope() == ELUtils.Scope.SESSION);
  }