Search in sources :

Example 21 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 22 with Project

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

the class ProjectServiceImplTest method modify_icon.

@Test
void modify_icon() {
    doCreateProjectAsAdmin(ProjectName.from("test-project"));
    adminContext().runWith(() -> {
        projectService.modifyIcon(ModifyProjectIconParams.create().name(ProjectName.from("test-project")).icon(CreateAttachment.create().mimeType("image/png").label("My New Image").name("MyNewImage.png").byteSource(ByteSource.wrap("new bytes".getBytes())).build()).scaleWidth(0).build());
        Project modifiedProject = projectService.get(ProjectName.from("test-project"));
        assertEquals("image/png", modifiedProject.getIcon().getMimeType());
        assertEquals("My New Image", modifiedProject.getIcon().getLabel());
        assertEquals("MyNewImage.png", modifiedProject.getIcon().getName());
        projectService.modifyIcon(ModifyProjectIconParams.create().name(ProjectName.from("test-project")).icon(null).scaleWidth(0).build());
        modifiedProject = projectService.get(ProjectName.from("test-project"));
        assertNull(modifiedProject.getIcon());
    });
}
Also used : Project(com.enonic.xp.project.Project) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 23 with Project

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

the class ProjectServiceImplTest method get_with_custom_permissions.

@Test
void get_with_custom_permissions() {
    final Project createdProject = doCreateProjectAsAdmin(ProjectName.from("test-project"));
    contentCustomManagerContext().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 24 with Project

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

the class ProjectServiceImplTest method get_with_manager_permissions.

@Test
void get_with_manager_permissions() {
    final Project createdProject = doCreateProjectAsAdmin(ProjectName.from("test-project"));
    contentManagerContext().runWith(() -> {
        final RuntimeException ex = Assertions.assertThrows(RuntimeException.class, () -> projectService.get(createdProject.getName()));
        assertEquals("Denied [user:system:repo-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)

Example 25 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) 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) 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