use of org.eclipse.sirius.components.core.api.IEditingContextPersistenceService 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