Пример #1
0
 // Test managed bean
 public void testNoProperty() throws Exception {
   // Testing with no properties set
   ManagedBeanInfo bean =
       new ManagedBeanInfo(beanName, beanName, "session", null, null, null, null);
   BeanManager beanManager = ApplicationAssociate.getCurrentInstance().getBeanManager();
   beanManager.register(bean);
   assertNotNull(beanManager.create(beanName, getFacesContext()));
   BeanBuilder builder = beanManager.getBuilder(beanName);
   assertTrue(builder.getScope() == ELUtils.Scope.SESSION);
 }
Пример #2
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);
  }
Пример #3
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);
  }
Пример #4
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);
  }
Пример #5
0
  /**
   * This method will be invoked {@link WebConfigResourceMonitor} when changes to any of the
   * faces-config.xml files included in WEB-INF are modified.
   */
  private void reload(ServletContext sc) {

    if (LOGGER.isLoggable(Level.INFO)) {
      LOGGER.log(
          Level.INFO,
          "Reloading JSF configuration for context {0}",
          getServletContextIdentifier(sc));
    }
    GroovyHelper helper = GroovyHelper.getCurrentInstance();
    if (helper != null) {
      helper.setClassLoader();
    }
    // tear down the application
    try {
      // this will only be true in the automated test usage scenario
      if (null != webAppListener) {
        List<HttpSession> sessions = webAppListener.getActiveSessions();
        if (sessions != null) {
          for (HttpSession session : sessions) {
            if (LOGGER.isLoggable(Level.INFO)) {
              LOGGER.log(Level.INFO, "Invalidating Session {0}", session.getId());
            }
            session.invalidate();
          }
        }
      }
      ApplicationAssociate associate = ApplicationAssociate.getInstance(sc);
      if (associate != null) {
        BeanManager manager = associate.getBeanManager();
        for (Map.Entry<String, BeanBuilder> entry : manager.getRegisteredBeans().entrySet()) {
          String name = entry.getKey();
          BeanBuilder bean = entry.getValue();
          if (ELUtils.Scope.APPLICATION.toString().equals(bean.getScope())) {
            if (LOGGER.isLoggable(Level.INFO)) {
              LOGGER.log(Level.INFO, "Removing application scoped managed bean: {0}", name);
            }
            sc.removeAttribute(name);
          }
        }
      }
      // Release any allocated application resources
      FactoryFinder.releaseFactories();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      FacesContext initContext = new InitFacesContext(sc);
      ApplicationAssociate.clearInstance(initContext.getExternalContext());
      ApplicationAssociate.setCurrentInstance(null);
      // Release the initialization mark on this web application
      ConfigManager.getInstance().destory(sc);
      initContext.release();
      ReflectionUtils.clearCache(Thread.currentThread().getContextClassLoader());
      WebConfiguration.clear(sc);
    }

    // bring the application back up, avoid re-registration of certain JSP
    // artifacts.  No verification will be performed either to make this
    // light weight.

    // init a new WebAppLifecycleListener so that the cached ApplicationAssociate
    // is removed.
    webAppListener = new WebappLifecycleListener(sc);

    FacesContext initContext = new InitFacesContext(sc);
    ReflectionUtils.initCache(Thread.currentThread().getContextClassLoader());

    try {
      ConfigManager configManager = ConfigManager.getInstance();
      configManager.initialize(sc);

      registerELResolverAndListenerWithJsp(sc, true);
      ApplicationAssociate associate = ApplicationAssociate.getInstance(sc);
      if (associate != null) {
        Boolean errorPagePresent =
            (Boolean) sc.getAttribute(RIConstants.ERROR_PAGE_PRESENT_KEY_NAME);
        if (null != errorPagePresent) {
          associate.setErrorPagePresent(errorPagePresent);
          associate.setContextName(getServletContextIdentifier(sc));
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      initContext.release();
    }

    if (LOGGER.isLoggable(Level.INFO)) {
      LOGGER.log(Level.INFO, "Reload complete.", getServletContextIdentifier(sc));
    }
  }
Пример #6
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);
  }