use of org.eclipse.sirius.components.emf.services.IEditingContextEPackageService in project sirius-components by eclipse-sirius.
the class EMFQueryServiceTests method testEMFQueryServiceContents.
@Test
public void testEMFQueryServiceContents() {
IEditingContext editingContext = this.createEditingContext();
IEditingContextEPackageService editingContextEPackageService = new IEditingContextEPackageService() {
@Override
public List<EPackage> getEPackages(String editingContextId) {
return List.of(EcorePackage.eINSTANCE);
}
};
IQueryService queryService = new EMFQueryService(editingContextEPackageService, List.of());
// $NON-NLS-1$
QueryBasedIntInput input = new QueryBasedIntInput(UUID.randomUUID(), "aql:editingContext.contents()->size()", Map.of());
IPayload payload = queryService.execute(editingContext, input);
assertTrue(payload instanceof QueryBasedIntSuccessPayload);
assertEquals(2, ((QueryBasedIntSuccessPayload) payload).getResult());
}
use of org.eclipse.sirius.components.emf.services.IEditingContextEPackageService 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.components.emf.services.IEditingContextEPackageService 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.components.emf.services.IEditingContextEPackageService in project sirius-components by eclipse-sirius.
the class EMFQueryServiceTests method testEMFQueryServiceAllContents.
@Test
public void testEMFQueryServiceAllContents() {
IEditingContext editingContext = this.createEditingContext();
IEditingContextEPackageService editingContextEPackageService = new IEditingContextEPackageService() {
@Override
public List<EPackage> getEPackages(String editingContextId) {
return List.of(EcorePackage.eINSTANCE);
}
};
IQueryService queryService = new EMFQueryService(editingContextEPackageService, List.of());
// $NON-NLS-1$
QueryBasedIntInput input = new QueryBasedIntInput(UUID.randomUUID(), "aql:editingContext.allContents()->size()", Map.of());
IPayload payload = queryService.execute(editingContext, input);
assertTrue(payload instanceof QueryBasedIntSuccessPayload);
assertEquals(8, ((QueryBasedIntSuccessPayload) payload).getResult());
}
use of org.eclipse.sirius.components.emf.services.IEditingContextEPackageService in project sirius-components by eclipse-sirius.
the class EMFQueryServiceTests method testEMFQueryServiceGetObjectById.
@Test
public void testEMFQueryServiceGetObjectById() {
EditingContext editingContext = this.createEditingContext();
IEditingContextEPackageService editingContextEPackageService = new IEditingContextEPackageService() {
@Override
public List<EPackage> getEPackages(String editingContextId) {
return List.of(EcorePackage.eINSTANCE);
}
};
IQueryService queryService = new EMFQueryService(editingContextEPackageService, List.of());
// @formatter:off
EObject eObjectToRetrieve = editingContext.getDomain().getResourceSet().getResources().get(0).getContents().get(0);
Optional<IDAdapter> optionalIDAdapter = eObjectToRetrieve.eAdapters().stream().filter(IDAdapter.class::isInstance).map(IDAdapter.class::cast).findFirst();
// $NON-NLS-1$
String id = optionalIDAdapter.map(IDAdapter::getId).map(Object::toString).orElse("");
// @formatter:on
// $NON-NLS-1$ //$NON-NLS-2$
QueryBasedObjectInput input = new QueryBasedObjectInput(UUID.randomUUID(), "aql:editingContext.getObjectById('" + id + "')", Map.of());
IPayload payload = queryService.execute(editingContext, input);
assertTrue(payload instanceof QueryBasedObjectSuccessPayload);
assertEquals(eObjectToRetrieve, ((QueryBasedObjectSuccessPayload) payload).getResult());
// $NON-NLS-1$ //$NON-NLS-2$
input = new QueryBasedObjectInput(UUID.randomUUID(), "aql:editingContext.getObjectById('" + id + "wrong')", Map.of());
payload = queryService.execute(editingContext, input);
assertTrue(payload instanceof ErrorPayload);
}
Aggregations