@Test
  public void testFriendlyURLCollision() throws Exception {
    String defaultLanguageId = LocaleUtil.toLanguageId(LocaleUtil.getDefault());

    Layout layoutA = LayoutTestUtil.addLayout(group.getGroupId(), "layoutA");

    layoutA = LayoutLocalServiceUtil.updateFriendlyURL(layoutA.getPlid(), "/layoutA-de", "de");

    Layout layoutB = LayoutTestUtil.addLayout(group.getGroupId(), "layoutB");

    layoutB = LayoutLocalServiceUtil.updateFriendlyURL(layoutB.getPlid(), "/layoutB-de", "de");

    long[] layoutIds = {layoutA.getLayoutId(), layoutB.getLayoutId()};

    exportImportLayouts(layoutIds, getImportParameterMap());

    layoutA =
        LayoutLocalServiceUtil.updateFriendlyURL(layoutA.getPlid(), "/temp", defaultLanguageId);

    layoutA = LayoutLocalServiceUtil.updateFriendlyURL(layoutA.getPlid(), "/temp-de", "de");

    layoutB =
        LayoutLocalServiceUtil.updateFriendlyURL(layoutB.getPlid(), "/layoutA", defaultLanguageId);

    LayoutLocalServiceUtil.updateFriendlyURL(layoutB.getPlid(), "/layoutA-de", "de");

    layoutA =
        LayoutLocalServiceUtil.updateFriendlyURL(layoutA.getPlid(), "/layoutB", defaultLanguageId);

    LayoutLocalServiceUtil.updateFriendlyURL(layoutA.getPlid(), "/layoutB-de", "de");

    exportImportLayouts(layoutIds, getImportParameterMap());
  }
Ejemplo n.º 2
0
  protected Group addScopeGroup() throws Exception {
    Group group = GroupTestUtil.addGroup();

    Layout layout = LayoutTestUtil.addLayout(group.getGroupId(), ServiceTestUtil.randomString());

    String name = ServiceTestUtil.randomString();

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext(group.getGroupId());

    Group scopeGroup =
        GroupLocalServiceUtil.addGroup(
            TestPropsValues.getUserId(),
            group.getParentGroupId(),
            Layout.class.getName(),
            layout.getPlid(),
            GroupConstants.DEFAULT_LIVE_GROUP_ID,
            name,
            ServiceTestUtil.randomString(),
            GroupConstants.TYPE_SITE_OPEN,
            true,
            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,
            StringPool.SLASH + FriendlyURLNormalizerUtil.normalize(name),
            false,
            true,
            serviceContext);

    return scopeGroup;
  }
  protected void testAvailableLocales(
      Locale[] sourceAvailableLocales, Locale[] targetAvailableLocales, boolean expectFailure)
      throws Exception {

    group = GroupTestUtil.updateDisplaySettings(group.getGroupId(), sourceAvailableLocales, null);
    importedGroup =
        GroupTestUtil.updateDisplaySettings(
            importedGroup.getGroupId(), targetAvailableLocales, null);

    LayoutTestUtil.addLayout(group.getGroupId(), ServiceTestUtil.randomString());

    long[] layoutIds = new long[0];

    try {
      exportImportLayouts(layoutIds, getImportParameterMap());

      if (expectFailure) {
        Assert.fail();
      }
    } catch (LocaleException le) {
      if (!expectFailure) {
        Assert.fail();
      }
    }
  }
  @Test
  public void testExportImportLayouts() throws Exception {
    LayoutTestUtil.addLayout(group.getGroupId(), ServiceTestUtil.randomString());

    long[] layoutIds = new long[0];

    exportImportLayouts(layoutIds, getImportParameterMap());

    Assert.assertEquals(
        LayoutLocalServiceUtil.getLayoutsCount(group, false),
        LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));
  }
  @Test
  public void testDeleteMissingLayouts() throws Exception {
    Layout layout1 = LayoutTestUtil.addLayout(group.getGroupId(), ServiceTestUtil.randomString());
    Layout layout2 = LayoutTestUtil.addLayout(group.getGroupId(), ServiceTestUtil.randomString());

    exportImportLayouts(null, getImportParameterMap());

    Assert.assertEquals(
        LayoutLocalServiceUtil.getLayoutsCount(group, false),
        LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));

    LayoutTestUtil.addLayout(importedGroup.getGroupId(), ServiceTestUtil.randomString());

    Map<String, String[]> parameterMap = getImportParameterMap();

    parameterMap.put(
        PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS, new String[] {Boolean.TRUE.toString()});

    long[] layoutIds = new long[] {layout1.getLayoutId()};

    exportImportLayouts(layoutIds, getImportParameterMap());

    Assert.assertEquals(
        LayoutLocalServiceUtil.getLayoutsCount(group, false),
        LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));

    Layout importedLayout1 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout1.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertNotNull(importedLayout1);

    Layout importedLayout2 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout2.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertNotNull(importedLayout2);
  }
  @Test
  public void testExportImportSelectedLayouts() throws Exception {
    Layout layout = LayoutTestUtil.addLayout(group.getGroupId(), ServiceTestUtil.randomString());

    long[] layoutIds = new long[] {layout.getLayoutId()};

    exportImportLayouts(layoutIds, getImportParameterMap());

    Assert.assertEquals(
        layoutIds.length, LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));

    importedLayout =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertNotNull(importedLayout);
  }
  @Override
  public void setUp() throws Exception {
    super.setUp();

    layout = LayoutTestUtil.addLayout(stagingGroup.getGroupId(), ServiceTestUtil.randomString());

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setUuid(layout.getUuid());

    LayoutLocalServiceUtil.addLayout(
        TestPropsValues.getUserId(),
        liveGroup.getGroupId(),
        layout.getPrivateLayout(),
        layout.getParentLayoutId(),
        layout.getName(),
        layout.getTitle(),
        layout.getDescription(),
        layout.getType(),
        layout.getHidden(),
        layout.getFriendlyURL(),
        serviceContext);
  }
  @Before
  public void setUp() throws Exception {

    // Create site template

    FinderCacheUtil.clearCache();

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

    _layoutSetPrototypeGroup = layoutSetPrototype.getGroup();

    _layoutSetPrototypeLayout =
        LayoutTestUtil.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 = GroupTestUtil.addGroup();

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

    propagateChanges(_group);
  }
  @Before
  public void setUp() throws Exception {
    FinderCacheUtil.clearCache();

    _liveGroup = GroupTestUtil.addGroup();
    _stagingGroup = GroupTestUtil.addGroup();

    _fileEntry =
        DLAppTestUtil.addFileEntry(
            _stagingGroup.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            ServiceTestUtil.randomString() + ".txt",
            ServiceTestUtil.randomString(),
            true);

    LiferayFileEntry liferayFileEntry = (LiferayFileEntry) _fileEntry;

    DLFileEntry dlFileEntry = liferayFileEntry.getDLFileEntry();

    dlFileEntry.setLargeImageId(dlFileEntry.getFileEntryId());

    DLFileEntryLocalServiceUtil.updateDLFileEntry(dlFileEntry);

    TestReaderWriter testReaderWriter = new TestReaderWriter();

    _portletDataContextExport =
        PortletDataContextFactoryUtil.createExportPortletDataContext(
            _stagingGroup.getCompanyId(),
            _stagingGroup.getGroupId(),
            new HashMap<String, String[]>(),
            new Date(System.currentTimeMillis() - Time.HOUR),
            new Date(),
            testReaderWriter);

    Element rootElement = SAXReaderUtil.createElement("root");

    _portletDataContextExport.setExportDataRootElement(rootElement);

    _stagingPrivateLayout =
        LayoutTestUtil.addLayout(_stagingGroup.getGroupId(), ServiceTestUtil.randomString(), true);
    _stagingPublicLayout =
        LayoutTestUtil.addLayout(_stagingGroup.getGroupId(), ServiceTestUtil.randomString(), false);

    _portletDataContextExport.setPlid(_stagingPublicLayout.getPlid());

    _portletDataContextImport =
        PortletDataContextFactoryUtil.createImportPortletDataContext(
            _stagingGroup.getCompanyId(),
            _stagingGroup.getGroupId(),
            new HashMap<String, String[]>(),
            new CurrentUserIdStrategy(TestPropsValues.getUser()),
            testReaderWriter);

    _portletDataContextImport.setImportDataRootElement(rootElement);

    _livePublicLayout =
        LayoutTestUtil.addLayout(_liveGroup.getGroupId(), ServiceTestUtil.randomString(), false);

    _portletDataContextImport.setPlid(_livePublicLayout.getPlid());

    _portletDataContextImport.setSourceGroupId(_stagingGroup.getGroupId());

    rootElement.addElement("entry");

    _referrerStagedModel =
        JournalTestUtil.addArticle(
            _stagingGroup.getGroupId(),
            ServiceTestUtil.randomString(),
            ServiceTestUtil.randomString());
  }