Beispiel #1
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);
  }
Beispiel #2
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);
  }