@Test
  public void testExecute_WithSecondState() throws Exception {
    User user = TestUtil.createUser();
    user.setActiveted(null);
    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");
    action.setSettingsId(settings.getChildSiteSettingsId());
    action.setConfirmCode("confirm");

    DraftChildSiteRegistration childSiteRegistration =
        TestUtil.createChildSiteRegistration("name", "comment");
    childSiteRegistration.setBlueprintsId(Arrays.asList(1, 2));
    settings.setRequiredToUseSiteBlueprint(true);
    settings.setSitePaymentSettings(new SitePaymentSettings());
    settings.setChildSiteRegistration(childSiteRegistration);

    Assert.assertNull(user.getActiveted());
    Assert.assertNull(new UsersManager().getLoginedUser());

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

    Assert.assertNotNull(user.getActiveted());
    Assert.assertNotNull(new UsersManager().getLoginedUser());
    Assert.assertEquals(user, new UsersManager().getLoginedUser());
    Assert.assertNull(action.getTellFriendHtml());
  }
  @Test
  public void getForumThreadsByUserIdWithNotFound() {
    final User user = new User();
    user.setEmail("a");
    user.setRegistrationDate(new Date());
    persistance.putUser(user);

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

    SubForum subForum = new SubForum();
    subForum.setSubForumName("ffff");
    subForum.setSubForumDescription("ffff1");
    forum.addSubForum(subForum);
    persistance.putSubForum(subForum);

    ForumThread forumThread1 = new ForumThread();
    forumThread1.setThreadName("f");
    forumThread1.setThreadDescription("f2");
    forumThread1.setUpdateDate(new Date());
    forumThread1.setAuthor(user);
    subForum.addForumThread(forumThread1);
    persistance.putForumThread(forumThread1);

    List<ForumThread> forumThreads = persistance.getForumThreadsByUserId(user.getUserId() + 90);
    Assert.assertEquals(0, forumThreads.size());
  }
  @Test
  public void getForumPostsByUserIdWithOther() {
    final User user = new User();
    user.setEmail("a");
    user.setRegistrationDate(new Date());
    persistance.putUser(user);

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

    SubForum subForum = new SubForum();
    subForum.setSubForumName("ffff");
    subForum.setSubForumDescription("ffff1");
    forum.addSubForum(subForum);
    persistance.putSubForum(subForum);

    ForumThread forumThread = new ForumThread();
    forumThread.setThreadName("f");
    forumThread.setThreadDescription("f2");
    forumThread.setUpdateDate(new Date());
    subForum.addForumThread(forumThread);
    persistance.putForumThread(forumThread);

    ForumPost forumPost = new ForumPost();
    forumPost.setText("bbb");
    forumPost.setAuthor(user);
    forumPost.setDateCreated(new Date(System.currentTimeMillis() * 2));
    forumThread.addForumPost(forumPost);
    persistance.putForumPost(forumPost);

    List<ForumPost> forumPosts = persistance.getForumPostsByUserId(user.getUserId() + 9);
    Assert.assertEquals(0, forumPosts.size());
  }
  @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 getForumsByUserIdForEmpty() {
    User user = new User();
    user.setPassword("1");
    user.setEmail("a");
    user.setRegistrationDate(new Date());
    persistance.putUser(user);

    List<DraftItem> userForums =
        persistance.getDraftItemsByUserId(user.getUserId(), ItemType.FORUM);
    Assert.assertEquals(0, userForums.size());
  }
예제 #6
0
  @SynchronizeByMethodParameter(entityClass = BlogPost.class, method = SynchronizeMethod.WRITE)
  @RemoteMethod
  public void execute(final int blogPostId) {
    final User user = new UsersManager().getLoginedUser();
    final Integer loginedUserId = user != null ? user.getUserId() : null;
    final BlogPost blogPost = BlogRight.getBlogPostOnEdit(loginedUserId, blogPostId);
    persistanceTransaction.execute(
        new Runnable() {

          public void run() {
            persistance.removeBlogPost(blogPost);
          }
        });
  }
 @Test
 public void testExecute_WithExpiredSettings() throws Exception {
   User user = TestUtil.createUser();
   user.setActiveted(null);
   Site parentSite = TestUtil.createSite();
   DraftChildSiteRegistration registration = TestUtil.createChildSiteRegistration(parentSite);
   ChildSiteSettings settings = TestUtil.createChildSiteSettings(registration, parentSite);
   settings.setCreatedDate(
       new Date((System.currentTimeMillis() - TimeInterval.TEN_DAYS.getMillis() * 2) + 1));
   settings.setUserId(user.getUserId());
   settings.setConfirmCode("confirm");
   action.setSettingsId(settings.getChildSiteSettingsId());
   action.setConfirmCode("confirm");
   ForwardResolution resolutionMock = (ForwardResolution) action.show();
   Assert.assertEquals(
       "/account/registration/registrationLinkExpired.jsp", resolutionMock.getPath());
 }
 @Test
 public void testExecute_WithActiveUser_secondState() throws Exception {
   final Date activationDate = new Date();
   User user = TestUtil.createUser();
   user.setActiveted(activationDate);
   Site parentSite = TestUtil.createSite();
   DraftChildSiteRegistration registration = TestUtil.createChildSiteRegistration(parentSite);
   ChildSiteSettings settings = TestUtil.createChildSiteSettings(registration, parentSite);
   settings.setUserId(user.getUserId());
   settings.setConfirmCode("confirm");
   settings.setCreatedDate(new Date());
   settings.setAccessLevel(SiteAccessLevel.ADMINISTRATOR);
   action.setSettingsId(settings.getChildSiteSettingsId());
   action.setConfirmCode("confirm");
   ForwardResolution resolutionMock = (ForwardResolution) action.show();
   Assert.assertNotNull(new UsersManager().getLoginedUser());
   Assert.assertEquals(user, new UsersManager().getLoginedUser());
   Assert.assertEquals(
       "/account/registration/childSiteRigistrationConfirmationSecondState.jsp",
       resolutionMock.getPath());
 }
  @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 testExecute_WithActiveUserAndCreatedChildSite() throws Exception {
   final Date activationDate = new Date();
   User user = TestUtil.createUser();
   user.setActiveted(activationDate);
   Site parentSite = TestUtil.createSite();
   DraftChildSiteRegistration registration = TestUtil.createChildSiteRegistration(parentSite);
   ChildSiteSettings settings = TestUtil.createChildSiteSettings(registration, parentSite);
   Site childSite = TestUtil.createSite();
   settings.setSite(childSite);
   settings.setUserId(user.getUserId());
   settings.setConfirmCode("confirm");
   settings.setCreatedDate(new Date());
   settings.setAccessLevel(SiteAccessLevel.ADMINISTRATOR);
   action.setSettingsId(settings.getChildSiteSettingsId());
   action.setConfirmCode("confirm");
   ResolutionMock resolutionMock = (ResolutionMock) action.show();
   Assert.assertEquals(SiteEditPageAction.class, resolutionMock.getRedirectByAction());
   Assert.assertEquals("siteId", resolutionMock.getRedirectByActionParameters()[0].getName());
   Assert.assertEquals(
       childSite.getSiteId(), resolutionMock.getRedirectByActionParameters()[0].getValue());
 }
  @Test
  public void getLastSubForumPost() {
    User account = new User();
    account.setEmail("a");
    account.setRegistrationDate(new Date());
    persistance.putUser(account);

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

    SubForum subForum = new SubForum();
    subForum.setSubForumName("ffff");
    subForum.setSubForumDescription("ffff1");
    forum.addSubForum(subForum);
    persistance.putSubForum(subForum);

    ForumThread forumThread1 = new ForumThread();
    forumThread1.setThreadName("f");
    forumThread1.setThreadDescription("f2");
    forumThread1.setUpdateDate(new Date());
    subForum.addForumThread(forumThread1);
    persistance.putForumThread(forumThread1);

    ForumPost forumPost1 = new ForumPost();
    forumPost1.setText("bbb");
    forumPost1.setDateCreated(new Date(System.currentTimeMillis() * 2));
    forumThread1.addForumPost(forumPost1);
    persistance.putForumPost(forumPost1);

    ForumPost forumPost2 = new ForumPost();
    forumPost2.setText("bbb");
    forumPost2.setDateCreated(new Date());
    forumThread1.addForumPost(forumPost2);
    persistance.putForumPost(forumPost2);

    ForumPost lastForumPost = persistance.getLastSubForumPost(subForum.getSubForumId());
    Assert.assertEquals(lastForumPost, forumPost1);
  }
  @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_WithFirstState() throws Exception {
    ServiceLocator.getConfigStorage().get().setUserSitesUrl("web-deva.com");
    User user = TestUtil.createUser();
    user.setActiveted(null);
    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");
    Site blueprint = TestUtil.createBlueprint();
    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.assertNull(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.assertNotNull(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());
  }