Search in sources :

Example 1 with ProjectName

use of com.enonic.xp.project.ProjectName in project xp by enonic.

the class ProjectsSyncTaskTest method order.

@Test
void order() {
    final Projects projects = Projects.create().addAll(Set.of(createProject("turkey-tr-tr", "turkey-tr"), createProject("enonic-common", null), createProject("corporate", "enonic-common"), createProject("corporate-no", "corporate"), createProject("countries", "enonic-common"), createProject("denmark", "countries"), createProject("without-actual-parent1", "unknown-parent1"), createProject("denmark-de", "denmark"), createProject("sweden", "countries"), createProject("sweden-sw", "sweden"), createProject("sweden-sw-sw", "sweden-sw"), createProject("root1", null), createProject("child1", "root1"), createProject("without-actual-parent2", "unknown-parent2"), createProject("turkey", "countries"), createProject("turkey-tr", "turkey"))).build();
    when(projectService.list()).thenReturn(projects);
    ProjectsSyncTask.create().projectService(projectService).syncContentService(syncContentService).build().run(TaskId.from("taskId"), mock(ProgressReporter.class, withSettings().stubOnly()));
    verify(syncContentService, times(14)).syncProject(paramsCaptor.capture());
    final List<ProjectName> syncProjects = paramsCaptor.getAllValues().stream().map(ProjectSyncParams::getTargetProject).collect(Collectors.toList());
    assertAll(() -> assertThat(syncProjects.indexOf(ProjectName.from("turkey-tr-tr"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("turkey-tr"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("turkey-tr"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("turkey"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("turkey"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("countries"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("corporate-no"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("corporate"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("denmark-de"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("denmark"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("denmark"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("countries"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("sweden-sw-sw"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("sweden-sw"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("sweden-sw"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("sweden"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("sweden"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("countries"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("child1"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("root1"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("without-actual-parent1"))).isGreaterThanOrEqualTo(12), () -> assertThat(syncProjects.indexOf(ProjectName.from("without-actual-parent2"))).isGreaterThanOrEqualTo(12), () -> assertThat(syncProjects).doesNotContain(ProjectName.from("enoic-common"), ProjectName.from("root1")));
}
Also used : ProjectName(com.enonic.xp.project.ProjectName) Projects(com.enonic.xp.project.Projects) ProgressReporter(com.enonic.xp.task.ProgressReporter) Test(org.junit.jupiter.api.Test)

Example 2 with ProjectName

use of com.enonic.xp.project.ProjectName in project xp by enonic.

the class SyncContentServiceImplTest method resetWithRemovedSource.

@Test
public void resetWithRemovedSource() throws Exception {
    final Content source = sourceContext.callWith(() -> createContent(ContentPath.ROOT));
    syncCreated(source.getId());
    targetContext.runWith(() -> {
        contentService.update(new UpdateContentParams().contentId(source.getId()).editor(edit -> {
            edit.workflowInfo = WorkflowInfo.ready();
            edit.data = new PropertyTree();
        }));
    });
    sourceContext.runWith(() -> contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(source.getPath()).build()));
    assertThrows(IllegalArgumentException.class, () -> syncContentService.resetInheritance(ResetContentInheritParams.create().contentId(source.getId()).inherit(EnumSet.of(ContentInheritType.CONTENT)).projectName(targetProject.getName()).build()));
}
Also used : ChildOrder(com.enonic.xp.index.ChildOrder) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) ContentPath(com.enonic.xp.content.ContentPath) ProjectSyncParams(com.enonic.xp.content.ProjectSyncParams) ContentInheritType(com.enonic.xp.content.ContentInheritType) Content(com.enonic.xp.content.Content) DeleteContentParams(com.enonic.xp.content.DeleteContentParams) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) ContentSyncEventType(com.enonic.xp.core.impl.content.ContentSyncEventType) Test(org.junit.jupiter.api.Test) ParentContentSynchronizer(com.enonic.xp.core.impl.content.ParentContentSynchronizer) SyncContentServiceImpl(com.enonic.xp.core.impl.content.SyncContentServiceImpl) ContentId(com.enonic.xp.content.ContentId) ResetContentInheritParams(com.enonic.xp.content.ResetContentInheritParams) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ProjectName(com.enonic.xp.project.ProjectName) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SetContentChildOrderParams(com.enonic.xp.content.SetContentChildOrderParams) ContentEventsSyncParams(com.enonic.xp.core.impl.content.ContentEventsSyncParams) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EnumSet(java.util.EnumSet) PropertyTree(com.enonic.xp.data.PropertyTree) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 3 with ProjectName

use of com.enonic.xp.project.ProjectName in project xp by enonic.

the class ProjectServiceImplTest method delete_with_custom_permissions.

@Test
void delete_with_custom_permissions() {
    final ProjectName projectName = ProjectName.from("test-project");
    doCreateProjectAsAdmin(projectName);
    adminContext().runWith(() -> assertNotNull(this.projectService.get(projectName)));
    contentCustomManagerContext().runWith(() -> {
        final RuntimeException ex = Assertions.assertThrows(RuntimeException.class, () -> projectService.delete(projectName));
        assertEquals("Denied [user:system:custom-user] user access for [delete] operation", ex.getMessage());
    });
}
Also used : ProjectName(com.enonic.xp.project.ProjectName) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 4 with ProjectName

use of com.enonic.xp.project.ProjectName in project xp by enonic.

the class ProjectServiceImplTest method create_project_with_public_readAccess.

@Test
void create_project_with_public_readAccess() {
    final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
    final ProjectName projectName = ProjectName.from(projectRepoId);
    adminContext().callWith(() -> doCreateProject(projectName, null, false, null, AccessControlList.create().add(AccessControlEntry.create().principal(RoleKeys.EVERYONE).allow(Permission.READ).build()).build()));
    ContextBuilder.from(adminContext()).branch(ContentConstants.BRANCH_DRAFT).repositoryId(projectRepoId).build().runWith(() -> {
        final Node rootContentNode = nodeService.getByPath(ContentConstants.CONTENT_ROOT_PATH);
        final AccessControlList rootContentPermissions = rootContentNode.getPermissions();
        assertTrue(rootContentPermissions.getEntry(RoleKeys.EVERYONE).isAllowed(Permission.READ));
    });
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) ProjectName(com.enonic.xp.project.ProjectName) Node(com.enonic.xp.node.Node) RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 5 with ProjectName

use of com.enonic.xp.project.ProjectName in project xp by enonic.

the class ProjectServiceImplTest method create_with_root_content_permissions.

@Test
void create_with_root_content_permissions() {
    final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
    final ProjectName projectName = ProjectName.from(projectRepoId);
    doCreateProjectAsAdmin(projectName);
    List.of(ContextBuilder.from(adminContext()).branch(ContentConstants.BRANCH_DRAFT).repositoryId(projectRepoId).build(), ContextBuilder.from(adminContext()).branch(ContentConstants.BRANCH_MASTER).repositoryId(projectRepoId).build()).forEach(context -> context.runWith(() -> {
        final Node rootContentNode = nodeService.getByPath(ContentConstants.CONTENT_ROOT_PATH);
        final AccessControlList rootContentPermissions = rootContentNode.getPermissions();
        assertTrue(rootContentPermissions.getEntry(RoleKeys.ADMIN).isAllowedAll());
        assertTrue(rootContentPermissions.getEntry(RoleKeys.CONTENT_MANAGER_ADMIN).isAllowedAll());
        assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.owner")).isAllowedAll());
        assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.editor")).isAllowedAll());
        assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.author")).isAllowed(Permission.READ, Permission.CREATE, Permission.MODIFY, Permission.DELETE));
        assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.contributor")).isAllowed(Permission.READ));
        assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.viewer")).isAllowed(Permission.READ));
        assertNull(rootContentPermissions.getEntry(RoleKeys.EVERYONE));
    }));
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) ProjectName(com.enonic.xp.project.ProjectName) Node(com.enonic.xp.node.Node) RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

ProjectName (com.enonic.xp.project.ProjectName)18 Test (org.junit.jupiter.api.Test)11 Project (com.enonic.xp.project.Project)7 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)7 RepositoryId (com.enonic.xp.repository.RepositoryId)6 Context (com.enonic.xp.context.Context)5 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)5 EnumSet (java.util.EnumSet)5 ContentId (com.enonic.xp.content.ContentId)4 ContextAccessor (com.enonic.xp.context.ContextAccessor)4 ContextBuilder (com.enonic.xp.context.ContextBuilder)4 PropertyTree (com.enonic.xp.data.PropertyTree)4 ProjectService (com.enonic.xp.project.ProjectService)4 RoleKeys (com.enonic.xp.security.RoleKeys)4 Collectors (java.util.stream.Collectors)4 Content (com.enonic.xp.content.Content)3 ContentInheritType (com.enonic.xp.content.ContentInheritType)3 ResetContentInheritParams (com.enonic.xp.content.ResetContentInheritParams)3 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)3 WorkflowInfo (com.enonic.xp.content.WorkflowInfo)3