@Test
  public void getForumsByUserId() {
    User user = new User();
    user.setPassword("1");
    user.setEmail("a");
    user.setRegistrationDate(new Date());
    persistance.putUser(user);

    Site site = new Site();
    site.getSitePaymentSettings().setUserId(-1);
    site.setSubDomain("$");
    site.getThemeId().setTemplateDirectory("f");
    site.getThemeId().setThemeCss("G");
    site.setTitle("F");
    persistance.putSite(site);

    UserOnSiteRight userOnUserRight = new UserOnSiteRight();
    userOnUserRight.setActive(true);
    userOnUserRight.setSiteAccessType(SiteAccessLevel.ADMINISTRATOR);
    user.addUserOnSiteRight(userOnUserRight);
    site.addUserOnSiteRight(userOnUserRight);
    persistance.putUserOnSiteRight(userOnUserRight);

    DraftForum forum = new DraftForum();
    forum.setSiteId(site.getSiteId());
    forum.setName("name");
    persistance.putItem(forum);

    List<DraftItem> userForums =
        persistance.getDraftItemsByUserId(user.getUserId(), ItemType.FORUM);
    Assert.assertEquals(forum, userForums.get(0));
  }
  @Test
  public void removeForumFromForumWidget() {
    DraftForum forum = new DraftForum();
    forum.setName("name");
    persistance.putItem(forum);

    Site site = new Site();
    site.getSitePaymentSettings().setUserId(-1);
    site.setTitle("f");
    site.getThemeId().setTemplateDirectory("f");
    site.getThemeId().setThemeCss("f");
    site.setSubDomain("f");
    persistance.putSite(site);

    Page page = TestUtil.createPage(site);
    PageManager pageVersion = new PageManager(page);

    WidgetItem widgetForum = new WidgetItem();
    widgetForum.setDraftItem(forum);
    persistance.putWidget(widgetForum);
    pageVersion.addWidget(widgetForum);

    persistance.removeDraftItem(forum);

    Assert.assertNull(persistance.getDraftItem(forum.getId()));
    Assert.assertNotNull(widgetForum.getDraftItem());
  }
  @Test
  public void getForumsByUserIdWithoutActive() {
    User user = new User();
    user.setPassword("1");
    user.setEmail("a");
    user.setRegistrationDate(new Date());
    persistance.putUser(user);

    Site site = new Site();
    site.getSitePaymentSettings().setUserId(-1);
    site.setSubDomain("$");
    site.getThemeId().setTemplateDirectory("f");
    site.getThemeId().setThemeCss("G");
    site.setTitle("F");
    persistance.putSite(site);

    DraftForum forum = new DraftForum();
    forum.setSiteId(site.getSiteId());
    forum.setName("name");
    persistance.putItem(forum);

    List<DraftItem> userForums =
        persistance.getDraftItemsByUserId(user.getUserId(), ItemType.FORUM);
    Assert.assertEquals(0, userForums.size());
  }
  @Test
  public void putSiteOnForumRight() {
    DraftForum forum = new DraftForum();
    forum.setName("aa");
    persistance.putItem(forum);

    Site site = new Site();
    site.getSitePaymentSettings().setUserId(-1);
    site.setTitle("f");
    site.setSubDomain("g");
    site.getThemeId().setTemplateDirectory("f");
    site.getThemeId().setThemeCss("f");
    persistance.putSite(site);

    SiteOnItem siteOnForumRight = new SiteOnItem();
    siteOnForumRight.getId().setItem(forum);
    siteOnForumRight.getId().setSite(site);
    persistance.putSiteOnItem(siteOnForumRight);
  }
  @Test
  public void getFormFiltersByUserId_and_getFormFilterByNameAndUserId() {
    User user = new User();
    user.setPassword("1");
    user.setEmail("a");
    user.setRegistrationDate(new Date());
    persistance.putUser(user);

    Site site = new Site();
    site.getSitePaymentSettings().setUserId(-1);
    site.setSubDomain("$");
    site.getThemeId().setTemplateDirectory("f");
    site.getThemeId().setThemeCss("G");
    site.setTitle("F");
    persistance.putSite(site);

    UserOnSiteRight userOnUserRight = new UserOnSiteRight();
    userOnUserRight.setActive(true);
    userOnUserRight.setSiteAccessType(SiteAccessLevel.ADMINISTRATOR);
    user.addUserOnSiteRight(userOnUserRight);
    site.addUserOnSiteRight(userOnUserRight);
    persistance.putUserOnSiteRight(userOnUserRight);

    DraftForm form = new DraftCustomForm();
    form.setSiteId(site.getSiteId());
    form.setName("name");
    persistance.putItem(form);

    DraftFormFilter filter = new DraftFormFilter();
    filter.setForm(form);
    String filterName = "filter name " + System.currentTimeMillis();
    filter.setName(filterName);
    persistance.putFormFilter(filter);

    List<DraftFormFilter> userFitlers = persistance.getFormFiltersByUserId(user.getUserId());
    Assert.assertEquals(filter, userFitlers.get(0));

    DraftFormFilter namedUserFilter =
        persistance.getFormFilterByNameAndUserId(filterName, user.getUserId());
    Assert.assertEquals(filter, namedUserFilter);
  }
  @Test
  public void testExecute_WithActiveUser_firstState() throws Exception {
    ServiceLocator.getConfigStorage().get().setUserSitesUrl("web-deva.com");
    User user = TestUtil.createUser();
    final Date activationDate = new Date();
    user.setActiveted(activationDate);
    Site parentSite = TestUtil.createSite();
    DraftChildSiteRegistration registration = TestUtil.createChildSiteRegistration(parentSite);
    ChildSiteSettings settings = TestUtil.createChildSiteSettings(registration, parentSite);
    settings.setCreatedDate(new Date());
    settings.setUserId(user.getUserId());
    settings.setConfirmCode("confirm");
    settings.setAccessLevel(SiteAccessLevel.ADMINISTRATOR);

    FilledForm filledForm = TestUtil.createFilledForm(registration.getFormId());
    FilledFormItem filledFormItemDomainName =
        TestUtil.createFilledFormItem(FormItemName.YOUR_OWN_DOMAIN_NAME);
    List<String> values = Arrays.asList("domainName");
    filledFormItemDomainName.setValues(values);

    FilledFormItem filledFormItemSiteName =
        TestUtil.createFilledFormItem(FormItemName.YOUR_PAGE_SITE_NAME);
    List<String> siteNameValues = Arrays.asList("siteName");
    filledFormItemSiteName.setValues(siteNameValues);

    filledForm.setFilledFormItems(Arrays.asList(filledFormItemDomainName, filledFormItemSiteName));
    settings.setFilledFormId(filledForm.getFilledFormId());

    action.setSettingsId(settings.getChildSiteSettingsId());
    action.setConfirmCode("confirm");

    DraftChildSiteRegistration childSiteRegistration =
        TestUtil.createChildSiteRegistration("name", "comment");
    final Site blueprint = TestUtil.createBlueprint();
    blueprint.getThemeId().setTemplateDirectory("TemplateDirectory");
    blueprint.getThemeId().setThemeCss("ThemeCss");
    childSiteRegistration.setBlueprintsId(Arrays.asList(blueprint.getSiteId()));

    settings.setRequiredToUseSiteBlueprint(true);
    final SitePaymentSettings sitePaymentSettings = new SitePaymentSettings();
    sitePaymentSettings.setSiteStatus(SiteStatus.ACTIVE);
    settings.setSitePaymentSettings(sitePaymentSettings);
    settings.setChildSiteRegistration(childSiteRegistration);

    Assert.assertEquals(activationDate, user.getActiveted());
    Assert.assertNull(new UsersManager().getLoginedUser());
    Assert.assertNull(ServiceLocator.getPersistance().getSiteBySubDomain("domainname"));

    ForwardResolution resolutionMock = (ForwardResolution) action.show();
    Assert.assertNotNull(new UsersManager().getLoginedUser());
    Assert.assertEquals(user, new UsersManager().getLoginedUser());
    Assert.assertEquals(
        "/account/registration/childSiteRigistrationConfirmationFirstState.jsp",
        resolutionMock.getPath());

    Assert.assertEquals(activationDate, user.getActiveted());
    Assert.assertNotNull(new UsersManager().getLoginedUser());
    Assert.assertEquals(user, new UsersManager().getLoginedUser());
    Site site = ServiceLocator.getPersistance().getSiteBySubDomain("domainname");
    Assert.assertNotNull(site);
    Assert.assertNotNull(new UserRightManager(user).toSite(site).getSiteAccessType());
    Assert.assertEquals(
        settings.getAccessLevel(), new UserRightManager(user).toSite(site).getSiteAccessType());
    Assert.assertEquals("domainname", site.getSubDomain());
    Assert.assertEquals("http://domainname.web-deva.com", action.getUrl());
    Assert.assertNotNull(action.getTellFriendHtml());
    Assert.assertEquals(2, site.getPages().size());

    Assert.assertEquals("siteName", site.getTitle());
    Assert.assertEquals(blueprint, site.getBlueprintParent());

    Assert.assertEquals("TemplateDirectory", site.getThemeId().getTemplateDirectory());
    Assert.assertEquals("ThemeCss", site.getThemeId().getThemeCss());
  }