Search in sources :

Example 16 with Project

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

the class ProjectServiceImplTest method list_with_content_manager_permissions.

@Test
void list_with_content_manager_permissions() {
    doCreateProjectAsAdmin(ProjectName.from("test-project1"));
    contentManagerContext().runWith(() -> {
        final Projects projects = projectService.list();
        assertEquals(1, projects.getSize());
        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) 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) 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) 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) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Mockito.when(org.mockito.Mockito.when) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Mockito(org.mockito.Mockito) 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) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 17 with Project

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

the class ProjectServiceImplTest method modify.

@Test
void modify() {
    doCreateProjectAsAdmin(ProjectName.from("test-project"));
    adminContext().runWith(() -> {
        projectService.modify(ModifyProjectParams.create().name(ProjectName.from("test-project")).description("new description").displayName("new display name").build());
        final Project modifiedProject = projectService.get(ProjectName.from("test-project"));
        assertEquals("new description", modifiedProject.getDescription());
        assertEquals("new display name", modifiedProject.getDisplayName());
    });
}
Also used : Project(com.enonic.xp.project.Project) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 18 with Project

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

the class ProjectServiceImplTest method get_empty_default_project_data.

@Test
void get_empty_default_project_data() {
    adminContext().runWith(() -> {
        final Project pro = projectService.get(ProjectName.from(ContentConstants.CONTENT_REPO_ID));
        assertEquals(ProjectConstants.DEFAULT_PROJECT.getDescription(), pro.getDescription());
        assertEquals(ProjectConstants.DEFAULT_PROJECT.getDisplayName(), pro.getDisplayName());
        assertEquals(ProjectConstants.DEFAULT_PROJECT.getIcon(), pro.getIcon());
        assertEquals(ProjectConstants.DEFAULT_PROJECT.getParent(), pro.getParent());
    });
}
Also used : Project(com.enonic.xp.project.Project) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 19 with Project

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

the class ProjectServiceImplTest method list_with_content_admin_permissions.

@Test
void list_with_content_admin_permissions() {
    doCreateProjectAsAdmin(ProjectName.from("test-project1"));
    doCreateProjectAsAdmin(ProjectName.from("test-project2"));
    doCreateProjectAsAdmin(ProjectName.from("test-project3"));
    contentAdminContext().runWith(() -> {
        final Projects projects = projectService.list();
        assertEquals(4, projects.getSize());
        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) 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) 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) 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) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Mockito.when(org.mockito.Mockito.when) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Mockito(org.mockito.Mockito) 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) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 20 with Project

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

the class ProjectServiceImplTest method get_without_permissions.

@Test
void get_without_permissions() {
    final Project createdProject = doCreateProjectAsAdmin(ProjectName.from("test-project"));
    final RuntimeException ex = Assertions.assertThrows(RuntimeException.class, () -> projectService.get(createdProject.getName()));
    assertEquals("Denied [user:system:test-user] user access to [test-project] project for [get] operation", ex.getMessage());
}
Also used : Project(com.enonic.xp.project.Project) 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