@Test
  public void testCountByG_P_L() throws Exception {
    _persistence.countByG_P_L(
        RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(), RandomTestUtil.nextLong());

    _persistence.countByG_P_L(0L, RandomTestUtil.randomBoolean(), 0L);
  }
  @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());
  }
  protected Group addScopeGroup() throws Exception {
    Group group = GroupTestUtil.addGroup();

    Layout layout = LayoutTestUtil.addLayout(group);

    Map<Locale, String> nameMap = new HashMap<>();

    String name = RandomTestUtil.randomString();

    nameMap.put(LocaleUtil.getDefault(), name);

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

    return GroupLocalServiceUtil.addGroup(
        TestPropsValues.getUserId(),
        group.getParentGroupId(),
        Layout.class.getName(),
        layout.getPlid(),
        GroupConstants.DEFAULT_LIVE_GROUP_ID,
        nameMap,
        RandomTestUtil.randomLocaleStringMap(),
        GroupConstants.TYPE_SITE_OPEN,
        true,
        GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,
        StringPool.SLASH + FriendlyURLNormalizerUtil.normalize(name),
        false,
        true,
        serviceContext);
  }
  @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());
  }
 @Test
 public void testCountByG_F_FArrayable() throws Exception {
   _persistence.countByG_F_F(
       RandomTestUtil.nextLong(),
       new long[] {RandomTestUtil.nextLong(), 0L},
       RandomTestUtil.nextLong());
 }
  @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 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());
  }
  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);
  }
  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 testCountByC_C_C() throws Exception {
    _persistence.countByC_C_C(
        RandomTestUtil.nextLong(), RandomTestUtil.nextLong(), RandomTestUtil.nextLong());

    _persistence.countByC_C_C(0L, 0L, 0L);
  }
  @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);
  }
  @Test
  public void testCountByC_C_A() throws Exception {
    _persistence.countByC_C_A(
        RandomTestUtil.nextLong(), StringPool.BLANK, RandomTestUtil.randomBoolean());

    _persistence.countByC_C_A(0L, StringPool.NULL, RandomTestUtil.randomBoolean());

    _persistence.countByC_C_A(0L, (String) null, RandomTestUtil.randomBoolean());
  }
  @Test
  public void testCountByG_U_PPPS() throws Exception {
    _persistence.countByG_U_PPPS(
        RandomTestUtil.nextLong(), RandomTestUtil.nextLong(), StringPool.BLANK);

    _persistence.countByG_U_PPPS(0L, 0L, StringPool.NULL);

    _persistence.countByG_U_PPPS(0L, 0L, (String) null);
  }
  @Test
  public void testCountByG_C_C_T() throws Exception {
    _persistence.countByG_C_C_T(
        RandomTestUtil.nextLong(),
        RandomTestUtil.nextLong(),
        RandomTestUtil.nextLong(),
        RandomTestUtil.nextInt());

    _persistence.countByG_C_C_T(0L, 0L, 0L, 0);
  }
  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;
  }
  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;
  }
  @Test(expected = EntryScoreException.class)
  public void testRatingScoreLessThan0IsInvalidScore() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    RatingsEntryLocalServiceUtil.updateEntry(
        TestPropsValues.getUserId(),
        RandomTestUtil.randomString(),
        RandomTestUtil.randomLong(),
        -1,
        serviceContext);
  }
  @Test
  public void testCountByG_P_L_P() throws Exception {
    _persistence.countByG_P_L_P(
        RandomTestUtil.nextLong(),
        RandomTestUtil.randomBoolean(),
        RandomTestUtil.nextLong(),
        StringPool.BLANK);

    _persistence.countByG_P_L_P(0L, RandomTestUtil.randomBoolean(), 0L, StringPool.NULL);

    _persistence.countByG_P_L_P(0L, RandomTestUtil.randomBoolean(), 0L, (String) null);
  }
  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));
  }
  @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();

    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 testRatingScore1IsValidScore() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    RatingsEntry ratingsEntry =
        RatingsEntryLocalServiceUtil.updateEntry(
            TestPropsValues.getUserId(),
            RandomTestUtil.randomString(),
            RandomTestUtil.randomLong(),
            1,
            serviceContext);

    Assert.assertEquals(1, ratingsEntry.getScore(), 0.001);
  }
  @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 testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereNoPrimaryKeysExist()
      throws Exception {
    long pk1 = RandomTestUtil.nextLong();

    long pk2 = RandomTestUtil.nextLong();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(pk1);
    primaryKeys.add(pk2);

    Map<Serializable, OrgLabor> orgLabors = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertTrue(orgLabors.isEmpty());
  }
  @Test(expected = NoSuchFileVersionException.class)
  public void testCreateLocalRepositoryFromNonexistentFileVersionId() throws Exception {

    long fileVersionId = RandomTestUtil.randomLong();

    RepositoryProviderUtil.getFileVersionLocalRepository(fileVersionId);
  }