@Test
  public void testUpdateExisting() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    ResourcePermission newResourcePermission = _persistence.create(pk);

    newResourcePermission.setCompanyId(ServiceTestUtil.nextLong());

    newResourcePermission.setName(ServiceTestUtil.randomString());

    newResourcePermission.setScope(ServiceTestUtil.nextInt());

    newResourcePermission.setPrimKey(ServiceTestUtil.randomString());

    newResourcePermission.setRoleId(ServiceTestUtil.nextLong());

    newResourcePermission.setOwnerId(ServiceTestUtil.nextLong());

    newResourcePermission.setActionIds(ServiceTestUtil.nextLong());

    _persistence.update(newResourcePermission, false);

    ResourcePermission existingResourcePermission =
        _persistence.findByPrimaryKey(newResourcePermission.getPrimaryKey());

    Assert.assertEquals(
        existingResourcePermission.getResourcePermissionId(),
        newResourcePermission.getResourcePermissionId());
    Assert.assertEquals(
        existingResourcePermission.getCompanyId(), newResourcePermission.getCompanyId());
    Assert.assertEquals(existingResourcePermission.getName(), newResourcePermission.getName());
    Assert.assertEquals(existingResourcePermission.getScope(), newResourcePermission.getScope());
    Assert.assertEquals(
        existingResourcePermission.getPrimKey(), newResourcePermission.getPrimKey());
    Assert.assertEquals(existingResourcePermission.getRoleId(), newResourcePermission.getRoleId());
    Assert.assertEquals(
        existingResourcePermission.getOwnerId(), newResourcePermission.getOwnerId());
    Assert.assertEquals(
        existingResourcePermission.getActionIds(), newResourcePermission.getActionIds());
  }
예제 #2
0
  protected void deletePermissions_6(long companyId) throws Exception {
    Group group = GroupLocalServiceUtil.getGroup(companyId, GroupConstants.CONTROL_PANEL);

    long plid = LayoutLocalServiceUtil.getDefaultPlid(group.getGroupId(), true);

    Role role = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST);

    List<ResourcePermission> resourcePermissions =
        ResourcePermissionLocalServiceUtil.getRoleResourcePermissions(role.getRoleId());

    for (ResourcePermission resourcePermission : resourcePermissions) {
      if (isControlPanelLayout(plid, resourcePermission.getPrimKey())
          || isPrivateLayout(resourcePermission.getName(), resourcePermission.getPrimKey())) {

        ResourcePermissionLocalServiceUtil.deleteResourcePermission(
            resourcePermission.getResourcePermissionId());
      }
    }
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    ResourcePermission newResourcePermission = addResourcePermission();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            ResourcePermission.class, ResourcePermission.class.getClassLoader());

    dynamicQuery.add(
        RestrictionsFactoryUtil.eq(
            "resourcePermissionId", newResourcePermission.getResourcePermissionId()));

    List<ResourcePermission> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    ResourcePermission existingResourcePermission = result.get(0);

    Assert.assertEquals(existingResourcePermission, newResourcePermission);
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    ResourcePermission newResourcePermission = addResourcePermission();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            ResourcePermission.class, ResourcePermission.class.getClassLoader());

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("resourcePermissionId"));

    Object newResourcePermissionId = newResourcePermission.getResourcePermissionId();

    dynamicQuery.add(
        RestrictionsFactoryUtil.in("resourcePermissionId", new Object[] {newResourcePermissionId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingResourcePermissionId = result.get(0);

    Assert.assertEquals(existingResourcePermissionId, newResourcePermissionId);
  }