Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian W. Damus2016-01-28 10:06:14 -0500
committerGerrit Code Review @ Eclipse.org2016-01-29 11:52:21 -0500
commit8d95235d0b3d9c15ff4c824c8bda35ff63528813 (patch)
tree0143d78f33b5df0b4517e511105c29e8a40161fe /tests
parent0e9c200139b99bb0825d52ff87ce962571c5bc6e (diff)
downloadorg.eclipse.papyrus-8d95235d0b3d9c15ff4c824c8bda35ff63528813.tar.gz
org.eclipse.papyrus-8d95235d0b3d9c15ff4c824c8bda35ff63528813.tar.xz
org.eclipse.papyrus-8d95235d0b3d9c15ff4c824c8bda35ff63528813.zip
Bug 486834: Language service doesn't understand new resources
https://bugs.eclipse.org/bugs/show_bug.cgi?id=486834 A resource that is new (such as in the New Model Wizard) cannot provide a content-type via its persisted state because that doesn't yet exist, so it is necessary to infer (as much as possible) a content-type from the in-memory state. This also introduces a cache by schema that can help to avoid the cost of accessing persisted content redundantly for the purpose of descibing the content.
Diffstat (limited to 'tests')
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/language/LanguageServiceTest.java67
1 files changed, 66 insertions, 1 deletions
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/language/LanguageServiceTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/language/LanguageServiceTest.java
index d332faeb09f..3530a06d78e 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/language/LanguageServiceTest.java
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/language/LanguageServiceTest.java
@@ -13,6 +13,7 @@
package org.eclipse.papyrus.infra.core.language;
+import static java.util.stream.StreamSupport.stream;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
@@ -20,17 +21,34 @@ import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.Collection;
-
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.infra.core.Activator;
import org.eclipse.papyrus.infra.core.internal.language.LanguageModelRegistry;
+import org.eclipse.papyrus.infra.core.resource.IEMFModel;
import org.eclipse.papyrus.infra.core.resource.IModel;
+import org.eclipse.papyrus.infra.core.resource.ModelMultiException;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.services.ExtensionServicesRegistry;
import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServiceMultiException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.TransactionHelper;
import org.eclipse.papyrus.junit.utils.resources.EcoreModel;
+import org.eclipse.papyrus.junit.utils.rules.HouseKeeper;
import org.eclipse.papyrus.junit.utils.rules.ModelSetFixture;
import org.eclipse.papyrus.junit.utils.rules.PluginResource;
import org.eclipse.papyrus.junit.utils.rules.ServiceRegistryModelSetFixture;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
/**
@@ -51,6 +69,9 @@ public class LanguageServiceTest {
private static IModel ecoreModel;
+ @Rule
+ public final HouseKeeper houseKeeper = new HouseKeeper();
+
public LanguageServiceTest() {
super();
}
@@ -106,6 +127,50 @@ public class LanguageServiceTest {
assertThat(models, hasItem(ecoreModel));
}
+ @Test
+ public void contentBasedLanguagesInNewModel() throws Exception {
+ ServicesRegistry services = houseKeeper.cleanUpLater(new ExtensionServicesRegistry(Activator.PLUGIN_ID), reg -> {
+ try {
+ reg.disposeRegistry();
+ } catch (ServiceMultiException e) {
+ // We expect these in the tests
+ }
+ });
+
+ try {
+ services.startRegistry();
+ } catch (ServiceMultiException e) {
+ // These are normal
+ }
+
+ ModelSet modelSet = services.getService(ModelSet.class);
+
+ IEMFModel ecore = new EcoreModel();
+ modelSet.registerModel(ecore);
+
+ URI uri = URI.createURI("platform:/resource/test/bogus.ecore", true);
+ EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
+ Resource resource = modelSet.createResource(uri);
+
+ TransactionHelper.run(modelSet.getTransactionalEditingDomain(), () -> {
+ resource.getContents().add(ePackage);
+ });
+
+ try {
+ modelSet.loadModels(uri);
+ } catch (ModelMultiException e) {
+ // We expect this
+ }
+
+ List<EObject> semanticRoots = ILanguageService.getLanguageModels(modelSet).stream()
+ .filter(IEMFModel.class::isInstance)
+ .map(IEMFModel.class::cast)
+ .flatMap(m -> stream(m.getRootElements().spliterator(), false))
+ .collect(Collectors.toList());
+
+ assertThat(semanticRoots, hasItem(ePackage));
+ }
+
//
// Test framework
//

Back to the top