Search in sources :

Example 1 with IDocumentRepository

use of org.eclipse.sirius.web.persistence.repositories.IDocumentRepository in project sirius-web by eclipse-sirius.

the class EditingContextSearchServiceTests method testEditingContextWithNoDocuments.

// @formatter:on
@Test
public void testEditingContextWithNoDocuments() {
    IProjectRepository projectRepository = new NoOpProjectRepository();
    IDocumentRepository documentRepository = new NoOpDocumentRepository();
    ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory();
    EPackage.Registry ePackageRegistry = new EPackageRegistryImpl();
    ePackageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
    String projectId = UUID.randomUUID().toString();
    IEditingContextEPackageService editingContextEPackageService = editingContextId -> List.of();
    IEditingContextSearchService editingContextSearchService = new EditingContextSearchService(projectRepository, documentRepository, editingContextEPackageService, composedAdapterFactory, ePackageRegistry, new SimpleMeterRegistry());
    IEditingContext editingContext = editingContextSearchService.findById(projectId).get();
    assertThat(editingContext).isInstanceOf(EditingContext.class);
    EditingDomain editingDomain = ((EditingContext) editingContext).getDomain();
    assertThat(editingDomain.getResourceSet().getResources()).hasSize(0);
}
Also used : IProjectRepository(org.eclipse.sirius.web.persistence.repositories.IProjectRepository) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) DocumentMetadataAdapter(org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter) URI(org.eclipse.emf.common.util.URI) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) EcorePackage(org.eclipse.emf.ecore.EcorePackage) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UUID(java.util.UUID) IProjectRepository(org.eclipse.sirius.web.persistence.repositories.IProjectRepository) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) EPackage(org.eclipse.emf.ecore.EPackage) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) Test(org.junit.jupiter.api.Test) List(java.util.List) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) Resource(org.eclipse.emf.ecore.resource.Resource) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) EPackage(org.eclipse.emf.ecore.EPackage) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) Test(org.junit.jupiter.api.Test)

Example 2 with IDocumentRepository

use of org.eclipse.sirius.web.persistence.repositories.IDocumentRepository in project sirius-web by eclipse-sirius.

the class EditingContextSearchServiceTests method testEditingContextWithDocuments.

@Test
public void testEditingContextWithDocuments() {
    UUID projectId = UUID.randomUUID();
    ProjectEntity projectEntity = new ProjectEntity();
    projectEntity.setId(projectId);
    // $NON-NLS-1$
    projectEntity.setName("");
    DocumentEntity firstDocumentEntity = new DocumentEntity();
    firstDocumentEntity.setId(UUID.randomUUID());
    // $NON-NLS-1$
    firstDocumentEntity.setName("First Document");
    firstDocumentEntity.setProject(projectEntity);
    firstDocumentEntity.setContent(CONTENT);
    DocumentEntity secondDocumentEntity = new DocumentEntity();
    secondDocumentEntity.setId(UUID.randomUUID());
    // $NON-NLS-1$
    secondDocumentEntity.setName("Second Document");
    secondDocumentEntity.setProject(projectEntity);
    secondDocumentEntity.setContent(CONTENT);
    IProjectRepository projectRepository = new NoOpProjectRepository();
    IDocumentRepository documentRepository = new NoOpDocumentRepository() {

        @Override
        public List<DocumentEntity> findAllByProjectId(UUID projectId) {
            return List.of(firstDocumentEntity, secondDocumentEntity);
        }
    };
    ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory();
    EPackage.Registry ePackageRegistry = new EPackageRegistryImpl();
    ePackageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
    IEditingContextEPackageService editingContextEPackageService = editingContextId -> List.of();
    IEditingContextSearchService editingContextSearchService = new EditingContextSearchService(projectRepository, documentRepository, editingContextEPackageService, composedAdapterFactory, ePackageRegistry, new SimpleMeterRegistry());
    IEditingContext editingContext = editingContextSearchService.findById(projectId.toString()).get();
    assertThat(editingContext).isInstanceOf(EditingContext.class);
    EditingDomain editingDomain = ((EditingContext) editingContext).getDomain();
    assertThat(editingDomain.getResourceSet().getResources()).hasSize(2);
    Resource firstResource = editingDomain.getResourceSet().getResource(URI.createURI(firstDocumentEntity.getId().toString()), true);
    this.assertProperResourceLoading(firstResource, firstDocumentEntity);
    Resource secondResource = editingDomain.getResourceSet().getResource(URI.createURI(secondDocumentEntity.getId().toString()), true);
    this.assertProperResourceLoading(secondResource, secondDocumentEntity);
}
Also used : IProjectRepository(org.eclipse.sirius.web.persistence.repositories.IProjectRepository) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) DocumentMetadataAdapter(org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter) URI(org.eclipse.emf.common.util.URI) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) EcorePackage(org.eclipse.emf.ecore.EcorePackage) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UUID(java.util.UUID) IProjectRepository(org.eclipse.sirius.web.persistence.repositories.IProjectRepository) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) EPackage(org.eclipse.emf.ecore.EPackage) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) Test(org.junit.jupiter.api.Test) List(java.util.List) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) Resource(org.eclipse.emf.ecore.resource.Resource) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Resource(org.eclipse.emf.ecore.resource.Resource) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) EPackage(org.eclipse.emf.ecore.EPackage) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 3 with IDocumentRepository

use of org.eclipse.sirius.web.persistence.repositories.IDocumentRepository in project sirius-web by eclipse-sirius.

the class EditingContextPersistenceServiceTests method testDocumentPersistence.

@Test
public void testDocumentPersistence() {
    UUID projectId = UUID.randomUUID();
    // $NON-NLS-1$
    String name = "New Document";
    UUID id = UUID.randomUUID();
    JsonResource resource = new SiriusWebJSONResourceFactoryImpl().createResource(URI.createURI(id.toString()));
    resource.eAdapters().add(new DocumentMetadataAdapter(name));
    EClass eClass = EcoreFactory.eINSTANCE.createEClass();
    // $NON-NLS-1$
    eClass.setName("Concept");
    resource.getContents().add(eClass);
    AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
    editingDomain.getResourceSet().getResources().add(resource);
    ProjectEntity projectEntity = new ProjectEntity();
    projectEntity.setId(projectId);
    // $NON-NLS-1$
    projectEntity.setName("");
    AccountEntity owner = new AccountEntity();
    owner.setId(UUID.randomUUID());
    // $NON-NLS-1$
    owner.setUsername("jdoe");
    projectEntity.setOwner(owner);
    DocumentEntity existingEntity = new DocumentEntity();
    existingEntity.setId(id);
    existingEntity.setProject(projectEntity);
    existingEntity.setName(name);
    // $NON-NLS-1$
    existingEntity.setContent("");
    List<DocumentEntity> entities = new ArrayList<>();
    IDocumentRepository documentRepository = new NoOpDocumentRepository() {

        @Override
        public <S extends DocumentEntity> S save(S entity) {
            entities.add(entity);
            return entity;
        }

        @Override
        public Optional<DocumentEntity> findById(UUID id) {
            return Optional.of(existingEntity);
        }
    };
    IEditingContextPersistenceService editingContextPersistenceService = new EditingContextPersistenceService(documentRepository, new NoOpApplicationEventPublisher(), new SimpleMeterRegistry());
    assertThat(entities).hasSize(0);
    IEditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
    editingContextPersistenceService.persist(editingContext);
    assertThat(entities).hasSize(1);
    DocumentEntity documentEntity = entities.get(0);
    assertThat(documentEntity.getId()).isEqualTo(id);
    assertThat(documentEntity.getName()).isEqualTo(name);
    assertThat(documentEntity.getProject().getId()).isEqualTo(projectId);
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) DocumentMetadataAdapter(org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ArrayList(java.util.ArrayList) JsonResource(org.eclipse.sirius.emfjson.resource.JsonResource) IEditingContextPersistenceService(org.eclipse.sirius.components.core.api.IEditingContextPersistenceService) AccountEntity(org.eclipse.sirius.web.persistence.entities.AccountEntity) EClass(org.eclipse.emf.ecore.EClass) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) IEditingContextPersistenceService(org.eclipse.sirius.components.core.api.IEditingContextPersistenceService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) SiriusWebJSONResourceFactoryImpl(org.eclipse.sirius.components.emf.services.SiriusWebJSONResourceFactoryImpl) UUID(java.util.UUID) EditingDomainFactory(org.eclipse.sirius.web.services.documents.EditingDomainFactory) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)3 UUID (java.util.UUID)3 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)3 EditingContext (org.eclipse.sirius.components.emf.services.EditingContext)3 DocumentEntity (org.eclipse.sirius.web.persistence.entities.DocumentEntity)3 ProjectEntity (org.eclipse.sirius.web.persistence.entities.ProjectEntity)3 IDocumentRepository (org.eclipse.sirius.web.persistence.repositories.IDocumentRepository)3 DocumentMetadataAdapter (org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter)3 Test (org.junit.jupiter.api.Test)3 List (java.util.List)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 URI (org.eclipse.emf.common.util.URI)2 EPackage (org.eclipse.emf.ecore.EPackage)2 EcorePackage (org.eclipse.emf.ecore.EcorePackage)2 EPackageRegistryImpl (org.eclipse.emf.ecore.impl.EPackageRegistryImpl)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ECrossReferenceAdapter (org.eclipse.emf.ecore.util.ECrossReferenceAdapter)2 EditingDomain (org.eclipse.emf.edit.domain.EditingDomain)2 ComposedAdapterFactory (org.eclipse.emf.edit.provider.ComposedAdapterFactory)2 IEditingContextSearchService (org.eclipse.sirius.components.core.api.IEditingContextSearchService)2