Ejemplo n.º 1
0
  protected void searchVersions() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

    searchContext.setKeywords(getSearchKeywords());

    int initialBaseModelsCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

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

    baseModel = addBaseModel(parentBaseModel, true, getSearchKeywords(), serviceContext);

    Assert.assertEquals(
        initialBaseModelsCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    baseModel = updateBaseModel(baseModel, "liferay", serviceContext);

    Assert.assertEquals(
        initialBaseModelsCount,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    baseModel = updateBaseModel(baseModel, "portal", serviceContext);

    searchContext.setKeywords("portal");

    Assert.assertEquals(
        initialBaseModelsCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
Ejemplo n.º 2
0
  @Test
  public void testLocalizedSearch() throws Exception {
    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

    int initialBaseModelsSearchCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

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

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

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

    keywordsMap.put(LocaleUtil.getDefault(), "entity title");
    keywordsMap.put(LocaleUtil.HUNGARY, "entitas neve");

    baseModel = addBaseModelWithWorkflow(parentBaseModel, true, keywordsMap, serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    searchContext.setAttribute(Field.TITLE, "nev");
    searchContext.setKeywords("nev");
    searchContext.setLocale(LocaleUtil.HUNGARY);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
Ejemplo n.º 3
0
  protected void searchComments() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

    searchContext.setIncludeDiscussions(true);

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

    int initialBaseModelsSearchCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

    baseModel = addBaseModel(parentBaseModel, true, RandomTestUtil.randomString(), serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    addComment(baseModel, getSearchKeywords(), serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 2,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    moveBaseModelToTrash((Long) baseModel.getPrimaryKeyObj());

    Assert.assertEquals(
        initialBaseModelsSearchCount,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
Ejemplo n.º 4
0
  protected void searchByKeywordsInsideParentBaseModel() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

    baseModel = addBaseModel(null, true, getSearchKeywords(), serviceContext);

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

    searchContext.setFolderIds(new long[] {(Long) parentBaseModel1.getPrimaryKeyObj()});
    searchContext.setKeywords(getSearchKeywords());

    int initialBaseModelsSearchCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

    baseModel = addBaseModel(parentBaseModel1, true, getSearchKeywords(), serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    BaseModel<?> parentBaseModel2 = getParentBaseModel(parentBaseModel1, serviceContext);

    baseModel = addBaseModel(parentBaseModel2, true, getSearchKeywords(), serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 2,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
Ejemplo n.º 5
0
  protected void searchByDDMStructureField() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

    int initialBaseModelsSearchCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

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

    baseModel = addBaseModelWithDDMStructure(parentBaseModel, getSearchKeywords(), serviceContext);

    searchContext.setAttribute("ddmStructureFieldName", getDDMStructureFieldName());
    searchContext.setAttribute("ddmStructureFieldValue", getSearchKeywords());

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    updateDDMStructure(serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
Ejemplo n.º 6
0
  protected void searchBaseModelWithUpdate() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

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

    searchContext.setKeywords(getSearchKeywords());

    int initialBaseModelsSearchCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

    baseModel = addBaseModel(parentBaseModel, true, getSearchKeywords(), serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    String updatedKeywords = RandomTestUtil.randomString();

    baseModel = updateBaseModel(baseModel, updatedKeywords, serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    searchContext.setKeywords(updatedKeywords);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
Ejemplo n.º 7
0
  protected void searchStatus() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

    int initialBaseModelsCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), "1.0", searchContext);

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

    baseModel = addBaseModel(parentBaseModel, false, "Version 1.0", serviceContext);

    Assert.assertEquals(
        initialBaseModelsCount,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    baseModel = updateBaseModel(baseModel, "Version 1.1", serviceContext);

    Assert.assertEquals(
        initialBaseModelsCount,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), "1.0", searchContext));
    Assert.assertEquals(
        initialBaseModelsCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), "1.1", searchContext));

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);

    baseModel = updateBaseModel(baseModel, "Version 1.2", serviceContext);

    Assert.assertEquals(
        initialBaseModelsCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), "1.1", searchContext));
    Assert.assertEquals(
        initialBaseModelsCount,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), "1.2", searchContext));

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    baseModel = updateBaseModel(baseModel, "Version 1.3", serviceContext);

    Assert.assertEquals(
        initialBaseModelsCount,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), "1.2", searchContext));
    Assert.assertEquals(
        initialBaseModelsCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), "1.3", searchContext));
  }
Ejemplo n.º 8
0
  protected void searchBaseModel() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

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

    int initialBaseModelsSearchCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

    baseModel = addBaseModel(parentBaseModel, true, RandomTestUtil.randomString(), serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
Ejemplo n.º 9
0
  protected void testUserPermissions(
      boolean addBaseModelPermission, boolean addParentBaseModelPermission) throws Exception {

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

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

    searchContext.setKeywords(getSearchKeywords());

    int initialBaseModelsSearchCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

    serviceContext.setAddGroupPermissions(addParentBaseModelPermission);
    serviceContext.setAddGuestPermissions(addParentBaseModelPermission);

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

    serviceContext.setAddGroupPermissions(addBaseModelPermission);
    serviceContext.setAddGuestPermissions(addBaseModelPermission);

    baseModel = addBaseModel(parentBaseModel, true, getSearchKeywords(), serviceContext);

    User user = UserTestUtil.addUser(null, 0);

    PermissionChecker originalPermissionChecker = PermissionThreadLocal.getPermissionChecker();

    try {
      PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);

      PermissionThreadLocal.setPermissionChecker(permissionChecker);

      searchContext.setUserId(user.getUserId());

      int baseModelsCount = initialBaseModelsSearchCount;

      if (addBaseModelPermission && !isCheckBaseModelPermission()) {
        baseModelsCount++;
      }

      Assert.assertEquals(
          baseModelsCount,
          searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
    } finally {
      PermissionThreadLocal.setPermissionChecker(originalPermissionChecker);
    }
  }
Ejemplo n.º 10
0
  protected void searchWithinDDMStructure() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

    searchContext.setKeywords(getSearchKeywords());

    int initialBaseModelsSearchCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

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

    baseModel = addBaseModelWithDDMStructure(parentBaseModel, getSearchKeywords(), serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
Ejemplo n.º 11
0
  protected void searchExpireVersions(boolean expireAllVersions) throws Exception {

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

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

    searchContext.setKeywords(getSearchKeywords());

    int initialBaseModelsCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

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

    baseModel = addBaseModel(parentBaseModel, true, getSearchKeywords(), serviceContext);

    Assert.assertEquals(
        initialBaseModelsCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    baseModel = updateBaseModel(baseModel, "liferay", serviceContext);

    Assert.assertEquals(
        initialBaseModelsCount,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    expireBaseModelVersions(baseModel, expireAllVersions, serviceContext);

    if (expireAllVersions && isExpirableAllVersions()) {
      Assert.assertEquals(
          initialBaseModelsCount,
          searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
    } else {
      Assert.assertEquals(
          initialBaseModelsCount + 1,
          searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
    }
  }
Ejemplo n.º 12
0
  protected void searchBaseModelWithTrash() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

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

    int initialBaseModelsSearchCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

    baseModel = addBaseModel(parentBaseModel, true, getSearchKeywords(), serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    moveBaseModelToTrash((Long) baseModel.getPrimaryKeyObj());

    searchContext.setKeywords(getSearchKeywords());

    Assert.assertEquals(
        initialBaseModelsSearchCount,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }