use of org.eclipse.sirius.web.services.api.accounts.Profile 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);
}
use of org.eclipse.sirius.web.services.api.accounts.Profile 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);
}
use of org.eclipse.sirius.web.services.api.accounts.Profile 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);
}
use of org.eclipse.sirius.web.services.api.accounts.Profile 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);
}
use of org.eclipse.sirius.web.services.api.accounts.Profile in project sirius-web by eclipse-sirius.
the class DocumentMapper method toDTO.
public Document toDTO(DocumentEntity documentEntity) {
ProjectEntity projectEntity = documentEntity.getProject();
var profile = new Profile(projectEntity.getOwner().getId(), projectEntity.getOwner().getUsername());
var visibility = Visibility.valueOf(projectEntity.getVisibility().name());
Project project = new Project(projectEntity.getId(), projectEntity.getName(), profile, visibility);
return new Document(documentEntity.getId(), project, documentEntity.getName(), documentEntity.getContent());
}
Aggregations