@Before
  public void setUp() throws Exception {
    _group = ServiceTestUtil.addGroup();

    String name = "Test Folder";
    String description = "This is a test folder.";

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setScopeGroupId(_group.getGroupId());

    try {
      DLAppServiceHttp.deleteFolder(
          TestPropsValues.getHttpPrincipal(),
          _group.getGroupId(),
          DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
          name);
    } catch (Exception e) {
    }

    _folder =
        DLAppServiceHttp.addFolder(
            TestPropsValues.getHttpPrincipal(),
            _group.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            name,
            description,
            serviceContext);
  }
  protected void trashFileEntry() throws Exception {
    Group group = ServiceTestUtil.addGroup();

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext();

    serviceContext.setScopeGroupId(group.getGroupId());

    BaseModel<?> parentBaseModel = getParentBaseModel(group, serviceContext);

    int initialBaseModelsCount = getBaseModelsNotInTrashCount(parentBaseModel);
    int initialTrashEntriesCount = getTrashEntriesCount(group.getGroupId());

    BaseModel<?> baseModel = addBaseModel(parentBaseModel, true, serviceContext);

    DLFileShortcut dlFileShortcut = (DLFileShortcut) baseModel;

    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId());

    Assert.assertEquals(initialBaseModelsCount + 1, getBaseModelsNotInTrashCount(parentBaseModel));
    Assert.assertEquals(initialTrashEntriesCount, getTrashEntriesCount(group.getGroupId()));

    DLAppServiceUtil.moveFileEntryToTrash(fileEntry.getFileEntryId());

    Assert.assertEquals(initialBaseModelsCount, getBaseModelsNotInTrashCount(parentBaseModel));
    Assert.assertEquals(initialTrashEntriesCount + 1, getTrashEntriesCount(group.getGroupId()));

    DLAppServiceUtil.restoreFileEntryFromTrash(fileEntry.getFileEntryId());

    Assert.assertEquals(initialBaseModelsCount + 1, getBaseModelsNotInTrashCount(parentBaseModel));
  }
  @Before
  public void setUp() throws Exception {

    // Create site template

    FinderCacheUtil.clearCache();

    LayoutSetPrototype layoutSetPrototype =
        ServiceTestUtil.addLayoutSetPrototype(ServiceTestUtil.randomString());

    _layoutSetPrototypeGroup = layoutSetPrototype.getGroup();

    _layoutSetPrototypeLayout =
        ServiceTestUtil.addLayout(
            _layoutSetPrototypeGroup.getGroupId(), ServiceTestUtil.randomString(), true);

    updateLayoutTemplateId(_layoutSetPrototypeLayout, "1_column");

    _layoutSetPrototypeJournalArticle =
        addJournalArticle(_layoutSetPrototypeGroup.getGroupId(), 0, "Test Article", "Test Content");

    _layoutSetPrototypeJournalContentPortletId =
        addJournalContentPortletToLayout(
            TestPropsValues.getUserId(),
            _layoutSetPrototypeLayout,
            _layoutSetPrototypeJournalArticle,
            "column-1");

    // Create site from site template

    _group = ServiceTestUtil.addGroup(ServiceTestUtil.randomString());

    SitesUtil.updateLayoutSetPrototypesLinks(
        _group, layoutSetPrototype.getLayoutSetPrototypeId(), 0, true, true);

    propagateChanges(_group);
  }
Пример #4
0
  @Before
  public void setUp() throws Exception {
    FinderCacheUtil.clearCache();

    group = ServiceTestUtil.addGroup();
  }
  protected void runLayoutSetPrototype(
      boolean layoutSetLinkEnabled,
      boolean layoutLinkEnabled,
      boolean addPage,
      boolean deletePage,
      boolean useLayoutPrototype)
      throws Exception {

    LayoutSetPrototype layoutSetPrototype =
        ServiceTestUtil.addLayoutSetPrototype(ServiceTestUtil.randomString());

    Group layoutSetPrototypeGroup = layoutSetPrototype.getGroup();

    int layoutSetPrototypeLayoutsCount =
        LayoutLocalServiceUtil.getLayoutsCount(layoutSetPrototypeGroup, true);

    ServiceTestUtil.addLayout(
        layoutSetPrototypeGroup.getGroupId(), ServiceTestUtil.randomString(), true);
    ServiceTestUtil.addLayout(
        layoutSetPrototypeGroup.getGroupId(), ServiceTestUtil.randomString(), true);

    Group group = ServiceTestUtil.addGroup();

    SitesUtil.updateLayoutSetPrototypesLinks(
        group, layoutSetPrototype.getLayoutSetPrototypeId(), 0, layoutSetLinkEnabled, false);

    propagateChanges(group);

    int groupLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(group, false);

    Assert.assertEquals(groupLayoutsCount, layoutSetPrototypeLayoutsCount + 2);

    if (addPage) {
      Layout layout = null;

      if (useLayoutPrototype) {
        LayoutPrototype layoutPrototype =
            ServiceTestUtil.addLayoutPrototype(ServiceTestUtil.randomString());

        Layout layoutPrototypeLayout = layoutPrototype.getLayout();

        updateLayoutTemplateId(layoutPrototypeLayout, "2_2_columns");

        layout =
            addLayout(
                group.getGroupId(),
                ServiceTestUtil.randomString(),
                layoutPrototype,
                layoutLinkEnabled);

        if (layoutLinkEnabled) {
          layout = propagateChanges(layout);
        }

        updateLayoutTemplateId(layoutPrototypeLayout, "1_column");

        if (layoutLinkEnabled) {
          Assert.assertEquals(
              "2_2_columns",
              layout.getTypeSettingsProperty(LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID));

          layout = propagateChanges(layout);
        }
      } else {

        // Database will store Date values without milliseconds. Wait
        // for more than one second to ensure that later queries can
        // correctly compare the Date values.

        Thread.sleep(2000);

        layout =
            ServiceTestUtil.addLayout(
                layoutSetPrototypeGroup.getGroupId(), ServiceTestUtil.randomString(), true);
      }

      if (!useLayoutPrototype) {
        groupLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(group, false);

        Assert.assertEquals(groupLayoutsCount, layoutSetPrototypeLayoutsCount + 2);
      }

      propagateChanges(group);

      groupLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(group, false);

      if (layoutSetLinkEnabled) {
        Assert.assertEquals(groupLayoutsCount, layoutSetPrototypeLayoutsCount + 3);

        if (useLayoutPrototype) {
          if (layoutLinkEnabled) {
            Assert.assertEquals(
                "1_column",
                layout.getTypeSettingsProperty(LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID));
          } else {
            Assert.assertEquals(
                "2_2_columns",
                layout.getTypeSettingsProperty(LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID));
          }
        }
      }

      if (deletePage) {
        LayoutLocalServiceUtil.deleteLayout(layout, true, ServiceTestUtil.getServiceContext());

        groupLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(group, false);

        if (layoutSetLinkEnabled) {
          if (!useLayoutPrototype) {
            Assert.assertEquals(groupLayoutsCount, layoutSetPrototypeLayoutsCount + 3);

            propagateChanges(group);
          }

          groupLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(group, false);
        }

        Assert.assertEquals(groupLayoutsCount, layoutSetPrototypeLayoutsCount + 2);
      }
    }
  }
Пример #6
0
  protected void enableLocalStaging(boolean stageJournal, boolean stagePolls) throws Exception {

    Group group = ServiceTestUtil.addGroup();

    ServiceTestUtil.addLayout(group.getGroupId(), "Page1");
    ServiceTestUtil.addLayout(group.getGroupId(), "Page2");

    int initialPagesCount = LayoutLocalServiceUtil.getLayoutsCount(group, false);

    // Create content

    JournalArticle journalArticle = addJournalArticle(group.getGroupId(), "Title", "content");

    PollsQuestion pollsQuestion = addPollsQuestion(group.getGroupId(), "Question", "Description");

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setScopeGroupId(group.getGroupId());

    Map<String, String[]> parameters = StagingUtil.getStagingParameters();

    parameters.put(PortletDataHandlerKeys.PORTLET_DATA_ALL, new String[] {String.valueOf(false)});

    parameters.put(
        PortletDataHandlerKeys.PORTLET_DATA + "_" + PortletKeys.JOURNAL,
        new String[] {String.valueOf(stageJournal)});

    parameters.put(
        PortletDataHandlerKeys.PORTLET_DATA + "_" + PortletKeys.POLLS,
        new String[] {String.valueOf(stagePolls)});

    for (String parameterName : parameters.keySet()) {
      serviceContext.setAttribute(parameterName, parameters.get(parameterName)[0]);
    }

    serviceContext.setAttribute(
        StagingConstants.STAGED_PORTLET + PortletKeys.JOURNAL, stageJournal);

    serviceContext.setAttribute(StagingConstants.STAGED_PORTLET + PortletKeys.POLLS, stagePolls);

    // Enable staging

    StagingUtil.enableLocalStaging(
        TestPropsValues.getUserId(), group, group, false, false, serviceContext);

    Group stagingGroup = group.getStagingGroup();

    Assert.assertNotNull(stagingGroup);

    Assert.assertEquals(
        LayoutLocalServiceUtil.getLayoutsCount(stagingGroup, false), initialPagesCount);

    // Update content in staging

    JournalArticle stagingJournalArticle =
        JournalArticleLocalServiceUtil.getArticleByUrlTitle(
            stagingGroup.getGroupId(), journalArticle.getUrlTitle());

    stagingJournalArticle =
        updateJournalArticle(stagingJournalArticle, "Title2", stagingJournalArticle.getContent());

    PollsQuestion stagingQuestion =
        PollsQuestionLocalServiceUtil.getPollsQuestionByUuidAndGroupId(
            pollsQuestion.getUuid(), stagingGroup.getGroupId());

    stagingQuestion = updatePollsQuestion(stagingQuestion, "Question2", "Description2");

    // Publish to live

    StagingUtil.publishLayouts(
        TestPropsValues.getUserId(),
        stagingGroup.getGroupId(),
        group.getGroupId(),
        false,
        parameters,
        null,
        null);

    // Retrieve content from live after publishing

    journalArticle = JournalArticleLocalServiceUtil.getArticle(journalArticle.getId());
    pollsQuestion = PollsQuestionLocalServiceUtil.getQuestion(pollsQuestion.getQuestionId());

    if (stagePolls) {
      for (Locale locale : _locales) {
        Assert.assertEquals(pollsQuestion.getTitle(locale), stagingQuestion.getTitle(locale));
      }
    } else {
      for (Locale locale : _locales) {
        Assert.assertFalse(pollsQuestion.getTitle(locale).equals(stagingQuestion.getTitle(locale)));
      }
    }

    if (stageJournal) {
      for (Locale locale : _locales) {
        Assert.assertEquals(
            journalArticle.getTitle(locale), stagingJournalArticle.getTitle(locale));
      }
    } else {
      for (Locale locale : _locales) {
        Assert.assertFalse(
            journalArticle.getTitle(locale).equals(stagingJournalArticle.getTitle(locale)));
      }
    }
  }