Skip to main content
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoreperico2010-07-01 11:52:35 +0000
committereperico2010-07-01 11:52:35 +0000
commit733a71355bedd139527816dc3e9dcb46444d2225 (patch)
treee1b5df11062170bdd3d5227ef39e5de03561162f /tests
parent322f38dde3b7600d057aa8f64e90d381df3236b0 (diff)
downloadorg.eclipse.papyrus-733a71355bedd139527816dc3e9dcb46444d2225.tar.gz
org.eclipse.papyrus-733a71355bedd139527816dc3e9dcb46444d2225.tar.xz
org.eclipse.papyrus-733a71355bedd139527816dc3e9dcb46444d2225.zip
NEW - bug 311149: [General] Manage several strategies for model loading
https://bugs.eclipse.org/bugs/show_bug.cgi?id=311149 -> add junit tests
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/AllTests.java2
-rw-r--r--tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/testModel1/AbstractResourceLoadingTestModel1.java42
-rw-r--r--tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/testModel2/AbstractResourceLoadingTestModel2.java95
3 files changed, 94 insertions, 45 deletions
diff --git a/tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/AllTests.java b/tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/AllTests.java
index 9af9b8de077..d2eb18d630b 100644
--- a/tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/AllTests.java
+++ b/tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/AllTests.java
@@ -28,7 +28,7 @@ public class AllTests {
public static Test suite()
{
- TestSuite suite = new TestSuite("Test for org.eclipse.papyrus.core");
+ TestSuite suite = new TestSuite("Test for org.eclipse.papyrus.core.resourceloading");
//$JUnit-BEGIN$
// Test suite for TestModel1
suite.addTestSuite(Strategy0TestModel1.class);
diff --git a/tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/testModel1/AbstractResourceLoadingTestModel1.java b/tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/testModel1/AbstractResourceLoadingTestModel1.java
index 5fe167d5f87..9f57a26a63c 100644
--- a/tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/testModel1/AbstractResourceLoadingTestModel1.java
+++ b/tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/testModel1/AbstractResourceLoadingTestModel1.java
@@ -86,30 +86,30 @@ public abstract class AbstractResourceLoadingTestModel1 extends TestCase {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("org.eclipse.papyrus.core.test");
IProgressMonitor monitor = new NullProgressMonitor();
- if(!project.exists()) {
+ if(project != null && !project.exists()) {
project.create(monitor);
- project.open(monitor);
- for(String res : resources) {
- for(String s : extensions) {
- IFile file = project.getFile(INITIAL_PATH + res + s);
- // link all the models resources
- if(!file.exists()) {
- createFolder(project, "resources/");
- createFolder(project, INITIAL_PATH);
- URL url = FileLocator.find(Activator.getDefault().getBundle(), new Path(INITIAL_PATH + res + s), null);
- URL newFile = FileLocator.resolve(url);
- file.createLink(newFile.toURI(), IResource.REPLACE, monitor);
- }
+ }
+ project.open(monitor);
+ for(String res : resources) {
+ for(String s : extensions) {
+ IFile file = project.getFile(INITIAL_PATH + res + s);
+ // link all the models resources
+ if(!file.exists()) {
+ createFolder(project, "resources/");
+ createFolder(project, INITIAL_PATH);
+ URL url = FileLocator.find(Activator.getDefault().getBundle(), new Path(INITIAL_PATH + res + s), null);
+ URL newFile = FileLocator.resolve(url);
+ file.createLink(newFile.toURI(), IResource.REPLACE, monitor);
}
}
- // link the profile
- String profilePath = INITIAL_PATH + "MyProfile.uml";
- IFile file = project.getFile(profilePath);
- if(!file.exists()) {
- URL url = FileLocator.find(Activator.getDefault().getBundle(), new Path(profilePath), null);
- URL newFile = FileLocator.resolve(url);
- file.createLink(newFile.toURI(), IResource.REPLACE, monitor);
- }
+ }
+ // link the profile
+ String profilePath = INITIAL_PATH + "MyProfile.uml";
+ IFile file = project.getFile(profilePath);
+ if(!file.exists()) {
+ URL url = FileLocator.find(Activator.getDefault().getBundle(), new Path(profilePath), null);
+ URL newFile = FileLocator.resolve(url);
+ file.createLink(newFile.toURI(), IResource.REPLACE, monitor);
}
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
return project;
diff --git a/tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/testModel2/AbstractResourceLoadingTestModel2.java b/tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/testModel2/AbstractResourceLoadingTestModel2.java
index 7ecc27c5699..e8729612f5c 100644
--- a/tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/testModel2/AbstractResourceLoadingTestModel2.java
+++ b/tests/org.eclipse.papyrus.core.test/src/org/eclipse/papyrus/core/test/testModel2/AbstractResourceLoadingTestModel2.java
@@ -30,7 +30,6 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.papyrus.core.resourceloading.OnDemandLoadingModelSetServiceFactory;
import org.eclipse.papyrus.core.resourceloading.preferences.StrategyChooser;
@@ -86,20 +85,20 @@ public abstract class AbstractResourceLoadingTestModel2 extends TestCase {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("org.eclipse.papyrus.core.test");
IProgressMonitor monitor = new NullProgressMonitor();
- if(!project.exists()) {
+ if(project != null && !project.exists()) {
project.create(monitor);
- project.open(monitor);
- for(String res : resources) {
- for(String s : extensions) {
- IFile file = project.getFile(INITIAL_PATH + res + s);
- // link all the models resources
- if(!file.exists()) {
- createFolder(project, "resources/");
- createFolder(project, INITIAL_PATH);
- URL url = FileLocator.find(Activator.getDefault().getBundle(), new Path(INITIAL_PATH + res + s), null);
- URL newFile = FileLocator.resolve(url);
- file.createLink(newFile.toURI(), IResource.REPLACE, monitor);
- }
+ }
+ project.open(monitor);
+ for(String res : resources) {
+ for(String s : extensions) {
+ IFile file = project.getFile(INITIAL_PATH + res + s);
+ // link all the models resources
+ if(!file.exists()) {
+ createFolder(project, "resources/");
+ createFolder(project, INITIAL_PATH);
+ URL url = FileLocator.find(Activator.getDefault().getBundle(), new Path(INITIAL_PATH + res + s), null);
+ URL newFile = FileLocator.resolve(url);
+ file.createLink(newFile.toURI(), IResource.REPLACE, monitor);
}
}
}
@@ -128,7 +127,7 @@ public abstract class AbstractResourceLoadingTestModel2 extends TestCase {
URI uriClass0 = URI.createPlatformResourceURI(RESOURCE_URI + "model1.uml#_1766sIRSEd-ZSb15jhF0Qw", false);
EObject class0 = modelSet.getEObject(uriClass0, true);
- assertEquals("Load object from a reference", type, class0);
+ assertTestGetReferenceInControlledRessource("Type of property is resolved ? :", type, class0);
}
private void assertTestGetDanglingReferenceFromParentResource(String message, EObject eObject) {
@@ -150,28 +149,78 @@ public abstract class AbstractResourceLoadingTestModel2 extends TestCase {
}
}
+ private void assertTestGetReferenceInControlledRessource(String message, EObject eObject1, EObject eObject2) {
+ switch(getStrategy()) {
+ case 0:
+ // Load all the needed resources
+ assertSame(message, eObject1, eObject2);
+ break;
+ case 1:
+ // Load the additional resources (profile and pathmap). Controlled resources are not loaded
+ assertNotSame(message, eObject1, eObject2);
+ break;
+ case 2:
+ // Load the additional resources (profile and pathmap) and the needed controlled resources
+ assertSame(message, eObject1, eObject2);
+ break;
+ default:
+ break;
+ }
+ }
+
/**
* Gets a figure (figure of Class0) contains in the high level resource (model1) from a diagram in controlled resource (Package0)
*/
public void testGetFigureInControlledRessource() {
URI uriFigurePackage0 = URI.createPlatformResourceURI(RESOURCE_URI + "Package0.notation#_-ig9EIRSEd-ZSb15jhF0Qw", false);
EObject figurePackage0 = modelSet.getEObject(uriFigurePackage0, true);
+ assertTestGetFigureInControlledRessource1("Get figure in Package0 resource", figurePackage0);
EObject element = null;
if (figurePackage0 instanceof Node) {
Node node = (Node)figurePackage0;
element = node.getElement();
- assertNotNull("Element from the figure not null", element);
- }
-
+ }
URI uriClass0 = URI.createPlatformResourceURI(RESOURCE_URI + "model1.uml#_1766sIRSEd-ZSb15jhF0Qw", false);
EObject class0 = modelSet.getEObject(uriClass0, true);
- assertEquals("Load figure from high level resource", class0, element);
+ assertTestGetFigureInControlledRessource2("Load figure from high level resource", class0, element);
}
- public void testResolveAll() {
- int nbResources = modelSet.getResources().size();
- EcoreUtil.resolveAll(modelSet);
- assertEquals(nbResources, modelSet.getResources().size());
+ private void assertTestGetFigureInControlledRessource1(String message, EObject eObject) {
+ switch(getStrategy()) {
+ case 0:
+ // Load all the needed resources
+ assertTrue(message, !eObject.eIsProxy());
+ break;
+ case 1:
+ // Load the additional resources (profile and pathmap). Controlled resources are not loaded
+ assertTrue(message, eObject.eIsProxy());
+ break;
+ case 2:
+ // Load the additional resources (profile and pathmap) and the needed controlled resources
+ assertTrue(message, !eObject.eIsProxy());
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void assertTestGetFigureInControlledRessource2(String message, EObject eObject1, EObject eObject2) {
+ switch(getStrategy()) {
+ case 0:
+ // Load all the needed resources
+ assertSame(message, eObject1, eObject2);
+ break;
+ case 1:
+ // Load the additional resources (profile and pathmap). Controlled resources are not loaded
+ assertNotSame(message, eObject1, eObject2);
+ break;
+ case 2:
+ // Load the additional resources (profile and pathmap) and the needed controlled resources
+ assertSame(message, eObject1, eObject2);
+ break;
+ default:
+ break;
+ }
}
/**

Back to the top