Search in sources :

Example 1 with ApplyContentPermissionsParams

use of com.enonic.xp.content.ApplyContentPermissionsParams in project xp by enonic.

the class ContentServiceImplTest_applyPermissions method audit_data.

@Test
public void audit_data() throws Exception {
    final ArgumentCaptor<LogAuditLogParams> captor = ArgumentCaptor.forClass(LogAuditLogParams.class);
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    final ApplyContentPermissionsParams applyParams = ApplyContentPermissionsParams.create().contentId(content.getId()).applyContentPermissionsListener(Mockito.mock(ApplyPermissionsListener.class)).build();
    final ApplyContentPermissionsResult result = this.contentService.applyPermissions(applyParams);
    Mockito.verify(auditLogService, Mockito.timeout(5000).times(2)).log(captor.capture());
    final PropertySet logResultSet = captor.getValue().getData().getSet("result");
    assertEquals(content.getPath().toString(), logResultSet.getStrings("succeedContents").iterator().next());
}
Also used : LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ApplyContentPermissionsParams(com.enonic.xp.content.ApplyContentPermissionsParams) PropertySet(com.enonic.xp.data.PropertySet) ApplyContentPermissionsResult(com.enonic.xp.content.ApplyContentPermissionsResult) Test(org.junit.jupiter.api.Test)

Example 2 with ApplyContentPermissionsParams

use of com.enonic.xp.content.ApplyContentPermissionsParams in project xp by enonic.

the class ContentServiceImplTest_applyPermissions method content_not_found.

@Test
public void content_not_found() throws Exception {
    final ApplyContentPermissionsParams applyParams = ApplyContentPermissionsParams.create().contentId(ContentId.from("id1")).applyContentPermissionsListener(Mockito.mock(ApplyPermissionsListener.class)).build();
    final ApplyContentPermissionsResult result = this.contentService.applyPermissions(applyParams);
    assertEquals(result.getSkippedContents().getSize(), 0);
    assertEquals(result.getSucceedContents().getSize(), 0);
}
Also used : ApplyContentPermissionsParams(com.enonic.xp.content.ApplyContentPermissionsParams) ApplyContentPermissionsResult(com.enonic.xp.content.ApplyContentPermissionsResult) Test(org.junit.jupiter.api.Test)

Example 3 with ApplyContentPermissionsParams

use of com.enonic.xp.content.ApplyContentPermissionsParams in project xp by enonic.

the class ContentServiceImplTest_applyPermissions method success.

@Test
public void success() throws Exception {
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    final Content child = this.contentService.create(CreateContentParams.create(createContentParams).parent(content.getPath()).build());
    final ApplyContentPermissionsParams applyParams = ApplyContentPermissionsParams.create().contentId(content.getId()).applyContentPermissionsListener(Mockito.mock(ApplyPermissionsListener.class)).build();
    final ApplyContentPermissionsResult result = this.contentService.applyPermissions(applyParams);
    assertEquals(result.getSkippedContents().getSize(), 0);
    assertEquals(result.getSucceedContents().getSize(), 2);
    assertTrue(result.getSucceedContents().contains(child.getPath()));
    assertTrue(result.getSucceedContents().contains(content.getPath()));
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ApplyContentPermissionsParams(com.enonic.xp.content.ApplyContentPermissionsParams) ApplyContentPermissionsResult(com.enonic.xp.content.ApplyContentPermissionsResult) Test(org.junit.jupiter.api.Test)

Example 4 with ApplyContentPermissionsParams

use of com.enonic.xp.content.ApplyContentPermissionsParams in project xp by enonic.

the class ModifyProjectReadAccessHandlerTest method initialize.

@Override
public void initialize() throws Exception {
    super.initialize();
    when(this.contentService.applyPermissions(any(ApplyContentPermissionsParams.class))).thenAnswer(mock -> {
        final ApplyContentPermissionsParams params = (ApplyContentPermissionsParams) mock.getArguments()[0];
        Mockito.when(contentService.getByPath(ContentPath.ROOT)).thenReturn(Content.create().id(ContentId.from("123")).name(ContentName.from("root")).parentPath(ContentPath.ROOT).permissions(AccessControlList.empty()).data(new PropertyTree()).extraDatas(ExtraDatas.empty()).permissions(params.getPermissions()).build());
        return null;
    });
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) ApplyContentPermissionsParams(com.enonic.xp.content.ApplyContentPermissionsParams)

Aggregations

ApplyContentPermissionsParams (com.enonic.xp.content.ApplyContentPermissionsParams)4 ApplyContentPermissionsResult (com.enonic.xp.content.ApplyContentPermissionsResult)3 PropertyTree (com.enonic.xp.data.PropertyTree)3 Test (org.junit.jupiter.api.Test)3 Content (com.enonic.xp.content.Content)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)2 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)1 PropertySet (com.enonic.xp.data.PropertySet)1