@Override
  protected void afterSecondBootWithOverride(PortalContainer container) throws Exception {
    //
    RequestLifeCycle.begin(container);

    DataStorage dataStorage = (DataStorage) container.getComponentInstanceOfType(DataStorage.class);
    PortalConfig portal = dataStorage.getPortalConfig("classic");
    Container layout = portal.getPortalLayout();
    assertEquals(1, layout.getChildren().size());
    Application<Portlet> layoutPortlet = (Application<Portlet>) layout.getChildren().get(0);
    assertEquals("site1/layout", dataStorage.getId(layoutPortlet.getState()));

    //
    Page home = dataStorage.getPage("portal::classic::home");
    assertNotNull(home);
    assertEquals("site 1", home.getTitle());

    Page page1 = dataStorage.getPage("portal::classic::page1");
    assertNotNull(page1);
    assertEquals("site 1", page1.getTitle());

    Page page2 = dataStorage.getPage("portal::classic::page2");
    assertNotNull(page2);
    assertEquals("site 2", page2.getTitle());

    Page dashboard1 = dataStorage.getPage("user::root::dashboard1");
    assertNotNull(dashboard1);
    assertEquals("site 2", dashboard1.getTitle());

    RequestLifeCycle.end();
  }
  /**
   * Fill the UI component with both information from the persistent model and some coming from the
   * portlet.xml defined by the JSR 286 specification
   */
  private static <S> void toUIPortlet(UIPortlet<S, ?> uiPortlet, Application<S> model) {

    //
    PortletState<S> portletState = new PortletState<S>(model.getState(), model.getType());

    /*
     * Fill UI component object with info from the XML file that persist portlet information
     */
    uiPortlet.setWidth(model.getWidth());
    uiPortlet.setHeight(model.getHeight());
    uiPortlet.setState(portletState);
    uiPortlet.setTitle(model.getTitle());
    uiPortlet.setIcon(model.getIcon());
    uiPortlet.setDescription(model.getDescription());
    uiPortlet.setShowInfoBar(model.getShowInfoBar());
    uiPortlet.setShowWindowState(model.getShowApplicationState());
    uiPortlet.setShowPortletMode(model.getShowApplicationMode());
    uiPortlet.setProperties(model.getProperties());
    uiPortlet.setTheme(model.getTheme());
    if (model.getAccessPermissions() != null)
      uiPortlet.setAccessPermissions(model.getAccessPermissions());
    uiPortlet.setModifiable(model.isModifiable());

    Portlet portlet = uiPortlet.getProducedOfferedPortlet();
    if (portlet == null || portlet.getInfo() == null) return;

    PortletInfo portletInfo = portlet.getInfo();

    /*
     * Define which portlet modes the portlet supports and hence should be shown in the portlet info bar
     */
    Set<ModeInfo> modes = portletInfo.getCapabilities().getModes(MediaType.create("text/html"));
    List<String> supportModes = new ArrayList<String>();
    for (ModeInfo modeInfo : modes) {
      String modeName = modeInfo.getModeName().toLowerCase();
      if ("config".equals(modeInfo.getModeName())) {
        supportModes.add(modeName);
      } else {
        supportModes.add(modeName);
      }
    }

    if (supportModes.size() > 1) supportModes.remove("view");
    uiPortlet.setSupportModes(supportModes);
  }
 public static void toUIGadget(UIGadget uiGadget, Application<Gadget> model) {
   uiGadget.setProperties(model.getProperties());
   uiGadget.setState(model.getState());
 }