protected Website addWebsite() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Website website = _persistence.create(pk);

    website.setMvccVersion(RandomTestUtil.nextLong());

    website.setUuid(RandomTestUtil.randomString());

    website.setCompanyId(RandomTestUtil.nextLong());

    website.setUserId(RandomTestUtil.nextLong());

    website.setUserName(RandomTestUtil.randomString());

    website.setCreateDate(RandomTestUtil.nextDate());

    website.setModifiedDate(RandomTestUtil.nextDate());

    website.setClassNameId(RandomTestUtil.nextLong());

    website.setClassPK(RandomTestUtil.nextLong());

    website.setUrl(RandomTestUtil.randomString());

    website.setTypeId(RandomTestUtil.nextLong());

    website.setPrimary(RandomTestUtil.randomBoolean());

    website.setLastPublishDate(RandomTestUtil.nextDate());

    _websites.add(_persistence.update(website));

    return website;
  }
  protected MBDiscussion addMBDiscussion() throws Exception {
    long pk = RandomTestUtil.nextLong();

    MBDiscussion mbDiscussion = _persistence.create(pk);

    mbDiscussion.setUuid(RandomTestUtil.randomString());

    mbDiscussion.setGroupId(RandomTestUtil.nextLong());

    mbDiscussion.setCompanyId(RandomTestUtil.nextLong());

    mbDiscussion.setUserId(RandomTestUtil.nextLong());

    mbDiscussion.setUserName(RandomTestUtil.randomString());

    mbDiscussion.setCreateDate(RandomTestUtil.nextDate());

    mbDiscussion.setModifiedDate(RandomTestUtil.nextDate());

    mbDiscussion.setClassNameId(RandomTestUtil.nextLong());

    mbDiscussion.setClassPK(RandomTestUtil.nextLong());

    mbDiscussion.setThreadId(RandomTestUtil.nextLong());

    mbDiscussion.setLastPublishDate(RandomTestUtil.nextDate());

    _mbDiscussions.add(_persistence.update(mbDiscussion));

    return mbDiscussion;
  }
  @Test
  public void testGetKBFoldersAndKBArticlesReturnKBFolderImmediateChildren() throws Exception {

    KBArticle parentKBArticle =
        addKBArticle(_kbFolder.getKbFolderId(), RandomTestUtil.randomString());

    addChildKBArticle(parentKBArticle, RandomTestUtil.randomString());

    KBFolder kbFolder = addKBFolder(_kbFolder.getKbFolderId());

    List<Object> kbFolderAndKBArticles =
        KBFolderLocalServiceUtil.getKBFoldersAndKBArticles(
            _group.getGroupId(),
            _kbFolder.getKbFolderId(),
            WorkflowConstants.STATUS_APPROVED,
            QueryUtil.ALL_POS,
            QueryUtil.ALL_POS,
            new KBObjectsTitleComparator<KBArticle>(true, true));

    KBFolder currentKBFolder = (KBFolder) kbFolderAndKBArticles.get(0);
    KBArticle currentKBArticle1 = (KBArticle) kbFolderAndKBArticles.get(1);

    Assert.assertEquals(kbFolder.getKbFolderId(), currentKBFolder.getKbFolderId());
    Assert.assertEquals(parentKBArticle.getKbArticleId(), currentKBArticle1.getKbArticleId());
    Assert.assertEquals(2, kbFolderAndKBArticles.size());
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    ServiceComponent newServiceComponent = _persistence.create(pk);

    newServiceComponent.setMvccVersion(RandomTestUtil.nextLong());

    newServiceComponent.setBuildNamespace(RandomTestUtil.randomString());

    newServiceComponent.setBuildNumber(RandomTestUtil.nextLong());

    newServiceComponent.setBuildDate(RandomTestUtil.nextLong());

    newServiceComponent.setData(RandomTestUtil.randomString());

    _serviceComponents.add(_persistence.update(newServiceComponent));

    ServiceComponent existingServiceComponent =
        _persistence.findByPrimaryKey(newServiceComponent.getPrimaryKey());

    Assert.assertEquals(
        existingServiceComponent.getMvccVersion(), newServiceComponent.getMvccVersion());
    Assert.assertEquals(
        existingServiceComponent.getServiceComponentId(),
        newServiceComponent.getServiceComponentId());
    Assert.assertEquals(
        existingServiceComponent.getBuildNamespace(), newServiceComponent.getBuildNamespace());
    Assert.assertEquals(
        existingServiceComponent.getBuildNumber(), newServiceComponent.getBuildNumber());
    Assert.assertEquals(
        existingServiceComponent.getBuildDate(), newServiceComponent.getBuildDate());
    Assert.assertEquals(existingServiceComponent.getData(), newServiceComponent.getData());
  }
  protected Country addCountry() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Country country = _persistence.create(pk);

    country.setMvccVersion(RandomTestUtil.nextLong());

    country.setName(RandomTestUtil.randomString());

    country.setA2(RandomTestUtil.randomString());

    country.setA3(RandomTestUtil.randomString());

    country.setNumber(RandomTestUtil.randomString());

    country.setIdd(RandomTestUtil.randomString());

    country.setZipRequired(RandomTestUtil.randomBoolean());

    country.setActive(RandomTestUtil.randomBoolean());

    _countries.add(_persistence.update(country));

    return country;
  }
  protected RatingsEntry addRatingsEntry() throws Exception {
    long pk = RandomTestUtil.nextLong();

    RatingsEntry ratingsEntry = _persistence.create(pk);

    ratingsEntry.setUuid(RandomTestUtil.randomString());

    ratingsEntry.setCompanyId(RandomTestUtil.nextLong());

    ratingsEntry.setUserId(RandomTestUtil.nextLong());

    ratingsEntry.setUserName(RandomTestUtil.randomString());

    ratingsEntry.setCreateDate(RandomTestUtil.nextDate());

    ratingsEntry.setModifiedDate(RandomTestUtil.nextDate());

    ratingsEntry.setClassNameId(RandomTestUtil.nextLong());

    ratingsEntry.setClassPK(RandomTestUtil.nextLong());

    ratingsEntry.setScore(RandomTestUtil.nextDouble());

    ratingsEntry.setLastPublishDate(RandomTestUtil.nextDate());

    _ratingsEntries.add(_persistence.update(ratingsEntry));

    return ratingsEntry;
  }
  protected MeetupsRegistration addMeetupsRegistration() throws Exception {
    long pk = RandomTestUtil.nextLong();

    MeetupsRegistration meetupsRegistration = _persistence.create(pk);

    meetupsRegistration.setCompanyId(RandomTestUtil.nextLong());

    meetupsRegistration.setUserId(RandomTestUtil.nextLong());

    meetupsRegistration.setUserName(RandomTestUtil.randomString());

    meetupsRegistration.setCreateDate(RandomTestUtil.nextDate());

    meetupsRegistration.setModifiedDate(RandomTestUtil.nextDate());

    meetupsRegistration.setMeetupsEntryId(RandomTestUtil.nextLong());

    meetupsRegistration.setStatus(RandomTestUtil.nextInt());

    meetupsRegistration.setComments(RandomTestUtil.randomString());

    _meetupsRegistrations.add(_persistence.update(meetupsRegistration));

    return meetupsRegistration;
  }
  @Test
  public void testGetKBFoldersAndKBArticlesWithMultipleKBArticleVersions() throws Exception {

    KBArticle kbArticle =
        addKBArticle(KBFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString());

    KBArticle newKBArticle = updateKBArticle(kbArticle, RandomTestUtil.randomString());

    List<Object> kbFolderAndKBArticles =
        KBFolderLocalServiceUtil.getKBFoldersAndKBArticles(
            _group.getGroupId(),
            KBFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            WorkflowConstants.STATUS_ANY,
            QueryUtil.ALL_POS,
            QueryUtil.ALL_POS,
            new KBObjectsTitleComparator<>(false, true));

    KBFolder currentKBFolder = (KBFolder) kbFolderAndKBArticles.get(0);
    KBArticle currentKBArticle1 = (KBArticle) kbFolderAndKBArticles.get(1);

    Assert.assertEquals(2, kbFolderAndKBArticles.size());

    Assert.assertEquals(_kbFolder.getKbFolderId(), currentKBFolder.getKbFolderId());
    Assert.assertEquals(newKBArticle.getKbArticleId(), currentKBArticle1.getKbArticleId());
  }
예제 #9
0
  public static DLFileEntry addDLFileEntry(long dlFolderId) throws Exception {
    DLFolder dlFolder = DLFolderLocalServiceUtil.fetchDLFolder(dlFolderId);

    byte[] bytes = RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE);

    InputStream is = new ByteArrayInputStream(bytes);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(dlFolder.getGroupId());

    return DLFileEntryLocalServiceUtil.addFileEntry(
        TestPropsValues.getUserId(),
        dlFolder.getGroupId(),
        dlFolder.getRepositoryId(),
        dlFolder.getFolderId(),
        RandomTestUtil.randomString(),
        ContentTypes.TEXT_PLAIN,
        RandomTestUtil.randomString(),
        StringPool.BLANK,
        StringPool.BLANK,
        DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT,
        null,
        null,
        is,
        bytes.length,
        serviceContext);
  }
  @Test
  public void testCopyFileEntryWithoutExtensionInRootFolderToFolder() throws Exception {

    DLFileEntry dlFileEntry = addDLFileEntry(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, false);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    DLFolder destFolder =
        DLFolderLocalServiceUtil.addFolder(
            TestPropsValues.getUserId(),
            _group.getGroupId(),
            _group.getGroupId(),
            false,
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            RandomTestUtil.randomString(),
            RandomTestUtil.randomString(),
            false,
            serviceContext);

    DLFileEntryServiceUtil.copyFileEntry(
        _group.getGroupId(),
        _group.getGroupId(),
        dlFileEntry.getFileEntryId(),
        destFolder.getFolderId(),
        serviceContext);
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Status newStatus = _persistence.create(pk);

    newStatus.setUserId(RandomTestUtil.nextLong());

    newStatus.setModifiedDate(RandomTestUtil.nextLong());

    newStatus.setOnline(RandomTestUtil.randomBoolean());

    newStatus.setAwake(RandomTestUtil.randomBoolean());

    newStatus.setActivePanelIds(RandomTestUtil.randomString());

    newStatus.setMessage(RandomTestUtil.randomString());

    newStatus.setPlaySound(RandomTestUtil.randomBoolean());

    _statuses.add(_persistence.update(newStatus));

    Status existingStatus = _persistence.findByPrimaryKey(newStatus.getPrimaryKey());

    Assert.assertEquals(existingStatus.getStatusId(), newStatus.getStatusId());
    Assert.assertEquals(existingStatus.getUserId(), newStatus.getUserId());
    Assert.assertEquals(existingStatus.getModifiedDate(), newStatus.getModifiedDate());
    Assert.assertEquals(existingStatus.getOnline(), newStatus.getOnline());
    Assert.assertEquals(existingStatus.getAwake(), newStatus.getAwake());
    Assert.assertEquals(existingStatus.getActivePanelIds(), newStatus.getActivePanelIds());
    Assert.assertEquals(existingStatus.getMessage(), newStatus.getMessage());
    Assert.assertEquals(existingStatus.getPlaySound(), newStatus.getPlaySound());
  }
  @Test
  public void testGetKBFoldersAndKBArticlesOrderedByDescendingPriority() throws Exception {

    KBArticle kbArticle1 =
        addKBArticle(KBFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString());
    KBArticle kbArticle2 =
        addKBArticle(KBFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString());
    KBArticle kbArticle3 =
        addKBArticle(KBFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString());

    KBArticleLocalServiceUtil.updatePriority(kbArticle2.getResourcePrimKey(), 10.0);

    List<Object> kbFolderAndKBArticles =
        KBFolderLocalServiceUtil.getKBFoldersAndKBArticles(
            _group.getGroupId(),
            KBFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            WorkflowConstants.STATUS_ANY,
            QueryUtil.ALL_POS,
            QueryUtil.ALL_POS,
            new KBObjectsPriorityComparator(false));

    KBFolder currentKBFolder = (KBFolder) kbFolderAndKBArticles.get(0);
    KBArticle currentKBArticle1 = (KBArticle) kbFolderAndKBArticles.get(3);
    KBArticle currentKBArticle2 = (KBArticle) kbFolderAndKBArticles.get(1);
    KBArticle currentKBArticle3 = (KBArticle) kbFolderAndKBArticles.get(2);

    Assert.assertEquals(_kbFolder.getKbFolderId(), currentKBFolder.getKbFolderId());
    Assert.assertEquals(kbArticle1.getKbArticleId(), currentKBArticle1.getKbArticleId());
    Assert.assertEquals(kbArticle2.getKbArticleId(), currentKBArticle2.getKbArticleId());
    Assert.assertEquals(kbArticle3.getKbArticleId(), currentKBArticle3.getKbArticleId());
  }
  protected DLFileEntry addDLFileEntry(long folderId, boolean appendExtension) throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    String sourceFileName = RandomTestUtil.randomString();

    if (appendExtension) {
      sourceFileName = sourceFileName.concat(".pdf");
    }

    String fileEntryTitle = RandomTestUtil.randomString();

    return DLFileEntryLocalServiceUtil.addFileEntry(
        TestPropsValues.getUserId(),
        _group.getGroupId(),
        _group.getGroupId(),
        folderId,
        sourceFileName,
        null,
        fileEntryTitle,
        RandomTestUtil.randomString(),
        StringPool.BLANK,
        DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT,
        null,
        null,
        new ByteArrayInputStream(_CONTENT.getBytes()),
        0,
        serviceContext);
  }
  @Test
  public void testTypeArticle() throws Exception {
    initExport();

    Map<String, List<StagedModel>> dependentStagedModelsMap = new HashMap<>();

    JournalArticle journalArticle =
        JournalTestUtil.addArticle(
            stagingGroup.getGroupId(),
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            RandomTestUtil.randomString(),
            RandomTestUtil.randomString());

    addDependentStagedModel(dependentStagedModelsMap, JournalArticle.class, journalArticle);

    Layout layout =
        LayoutTestUtil.addTypeArticleLayout(
            stagingGroup.getGroupId(), journalArticle.getArticleId());

    addDependentLayoutFriendlyURLs(dependentStagedModelsMap, layout);

    StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, layout);

    validateExport(portletDataContext, layout, dependentStagedModelsMap);

    initImport();

    Layout exportedLayout = (Layout) readExportedStagedModel(layout);

    StagedModelDataHandlerUtil.importStagedModel(portletDataContext, exportedLayout);
  }
  protected Team addTeam() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Team team = _persistence.create(pk);

    team.setMvccVersion(RandomTestUtil.nextLong());

    team.setUuid(RandomTestUtil.randomString());

    team.setCompanyId(RandomTestUtil.nextLong());

    team.setUserId(RandomTestUtil.nextLong());

    team.setUserName(RandomTestUtil.randomString());

    team.setCreateDate(RandomTestUtil.nextDate());

    team.setModifiedDate(RandomTestUtil.nextDate());

    team.setGroupId(RandomTestUtil.nextLong());

    team.setName(RandomTestUtil.randomString());

    team.setDescription(RandomTestUtil.randomString());

    team.setLastPublishDate(RandomTestUtil.nextDate());

    _teams.add(_persistence.update(team));

    return team;
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    SystemEvent newSystemEvent = _persistence.create(pk);

    newSystemEvent.setMvccVersion(RandomTestUtil.nextLong());

    newSystemEvent.setGroupId(RandomTestUtil.nextLong());

    newSystemEvent.setCompanyId(RandomTestUtil.nextLong());

    newSystemEvent.setUserId(RandomTestUtil.nextLong());

    newSystemEvent.setUserName(RandomTestUtil.randomString());

    newSystemEvent.setCreateDate(RandomTestUtil.nextDate());

    newSystemEvent.setClassNameId(RandomTestUtil.nextLong());

    newSystemEvent.setClassPK(RandomTestUtil.nextLong());

    newSystemEvent.setClassUuid(RandomTestUtil.randomString());

    newSystemEvent.setReferrerClassNameId(RandomTestUtil.nextLong());

    newSystemEvent.setParentSystemEventId(RandomTestUtil.nextLong());

    newSystemEvent.setSystemEventSetKey(RandomTestUtil.nextLong());

    newSystemEvent.setType(RandomTestUtil.nextInt());

    newSystemEvent.setExtraData(RandomTestUtil.randomString());

    _systemEvents.add(_persistence.update(newSystemEvent));

    SystemEvent existingSystemEvent = _persistence.findByPrimaryKey(newSystemEvent.getPrimaryKey());

    Assert.assertEquals(existingSystemEvent.getMvccVersion(), newSystemEvent.getMvccVersion());
    Assert.assertEquals(existingSystemEvent.getSystemEventId(), newSystemEvent.getSystemEventId());
    Assert.assertEquals(existingSystemEvent.getGroupId(), newSystemEvent.getGroupId());
    Assert.assertEquals(existingSystemEvent.getCompanyId(), newSystemEvent.getCompanyId());
    Assert.assertEquals(existingSystemEvent.getUserId(), newSystemEvent.getUserId());
    Assert.assertEquals(existingSystemEvent.getUserName(), newSystemEvent.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingSystemEvent.getCreateDate()),
        Time.getShortTimestamp(newSystemEvent.getCreateDate()));
    Assert.assertEquals(existingSystemEvent.getClassNameId(), newSystemEvent.getClassNameId());
    Assert.assertEquals(existingSystemEvent.getClassPK(), newSystemEvent.getClassPK());
    Assert.assertEquals(existingSystemEvent.getClassUuid(), newSystemEvent.getClassUuid());
    Assert.assertEquals(
        existingSystemEvent.getReferrerClassNameId(), newSystemEvent.getReferrerClassNameId());
    Assert.assertEquals(
        existingSystemEvent.getParentSystemEventId(), newSystemEvent.getParentSystemEventId());
    Assert.assertEquals(
        existingSystemEvent.getSystemEventSetKey(), newSystemEvent.getSystemEventSetKey());
    Assert.assertEquals(existingSystemEvent.getType(), newSystemEvent.getType());
    Assert.assertEquals(existingSystemEvent.getExtraData(), newSystemEvent.getExtraData());
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Website newWebsite = _persistence.create(pk);

    newWebsite.setMvccVersion(RandomTestUtil.nextLong());

    newWebsite.setUuid(RandomTestUtil.randomString());

    newWebsite.setCompanyId(RandomTestUtil.nextLong());

    newWebsite.setUserId(RandomTestUtil.nextLong());

    newWebsite.setUserName(RandomTestUtil.randomString());

    newWebsite.setCreateDate(RandomTestUtil.nextDate());

    newWebsite.setModifiedDate(RandomTestUtil.nextDate());

    newWebsite.setClassNameId(RandomTestUtil.nextLong());

    newWebsite.setClassPK(RandomTestUtil.nextLong());

    newWebsite.setUrl(RandomTestUtil.randomString());

    newWebsite.setTypeId(RandomTestUtil.nextLong());

    newWebsite.setPrimary(RandomTestUtil.randomBoolean());

    newWebsite.setLastPublishDate(RandomTestUtil.nextDate());

    _websites.add(_persistence.update(newWebsite));

    Website existingWebsite = _persistence.findByPrimaryKey(newWebsite.getPrimaryKey());

    Assert.assertEquals(existingWebsite.getMvccVersion(), newWebsite.getMvccVersion());
    Assert.assertEquals(existingWebsite.getUuid(), newWebsite.getUuid());
    Assert.assertEquals(existingWebsite.getWebsiteId(), newWebsite.getWebsiteId());
    Assert.assertEquals(existingWebsite.getCompanyId(), newWebsite.getCompanyId());
    Assert.assertEquals(existingWebsite.getUserId(), newWebsite.getUserId());
    Assert.assertEquals(existingWebsite.getUserName(), newWebsite.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingWebsite.getCreateDate()),
        Time.getShortTimestamp(newWebsite.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingWebsite.getModifiedDate()),
        Time.getShortTimestamp(newWebsite.getModifiedDate()));
    Assert.assertEquals(existingWebsite.getClassNameId(), newWebsite.getClassNameId());
    Assert.assertEquals(existingWebsite.getClassPK(), newWebsite.getClassPK());
    Assert.assertEquals(existingWebsite.getUrl(), newWebsite.getUrl());
    Assert.assertEquals(existingWebsite.getTypeId(), newWebsite.getTypeId());
    Assert.assertEquals(existingWebsite.getPrimary(), newWebsite.getPrimary());
    Assert.assertEquals(
        Time.getShortTimestamp(existingWebsite.getLastPublishDate()),
        Time.getShortTimestamp(newWebsite.getLastPublishDate()));
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    MBDiscussion newMBDiscussion = _persistence.create(pk);

    newMBDiscussion.setUuid(RandomTestUtil.randomString());

    newMBDiscussion.setGroupId(RandomTestUtil.nextLong());

    newMBDiscussion.setCompanyId(RandomTestUtil.nextLong());

    newMBDiscussion.setUserId(RandomTestUtil.nextLong());

    newMBDiscussion.setUserName(RandomTestUtil.randomString());

    newMBDiscussion.setCreateDate(RandomTestUtil.nextDate());

    newMBDiscussion.setModifiedDate(RandomTestUtil.nextDate());

    newMBDiscussion.setClassNameId(RandomTestUtil.nextLong());

    newMBDiscussion.setClassPK(RandomTestUtil.nextLong());

    newMBDiscussion.setThreadId(RandomTestUtil.nextLong());

    newMBDiscussion.setLastPublishDate(RandomTestUtil.nextDate());

    _mbDiscussions.add(_persistence.update(newMBDiscussion));

    MBDiscussion existingMBDiscussion =
        _persistence.findByPrimaryKey(newMBDiscussion.getPrimaryKey());

    Assert.assertEquals(existingMBDiscussion.getUuid(), newMBDiscussion.getUuid());
    Assert.assertEquals(existingMBDiscussion.getDiscussionId(), newMBDiscussion.getDiscussionId());
    Assert.assertEquals(existingMBDiscussion.getGroupId(), newMBDiscussion.getGroupId());
    Assert.assertEquals(existingMBDiscussion.getCompanyId(), newMBDiscussion.getCompanyId());
    Assert.assertEquals(existingMBDiscussion.getUserId(), newMBDiscussion.getUserId());
    Assert.assertEquals(existingMBDiscussion.getUserName(), newMBDiscussion.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingMBDiscussion.getCreateDate()),
        Time.getShortTimestamp(newMBDiscussion.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingMBDiscussion.getModifiedDate()),
        Time.getShortTimestamp(newMBDiscussion.getModifiedDate()));
    Assert.assertEquals(existingMBDiscussion.getClassNameId(), newMBDiscussion.getClassNameId());
    Assert.assertEquals(existingMBDiscussion.getClassPK(), newMBDiscussion.getClassPK());
    Assert.assertEquals(existingMBDiscussion.getThreadId(), newMBDiscussion.getThreadId());
    Assert.assertEquals(
        Time.getShortTimestamp(existingMBDiscussion.getLastPublishDate()),
        Time.getShortTimestamp(newMBDiscussion.getLastPublishDate()));
  }
  protected void addBlogsEntry(long groupId, String assetTagName) throws Exception {

    ServiceContext serviceContext =
        ServiceContextTestUtil.getServiceContext(groupId, TestPropsValues.getUserId());

    serviceContext.setAssetTagNames(new String[] {assetTagName});

    BlogsEntryLocalServiceUtil.addEntry(
        TestPropsValues.getUserId(),
        RandomTestUtil.randomString(),
        RandomTestUtil.randomString(),
        serviceContext);
  }
  @Test
  public void testGetKBFoldersAndKBArticlesCountInKBFolder() throws Exception {

    addKBArticle(_kbFolder.getKbFolderId(), RandomTestUtil.randomString());
    addKBArticle(_kbFolder.getKbFolderId(), RandomTestUtil.randomString());

    addKBFolder(_kbFolder.getKbFolderId());

    Assert.assertEquals(
        3,
        KBFolderLocalServiceUtil.getKBFoldersAndKBArticlesCount(
            _group.getGroupId(), _kbFolder.getKbFolderId(), WorkflowConstants.STATUS_ANY));
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Team newTeam = _persistence.create(pk);

    newTeam.setMvccVersion(RandomTestUtil.nextLong());

    newTeam.setUuid(RandomTestUtil.randomString());

    newTeam.setCompanyId(RandomTestUtil.nextLong());

    newTeam.setUserId(RandomTestUtil.nextLong());

    newTeam.setUserName(RandomTestUtil.randomString());

    newTeam.setCreateDate(RandomTestUtil.nextDate());

    newTeam.setModifiedDate(RandomTestUtil.nextDate());

    newTeam.setGroupId(RandomTestUtil.nextLong());

    newTeam.setName(RandomTestUtil.randomString());

    newTeam.setDescription(RandomTestUtil.randomString());

    newTeam.setLastPublishDate(RandomTestUtil.nextDate());

    _teams.add(_persistence.update(newTeam));

    Team existingTeam = _persistence.findByPrimaryKey(newTeam.getPrimaryKey());

    Assert.assertEquals(existingTeam.getMvccVersion(), newTeam.getMvccVersion());
    Assert.assertEquals(existingTeam.getUuid(), newTeam.getUuid());
    Assert.assertEquals(existingTeam.getTeamId(), newTeam.getTeamId());
    Assert.assertEquals(existingTeam.getCompanyId(), newTeam.getCompanyId());
    Assert.assertEquals(existingTeam.getUserId(), newTeam.getUserId());
    Assert.assertEquals(existingTeam.getUserName(), newTeam.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingTeam.getCreateDate()),
        Time.getShortTimestamp(newTeam.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingTeam.getModifiedDate()),
        Time.getShortTimestamp(newTeam.getModifiedDate()));
    Assert.assertEquals(existingTeam.getGroupId(), newTeam.getGroupId());
    Assert.assertEquals(existingTeam.getName(), newTeam.getName());
    Assert.assertEquals(existingTeam.getDescription(), newTeam.getDescription());
    Assert.assertEquals(
        Time.getShortTimestamp(existingTeam.getLastPublishDate()),
        Time.getShortTimestamp(newTeam.getLastPublishDate()));
  }
  @Override
  protected void doSetUp() throws Exception {
    _article =
        JournalTestUtil.addArticle(
            group.getGroupId(), RandomTestUtil.randomString(), RandomTestUtil.randomString());

    JournalFolder folder =
        JournalTestUtil.addFolder(group.getGroupId(), RandomTestUtil.randomString());

    _subarticle =
        JournalTestUtil.addArticle(
            group.getGroupId(), folder.getFolderId(),
            RandomTestUtil.randomString(), RandomTestUtil.randomString());
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    MeetupsRegistration newMeetupsRegistration = _persistence.create(pk);

    newMeetupsRegistration.setCompanyId(RandomTestUtil.nextLong());

    newMeetupsRegistration.setUserId(RandomTestUtil.nextLong());

    newMeetupsRegistration.setUserName(RandomTestUtil.randomString());

    newMeetupsRegistration.setCreateDate(RandomTestUtil.nextDate());

    newMeetupsRegistration.setModifiedDate(RandomTestUtil.nextDate());

    newMeetupsRegistration.setMeetupsEntryId(RandomTestUtil.nextLong());

    newMeetupsRegistration.setStatus(RandomTestUtil.nextInt());

    newMeetupsRegistration.setComments(RandomTestUtil.randomString());

    _meetupsRegistrations.add(_persistence.update(newMeetupsRegistration));

    MeetupsRegistration existingMeetupsRegistration =
        _persistence.findByPrimaryKey(newMeetupsRegistration.getPrimaryKey());

    Assert.assertEquals(
        existingMeetupsRegistration.getMeetupsRegistrationId(),
        newMeetupsRegistration.getMeetupsRegistrationId());
    Assert.assertEquals(
        existingMeetupsRegistration.getCompanyId(), newMeetupsRegistration.getCompanyId());
    Assert.assertEquals(
        existingMeetupsRegistration.getUserId(), newMeetupsRegistration.getUserId());
    Assert.assertEquals(
        existingMeetupsRegistration.getUserName(), newMeetupsRegistration.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingMeetupsRegistration.getCreateDate()),
        Time.getShortTimestamp(newMeetupsRegistration.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingMeetupsRegistration.getModifiedDate()),
        Time.getShortTimestamp(newMeetupsRegistration.getModifiedDate()));
    Assert.assertEquals(
        existingMeetupsRegistration.getMeetupsEntryId(),
        newMeetupsRegistration.getMeetupsEntryId());
    Assert.assertEquals(
        existingMeetupsRegistration.getStatus(), newMeetupsRegistration.getStatus());
    Assert.assertEquals(
        existingMeetupsRegistration.getComments(), newMeetupsRegistration.getComments());
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    RatingsEntry newRatingsEntry = _persistence.create(pk);

    newRatingsEntry.setUuid(RandomTestUtil.randomString());

    newRatingsEntry.setCompanyId(RandomTestUtil.nextLong());

    newRatingsEntry.setUserId(RandomTestUtil.nextLong());

    newRatingsEntry.setUserName(RandomTestUtil.randomString());

    newRatingsEntry.setCreateDate(RandomTestUtil.nextDate());

    newRatingsEntry.setModifiedDate(RandomTestUtil.nextDate());

    newRatingsEntry.setClassNameId(RandomTestUtil.nextLong());

    newRatingsEntry.setClassPK(RandomTestUtil.nextLong());

    newRatingsEntry.setScore(RandomTestUtil.nextDouble());

    newRatingsEntry.setLastPublishDate(RandomTestUtil.nextDate());

    _ratingsEntries.add(_persistence.update(newRatingsEntry));

    RatingsEntry existingRatingsEntry =
        _persistence.findByPrimaryKey(newRatingsEntry.getPrimaryKey());

    Assert.assertEquals(existingRatingsEntry.getUuid(), newRatingsEntry.getUuid());
    Assert.assertEquals(existingRatingsEntry.getEntryId(), newRatingsEntry.getEntryId());
    Assert.assertEquals(existingRatingsEntry.getCompanyId(), newRatingsEntry.getCompanyId());
    Assert.assertEquals(existingRatingsEntry.getUserId(), newRatingsEntry.getUserId());
    Assert.assertEquals(existingRatingsEntry.getUserName(), newRatingsEntry.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingRatingsEntry.getCreateDate()),
        Time.getShortTimestamp(newRatingsEntry.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingRatingsEntry.getModifiedDate()),
        Time.getShortTimestamp(newRatingsEntry.getModifiedDate()));
    Assert.assertEquals(existingRatingsEntry.getClassNameId(), newRatingsEntry.getClassNameId());
    Assert.assertEquals(existingRatingsEntry.getClassPK(), newRatingsEntry.getClassPK());
    AssertUtils.assertEquals(existingRatingsEntry.getScore(), newRatingsEntry.getScore());
    Assert.assertEquals(
        Time.getShortTimestamp(existingRatingsEntry.getLastPublishDate()),
        Time.getShortTimestamp(newRatingsEntry.getLastPublishDate()));
  }
  @Test
  public void testMigrateDLWhenFileEntryInFolder() throws Exception {
    ServiceContext serviceContext =
        ServiceContextTestUtil.getServiceContext(_group.getGroupId(), TestPropsValues.getUserId());

    Folder folder =
        DLAppServiceUtil.addFolder(
            _group.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            RandomTestUtil.randomString(),
            RandomTestUtil.randomString(),
            serviceContext);

    testMigrateDL(folder.getFolderId());
  }
  @Override
  protected void addStagedModels() throws Exception {
    WikiNode node = WikiTestUtil.addNode(stagingGroup.getGroupId());

    ServiceContext serviceContext =
        ServiceContextTestUtil.getServiceContext(stagingGroup.getGroupId());

    WikiTestUtil.addPage(
        TestPropsValues.getUserId(),
        node.getNodeId(),
        RandomTestUtil.randomString(),
        RandomTestUtil.randomString(),
        true,
        serviceContext);
  }
  protected KBFolder addKBFolder(long parentResourcePrimKey)
      throws com.liferay.portal.kernel.exception.PortalException {

    ServiceContext serviceContext =
        ServiceContextTestUtil.getServiceContext(_group, _user.getUserId());

    return KBFolderLocalServiceUtil.addKBFolder(
        _user.getUserId(),
        _group.getGroupId(),
        PortalUtil.getClassNameId(KBFolderConstants.getClassName()),
        parentResourcePrimKey,
        RandomTestUtil.randomString(),
        RandomTestUtil.randomString(),
        serviceContext);
  }
  @Test
  public void testGetKBFoldersAndKBArticlesCountKBFolderImmediateChildren() throws Exception {

    KBArticle parentKBArticle =
        addKBArticle(_kbFolder.getKbFolderId(), RandomTestUtil.randomString());

    addChildKBArticle(parentKBArticle, RandomTestUtil.randomString());

    addKBFolder(_kbFolder.getKbFolderId());

    Assert.assertEquals(
        2,
        KBFolderLocalServiceUtil.getKBFoldersAndKBArticlesCount(
            _group.getGroupId(), _kbFolder.getKbFolderId(), WorkflowConstants.STATUS_ANY));
  }
  @Test
  public void testGetKBFoldersAndKBArticlesCountWithMultipleKBArticleVersions() throws Exception {

    KBArticle kbArticle =
        addKBArticle(KBFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString());

    updateKBArticle(kbArticle, RandomTestUtil.randomString());

    Assert.assertEquals(
        2,
        KBFolderLocalServiceUtil.getKBFoldersAndKBArticlesCount(
            _group.getGroupId(),
            KBFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            WorkflowConstants.STATUS_ANY));
  }
  @Test
  public void testRestoreFileNameWhenDeletingLatestFileVersion() throws Exception {

    DLFileEntry dlFileEntry = addDLFileEntry(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, false);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    dlFileEntry = updateStatus(dlFileEntry.getLatestFileVersion(true), serviceContext);

    String initialFileName = dlFileEntry.getFileName();

    dlFileEntry.setTitle(RandomTestUtil.randomString());

    dlFileEntry = updateDLFileEntry(dlFileEntry, serviceContext);

    dlFileEntry = updateStatus(dlFileEntry.getLatestFileVersion(true), serviceContext);

    DLFileVersion dlFileVersion = dlFileEntry.getLatestFileVersion(true);

    dlFileEntry =
        DLFileEntryLocalServiceUtil.deleteFileVersion(
            dlFileEntry.getUserId(), dlFileEntry.getFileEntryId(), dlFileVersion.getVersion());

    Assert.assertEquals(initialFileName, dlFileEntry.getFileName());
  }