Search in sources :

Example 6 with Project

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

the class ProjectServiceImplTest method get.

@Test
void get() {
    final Project createdProject = doCreateProjectAsAdmin(ProjectName.from("test-project"));
    adminContext().runWith(() -> {
        assertProjectEquals(createdProject, projectService.get(createdProject.getName()));
    });
}
Also used : Project(com.enonic.xp.project.Project) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 7 with Project

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

the class ProjectsSyncTaskTest method syncAll.

@Test
void syncAll() {
    final Project parent = createProject("parent", null);
    final Project child1 = createProject("child1", "parent");
    final Project child2 = createProject("child2", "child1");
    when(projectService.list()).thenReturn(Projects.create().addAll(Set.of(parent, child1, child2)).build());
    ProjectsSyncTask.create().projectService(projectService).syncContentService(syncContentService).build().run(TaskId.from("taskId"), mock(ProgressReporter.class, withSettings().stubOnly()));
    verify(syncContentService, times(2)).syncProject(paramsCaptor.capture());
    final List<ProjectName> syncProjects = paramsCaptor.getAllValues().stream().map(ProjectSyncParams::getTargetProject).collect(Collectors.toList());
    assertThat(syncProjects).containsExactly(child1.getName(), child2.getName());
}
Also used : Project(com.enonic.xp.project.Project) ProjectName(com.enonic.xp.project.ProjectName) ProgressReporter(com.enonic.xp.task.ProgressReporter) Test(org.junit.jupiter.api.Test)

Example 8 with Project

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

the class ProjectServiceImplTest method create_with_content_admin_permissions.

@Test
void create_with_content_admin_permissions() {
    final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
    final Project project = contentAdminContext().callWith(() -> doCreateProject(ProjectName.from(projectRepoId)));
    assertNotNull(project);
}
Also used : Project(com.enonic.xp.project.Project) RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 9 with Project

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

the class ProjectServiceImplTest method get_icon.

@Test
void get_icon() throws Exception {
    final Project project = doCreateProjectAsAdmin(ProjectName.from("test-project"));
    final ByteSource source = ByteSource.wrap("new bytes".getBytes());
    adminContext().runWith(() -> {
        assertNull(projectService.getIcon(project.getName()));
        projectService.modifyIcon(ModifyProjectIconParams.create().name(project.getName()).icon(CreateAttachment.create().mimeType("image/png").label("My New Image").name("MyNewImage.png").byteSource(ByteSource.wrap("new bytes".getBytes())).build()).build());
        try {
            assertArrayEquals(source.read(), projectService.getIcon(project.getName()).read());
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    });
    Assertions.assertThrows(ProjectAccessException.class, () -> projectService.getIcon(project.getName()));
}
Also used : Project(com.enonic.xp.project.Project) ByteSource(com.google.common.io.ByteSource) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 10 with Project

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

the class ProjectServiceImplTest method list_with_custom_permissions.

@Test
void list_with_custom_permissions() {
    doCreateProjectAsAdmin(ProjectName.from("test-project1"), ProjectPermissions.create().build());
    doCreateProjectAsAdmin(ProjectName.from("test-project2"), ProjectPermissions.create().addOwner(REPO_TEST_OWNER.getKey()).build());
    doCreateProjectAsAdmin(ProjectName.from("test-project3"), ProjectPermissions.create().addEditor(REPO_TEST_OWNER.getKey()).build());
    doCreateProjectAsAdmin(ProjectName.from("test-project4"), ProjectPermissions.create().addAuthor(REPO_TEST_OWNER.getKey()).build());
    doCreateProjectAsAdmin(ProjectName.from("test-project5"), ProjectPermissions.create().addContributor(REPO_TEST_OWNER.getKey()).build());
    final AuthenticationInfo authenticationInfo = AuthenticationInfo.copyOf(REPO_TEST_CUSTOM_MANAGER_AUTHINFO).principals(ProjectAccessHelper.createRoleKey(ProjectName.from("test-project2"), ProjectRole.OWNER), ProjectAccessHelper.createRoleKey(ProjectName.from("test-project3"), ProjectRole.EDITOR), ProjectAccessHelper.createRoleKey(ProjectName.from("test-project4"), ProjectRole.AUTHOR), ProjectAccessHelper.createRoleKey(ProjectName.from("test-project5"), ProjectRole.CONTRIBUTOR)).build();
    ContextBuilder.from(contentCustomManagerContext()).authInfo(authenticationInfo).build().runWith(() -> {
        final Projects projects = projectService.list();
        assertEquals(5, projectService.list().getSize());
        assertFalse(projects.stream().anyMatch(project -> project.getName().toString().equals("test-project1")));
        assertTrue(projects.stream().anyMatch(project -> project.getName().equals(ProjectName.from(ContentConstants.CONTENT_REPO_ID))));
    });
}
Also used : NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) BeforeEach(org.junit.jupiter.api.BeforeEach) IdProviderKey(com.enonic.xp.security.IdProviderKey) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) SecurityAuditLogSupportImpl(com.enonic.xp.core.impl.security.SecurityAuditLogSupportImpl) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Permission(com.enonic.xp.security.acl.Permission) RepositoryId(com.enonic.xp.repository.RepositoryId) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ContextBuilder(com.enonic.xp.context.ContextBuilder) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) SystemConstants(com.enonic.xp.security.SystemConstants) ProjectPermissionsContextManagerImpl(com.enonic.xp.core.impl.project.ProjectPermissionsContextManagerImpl) CreateUserParams(com.enonic.xp.security.CreateUserParams) User(com.enonic.xp.security.User) Projects(com.enonic.xp.project.Projects) PrincipalRelationship(com.enonic.xp.security.PrincipalRelationship) Set(java.util.Set) Project(com.enonic.xp.project.Project) AccessControlList(com.enonic.xp.security.acl.AccessControlList) Collectors(java.util.stream.Collectors) CreateProjectParams(com.enonic.xp.project.CreateProjectParams) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.jupiter.api.Test) List(java.util.List) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) IndexServiceInternal(com.enonic.xp.repo.impl.index.IndexServiceInternal) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) ProjectServiceImpl(com.enonic.xp.core.impl.project.ProjectServiceImpl) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) Repository(com.enonic.xp.repository.Repository) Mockito.mock(org.mockito.Mockito.mock) SecurityServiceImpl(com.enonic.xp.core.impl.security.SecurityServiceImpl) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContentConstants(com.enonic.xp.content.ContentConstants) Node(com.enonic.xp.node.Node) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ProjectConstants(com.enonic.xp.project.ProjectConstants) ProjectRole(com.enonic.xp.project.ProjectRole) ProjectName(com.enonic.xp.project.ProjectName) ModifyProjectIconParams(com.enonic.xp.project.ModifyProjectIconParams) AuditLogService(com.enonic.xp.audit.AuditLogService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) ProjectGraph(com.enonic.xp.project.ProjectGraph) ProjectPermissions(com.enonic.xp.project.ProjectPermissions) InternalContext(com.enonic.xp.repo.impl.InternalContext) PropertySet(com.enonic.xp.data.PropertySet) NodePath(com.enonic.xp.node.NodePath) IOException(java.io.IOException) SecurityConfig(com.enonic.xp.core.impl.security.SecurityConfig) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Mockito.when(org.mockito.Mockito.when) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) PrincipalKey(com.enonic.xp.security.PrincipalKey) Assertions(org.junit.jupiter.api.Assertions) ProjectAccessException(com.enonic.xp.core.impl.project.ProjectAccessException) ProjectAccessHelper(com.enonic.xp.core.impl.project.ProjectAccessHelper) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) ModifyProjectParams(com.enonic.xp.project.ModifyProjectParams) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) Projects(com.enonic.xp.project.Projects) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

Project (com.enonic.xp.project.Project)31 Test (org.junit.jupiter.api.Test)19 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)18 ProjectName (com.enonic.xp.project.ProjectName)9 ProjectPermissions (com.enonic.xp.project.ProjectPermissions)9 RepositoryId (com.enonic.xp.repository.RepositoryId)9 CreateProjectParams (com.enonic.xp.project.CreateProjectParams)7 ModifyProjectParams (com.enonic.xp.project.ModifyProjectParams)7 Repository (com.enonic.xp.repository.Repository)7 Context (com.enonic.xp.context.Context)6 ContextBuilder (com.enonic.xp.context.ContextBuilder)6 ProjectGraph (com.enonic.xp.project.ProjectGraph)6 RoleKeys (com.enonic.xp.security.RoleKeys)6 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)6 ByteSource (com.google.common.io.ByteSource)6 IOException (java.io.IOException)6 UncheckedIOException (java.io.UncheckedIOException)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)5