Search in sources :

Example 1 with IDocumentService

use of org.eclipse.sirius.web.services.api.document.IDocumentService in project sirius-web by eclipse-sirius.

the class CreateDocumentEventHandlerTests method testCreateTwoDocumentWithSameName.

@Test
public void testCreateTwoDocumentWithSameName() {
    IDocumentService documentService = new IDocumentService.NoOp() {

        @Override
        public Optional<Document> createDocument(String projectId, String name, String content) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return Optional.of(new Document(UUID.randomUUID(), new Project(UUID.fromString(projectId), "", new Profile(UUID.randomUUID(), "username"), Visibility.PUBLIC), name, content));
        }
    };
    IStereotypeDescriptionService stereotypeDescriptionService = new IStereotypeDescriptionService.NoOp() {

        @Override
        public Optional<StereotypeDescription> getStereotypeDescriptionById(String editingContextId, UUID stereotypeId) {
            // $NON-NLS-1$
            StereotypeDescription stereotypeDescription = new StereotypeDescription(stereotypeId, "label", () -> CONTENT);
            return Optional.of(stereotypeDescription);
        }
    };
    IServicesMessageService messageService = new NoOpServicesMessageService();
    AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
    EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
    CreateDocumentEventHandler handler = new CreateDocumentEventHandler(documentService, stereotypeDescriptionService, messageService, new SimpleMeterRegistry());
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    changeDescriptionSink.asFlux().subscribe(changeDescription -> {
        assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
    });
    var firstCreateInput = new CreateDocumentInput(UUID.randomUUID(), editingContext.getId(), DOCUMENT_NAME, STEREOTYPE_DESCRIPTION_ID);
    assertThat(handler.canHandle(editingContext, firstCreateInput)).isTrue();
    One<IPayload> firstPayloadSink = Sinks.one();
    handler.handle(firstPayloadSink, changeDescriptionSink, editingContext, firstCreateInput);
    IPayload firstPayload = firstPayloadSink.asMono().block();
    assertThat(firstPayload).isInstanceOf(CreateDocumentSuccessPayload.class);
    var secondCreatedInput = new CreateDocumentInput(UUID.randomUUID(), editingContext.getId(), DOCUMENT_NAME, STEREOTYPE_DESCRIPTION_ID);
    assertThat(handler.canHandle(editingContext, secondCreatedInput)).isTrue();
    One<IPayload> secondPayloadSink = Sinks.one();
    handler.handle(secondPayloadSink, changeDescriptionSink, editingContext, secondCreatedInput);
    IPayload secondPayload = firstPayloadSink.asMono().block();
    assertThat(secondPayload).isInstanceOf(CreateDocumentSuccessPayload.class);
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) StereotypeDescription(org.eclipse.sirius.components.core.configuration.StereotypeDescription) IServicesMessageService(org.eclipse.sirius.web.services.messages.IServicesMessageService) NoOpServicesMessageService(org.eclipse.sirius.web.services.projects.NoOpServicesMessageService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IStereotypeDescriptionService(org.eclipse.sirius.web.services.api.stereotypes.IStereotypeDescriptionService) Document(org.eclipse.sirius.web.services.api.document.Document) 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) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) IDocumentService(org.eclipse.sirius.web.services.api.document.IDocumentService) UUID(java.util.UUID) CreateDocumentInput(org.eclipse.sirius.components.collaborative.dto.CreateDocumentInput) Test(org.junit.jupiter.api.Test)

Example 2 with IDocumentService

use of org.eclipse.sirius.web.services.api.document.IDocumentService in project sirius-web by eclipse-sirius.

the class CreateDocumentEventHandlerTests method testCreateDocument.

@Test
public void testCreateDocument() {
    IDocumentService documentService = new IDocumentService.NoOp() {

        @Override
        public Optional<Document> createDocument(String projectId, String name, String content) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return Optional.of(new Document(UUID.randomUUID(), new Project(UUID.fromString(projectId), "", new Profile(UUID.randomUUID(), "username"), Visibility.PUBLIC), name, content));
        }
    };
    IStereotypeDescriptionService stereotypeDescriptionService = new IStereotypeDescriptionService.NoOp() {

        @Override
        public Optional<StereotypeDescription> getStereotypeDescriptionById(String editingContextId, UUID stereotypeId) {
            // $NON-NLS-1$
            StereotypeDescription stereotypeDescription = new StereotypeDescription(stereotypeId, "label", () -> CONTENT);
            return Optional.of(stereotypeDescription);
        }
    };
    IServicesMessageService messageService = new NoOpServicesMessageService();
    CreateDocumentEventHandler handler = new CreateDocumentEventHandler(documentService, stereotypeDescriptionService, messageService, new SimpleMeterRegistry());
    var input = new CreateDocumentInput(UUID.randomUUID(), UUID.randomUUID().toString(), DOCUMENT_NAME, STEREOTYPE_DESCRIPTION_ID);
    AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
    EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    assertThat(handler.canHandle(editingContext, input)).isTrue();
    handler.handle(payloadSink, changeDescriptionSink, editingContext, input);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(CreateDocumentSuccessPayload.class);
    assertThat(editingDomain.getResourceSet().getResources().size()).isEqualTo(1);
    // $NON-NLS-1$
    Condition<Object> condition = new Condition<>(adapter -> adapter instanceof DocumentMetadataAdapter, "has an DocumentMetadataAdapter");
    assertThat(editingDomain.getResourceSet().getResources().get(0).eAdapters()).areAtLeastOne(condition);
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) NoOpServicesMessageService(org.eclipse.sirius.web.services.projects.NoOpServicesMessageService) IStereotypeDescriptionService(org.eclipse.sirius.web.services.api.stereotypes.IStereotypeDescriptionService) Document(org.eclipse.sirius.web.services.api.document.Document) Profile(org.eclipse.sirius.web.services.api.accounts.Profile) IPayload(org.eclipse.sirius.components.core.api.IPayload) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) UUID(java.util.UUID) CreateDocumentInput(org.eclipse.sirius.components.collaborative.dto.CreateDocumentInput) Condition(org.assertj.core.api.Condition) StereotypeDescription(org.eclipse.sirius.components.core.configuration.StereotypeDescription) IServicesMessageService(org.eclipse.sirius.web.services.messages.IServicesMessageService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Project(org.eclipse.sirius.web.services.api.projects.Project) IDocumentService(org.eclipse.sirius.web.services.api.document.IDocumentService) Test(org.junit.jupiter.api.Test)

Example 3 with IDocumentService

use of org.eclipse.sirius.web.services.api.document.IDocumentService in project sirius-web by eclipse-sirius.

the class RenameDocumentEventHandlerTests method testRenameDocument.

@Test
public void testRenameDocument() {
    IDocumentService noOpDocumentService = new IDocumentService.NoOp() {

        @Override
        public Optional<Document> rename(UUID documentId, String newName) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            return Optional.of(new Document(documentId, new Project(UUID.randomUUID(), "", new Profile(UUID.randomUUID(), "username"), Visibility.PUBLIC), newName, "noContent"));
        }
    };
    RenameDocumentEventHandler handler = new RenameDocumentEventHandler(noOpDocumentService, new NoOpServicesMessageService(), new SimpleMeterRegistry());
    UUID documentId = UUID.randomUUID();
    IInput input = new RenameDocumentInput(UUID.randomUUID(), documentId, NEW_NAME);
    AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
    DocumentMetadataAdapter adapter = new DocumentMetadataAdapter(OLD_NAME);
    Resource resource = new SiriusWebJSONResourceFactoryImpl().createResource(URI.createURI(documentId.toString()));
    resource.eAdapters().add(adapter);
    editingDomain.getResourceSet().getResources().add(resource);
    assertThat(editingDomain.getResourceSet().getResources().size()).isEqualTo(1);
    assertThat(adapter.getName()).isEqualTo(OLD_NAME);
    IEditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
    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(editingDomain.getResourceSet().getResources().size()).isEqualTo(1);
    assertThat(adapter.getName()).isEqualTo(NEW_NAME);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(RenameDocumentSuccessPayload.class);
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) NoOpServicesMessageService(org.eclipse.sirius.web.services.projects.NoOpServicesMessageService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) RenameDocumentInput(org.eclipse.sirius.components.collaborative.dto.RenameDocumentInput) Resource(org.eclipse.emf.ecore.resource.Resource) IInput(org.eclipse.sirius.components.core.api.IInput) Document(org.eclipse.sirius.web.services.api.document.Document) 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) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) SiriusWebJSONResourceFactoryImpl(org.eclipse.sirius.components.emf.services.SiriusWebJSONResourceFactoryImpl) IDocumentService(org.eclipse.sirius.web.services.api.document.IDocumentService) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 4 with IDocumentService

use of org.eclipse.sirius.web.services.api.document.IDocumentService in project sirius-web by eclipse-sirius.

the class DeleteDocumentEventHandlerTests method testDeleteDocument.

@Test
public void testDeleteDocument() {
    UUID projectId = UUID.randomUUID();
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    Document document = new Document(UUID.randomUUID(), new Project(projectId, "", new Profile(UUID.randomUUID(), "username"), Visibility.PUBLIC), "name", "content");
    IDocumentService documentService = new IDocumentService.NoOp() {

        @Override
        public Optional<Document> getDocument(UUID documentId) {
            return Optional.of(document);
        }
    };
    DeleteDocumentEventHandler handler = new DeleteDocumentEventHandler(documentService, new NoOpServicesMessageService(), new SimpleMeterRegistry());
    var input = new DeleteDocumentInput(UUID.randomUUID(), document.getId());
    AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
    Resource resource = new SiriusWebJSONResourceFactoryImpl().createResource(URI.createURI(document.getId().toString()));
    editingDomain.getResourceSet().getResources().add(resource);
    EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
    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(editingDomain.getResourceSet().getResources().size()).isEqualTo(0);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(DeleteDocumentSuccessPayload.class);
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) NoOpServicesMessageService(org.eclipse.sirius.web.services.projects.NoOpServicesMessageService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Resource(org.eclipse.emf.ecore.resource.Resource) Document(org.eclipse.sirius.web.services.api.document.Document) 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) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) SiriusWebJSONResourceFactoryImpl(org.eclipse.sirius.components.emf.services.SiriusWebJSONResourceFactoryImpl) UUID(java.util.UUID) IDocumentService(org.eclipse.sirius.web.services.api.document.IDocumentService) DeleteDocumentInput(org.eclipse.sirius.components.collaborative.dto.DeleteDocumentInput) Test(org.junit.jupiter.api.Test)

Example 5 with IDocumentService

use of org.eclipse.sirius.web.services.api.document.IDocumentService in project sirius-web by eclipse-sirius.

the class UploadDocumentEventHandlerTests method simulatesDocumentUpload.

/**
 * Simulates a document upload with fake services. The uploaded resource will be put in the given editing domain
 * with the documentId as URI.
 *
 * @param editingDomain
 *            The editing domain where the uploaded resource will be put
 * @param documentId
 *            The id of the document to upload
 * @param resourceBytes
 *            The content of the document to upload
 */
private void simulatesDocumentUpload(AdapterFactoryEditingDomain editingDomain, UUID documentId, byte[] resourceBytes) {
    IDocumentService documentService = new IDocumentService.NoOp() {

        @Override
        public Optional<Document> createDocument(String projectId, String name, String content) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return Optional.of(new Document(documentId, new Project(UUID.fromString(projectId), "", new Profile(UUID.randomUUID(), "username"), Visibility.PUBLIC), name, content));
        }
    };
    IServicesMessageService messageService = new NoOpServicesMessageService();
    UploadDocumentEventHandler handler = new UploadDocumentEventHandler(documentService, messageService, new SimpleMeterRegistry());
    UploadFile file = new UploadFile(FILE_NAME, new ByteArrayInputStream(resourceBytes));
    var input = new UploadDocumentInput(UUID.randomUUID(), UUID.randomUUID().toString(), file);
    IEditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    assertThat(handler.canHandle(editingContext, input)).isTrue();
    handler.handle(payloadSink, changeDescriptionSink, editingContext, input);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(UploadDocumentSuccessPayload.class);
}
Also used : IServicesMessageService(org.eclipse.sirius.web.services.messages.IServicesMessageService) NoOpServicesMessageService(org.eclipse.sirius.web.services.projects.NoOpServicesMessageService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Document(org.eclipse.sirius.web.services.api.document.Document) 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) UploadDocumentInput(org.eclipse.sirius.web.services.api.document.UploadDocumentInput) UploadFile(org.eclipse.sirius.components.graphql.api.UploadFile) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) ByteArrayInputStream(java.io.ByteArrayInputStream) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) IDocumentService(org.eclipse.sirius.web.services.api.document.IDocumentService)

Aggregations

IDocumentService (org.eclipse.sirius.web.services.api.document.IDocumentService)8 Profile (org.eclipse.sirius.web.services.api.accounts.Profile)7 Document (org.eclipse.sirius.web.services.api.document.Document)7 Project (org.eclipse.sirius.web.services.api.projects.Project)7 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)6 UUID (java.util.UUID)6 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)6 IPayload (org.eclipse.sirius.components.core.api.IPayload)6 EditingContext (org.eclipse.sirius.components.emf.services.EditingContext)6 NoOpServicesMessageService (org.eclipse.sirius.web.services.projects.NoOpServicesMessageService)6 Test (org.junit.jupiter.api.Test)6 AdapterFactoryEditingDomain (org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain)5 IServicesMessageService (org.eclipse.sirius.web.services.messages.IServicesMessageService)4 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)3 Resource (org.eclipse.emf.ecore.resource.Resource)2 CreateDocumentInput (org.eclipse.sirius.components.collaborative.dto.CreateDocumentInput)2 StereotypeDescription (org.eclipse.sirius.components.core.configuration.StereotypeDescription)2 SiriusWebJSONResourceFactoryImpl (org.eclipse.sirius.components.emf.services.SiriusWebJSONResourceFactoryImpl)2 UploadFile (org.eclipse.sirius.components.graphql.api.UploadFile)2 UploadDocumentInput (org.eclipse.sirius.web.services.api.document.UploadDocumentInput)2