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