Search in sources :

Example 1 with IProjectService

use of org.eclipse.sirius.web.services.api.projects.IProjectService in project sirius-web by eclipse-sirius.

the class RenameProjectEventHandlerTests method testRenameProject.

@Test
public void testRenameProject() {
    // $NON-NLS-1$ //$NON-NLS-2$
    Project project = new Project(UUID.randomUUID(), "newName", new Profile(UUID.randomUUID(), "system"), Visibility.PUBLIC);
    AtomicBoolean hasBeenCalled = new AtomicBoolean();
    IProjectService projectService = new IProjectService.NoOp() {

        @Override
        public Optional<Project> renameProject(UUID projectId, String newName) {
            hasBeenCalled.set(true);
            return Optional.of(project);
        }
    };
    RenameProjectEventHandler handler = new RenameProjectEventHandler(new NoOpServicesMessageService(), projectService);
    // $NON-NLS-1$
    var input = new RenameProjectInput(UUID.randomUUID(), UUID.randomUUID(), "newName");
    IEditingContext editingContext = () -> UUID.randomUUID().toString();
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    assertThat(handler.canHandle(editingContext, input)).isTrue();
    handler.handle(payloadSink, changeDescriptionSink, editingContext, input);
    assertThat(hasBeenCalled.get()).isTrue();
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.PROJECT_RENAMING);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(RenameProjectSuccessPayload.class);
}
Also used : IProjectService(org.eclipse.sirius.web.services.api.projects.IProjectService) RenameProjectInput(org.eclipse.sirius.web.services.api.projects.RenameProjectInput) Profile(org.eclipse.sirius.web.services.api.accounts.Profile) IPayload(org.eclipse.sirius.components.core.api.IPayload) Project(org.eclipse.sirius.web.services.api.projects.Project) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 2 with IProjectService

use of org.eclipse.sirius.web.services.api.projects.IProjectService in project sirius-web by eclipse-sirius.

the class ProjectControllerTests method testProjectDoesNotExist.

@Test
public void testProjectDoesNotExist() {
    IProjectService projectService = new IProjectService.NoOp();
    IProjectExportService projectExportService = new IProjectExportService.NoOp();
    ProjectController projectController = new ProjectController(projectService, projectExportService);
    // $NON-NLS-1$
    String projectId = "631fcb2d-3463-4084-b5da-fd8022ebae53";
    ResponseEntity<Resource> responseEntity = projectController.getProject(UUID.fromString(projectId));
    assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
Also used : IProjectService(org.eclipse.sirius.web.services.api.projects.IProjectService) Resource(org.springframework.core.io.Resource) IProjectExportService(org.eclipse.sirius.web.services.api.projects.IProjectExportService) Test(org.junit.jupiter.api.Test)

Example 3 with IProjectService

use of org.eclipse.sirius.web.services.api.projects.IProjectService in project sirius-web by eclipse-sirius.

the class ProjectControllerTests method testProjectExists.

@Test
public void testProjectExists() {
    // $NON-NLS-1$
    String projectFoundId = "631fcb2d-3463-4084-b5da-fd8022ebae53";
    IProjectService projectService = new IProjectService.NoOp() {

        @Override
        public Optional<Project> getProject(UUID projectId) {
            // $NON-NLS-1$
            return Optional.of(new Project(UUID.fromString(projectFoundId), projectFoundId, new Profile(UUID.randomUUID(), "username"), Visibility.PUBLIC));
        }
    };
    IProjectExportService projectExportService = new IProjectExportService.NoOp();
    ProjectController projectController = new ProjectController(projectService, projectExportService);
    ResponseEntity<Resource> responseEntity = projectController.getProject(UUID.fromString(projectFoundId));
    assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
    HttpHeaders headers = responseEntity.getHeaders();
    // $NON-NLS-1$
    assertThat(headers.getContentType()).isEqualTo(MediaType.parseMediaType("application/zip"));
    assertThat(headers.getContentLength()).isEqualTo(0);
    // $NON-NLS-1$
    assertThat(headers.getContentDisposition().getFilename()).isEqualTo(projectFoundId + ".zip");
}
Also used : Project(org.eclipse.sirius.web.services.api.projects.Project) HttpHeaders(org.springframework.http.HttpHeaders) IProjectService(org.eclipse.sirius.web.services.api.projects.IProjectService) Resource(org.springframework.core.io.Resource) IProjectExportService(org.eclipse.sirius.web.services.api.projects.IProjectExportService) UUID(java.util.UUID) Profile(org.eclipse.sirius.web.services.api.accounts.Profile) Test(org.junit.jupiter.api.Test)

Aggregations

IProjectService (org.eclipse.sirius.web.services.api.projects.IProjectService)3 Test (org.junit.jupiter.api.Test)3 UUID (java.util.UUID)2 Profile (org.eclipse.sirius.web.services.api.accounts.Profile)2 IProjectExportService (org.eclipse.sirius.web.services.api.projects.IProjectExportService)2 Project (org.eclipse.sirius.web.services.api.projects.Project)2 Resource (org.springframework.core.io.Resource)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)1 IPayload (org.eclipse.sirius.components.core.api.IPayload)1 RenameProjectInput (org.eclipse.sirius.web.services.api.projects.RenameProjectInput)1 HttpHeaders (org.springframework.http.HttpHeaders)1