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()));
}
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());
});
}
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()));
});
}
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());
});
}
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))));
});
}
Aggregations