Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrschnekenbu2013-11-25 15:55:22 +0000
committerrschnekenbu2013-11-25 16:03:33 +0000
commit5cb13d43c86e5c3c39de03f0e4f5b8f45054634f (patch)
treee625a916d04a8bf0221afe82f01817fc2b2ee25e /sandbox
parent55200c056973cfc195fd17780c0acd94e4fdd4fa (diff)
downloadorg.eclipse.papyrus-5cb13d43c86e5c3c39de03f0e4f5b8f45054634f.tar.gz
org.eclipse.papyrus-5cb13d43c86e5c3c39de03f0e4f5b8f45054634f.tar.xz
org.eclipse.papyrus-5cb13d43c86e5c3c39de03f0e4f5b8f45054634f.zip
Update tests to check result files before checking files
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractChangeStrategyTests.java86
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractExternalResourcesTest.java36
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/oneresourceforallprofiles/OneResourceForAllProfilesTests.java2
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/resourceperprofile/ResourcePerProfileTests.java5
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/standardstrategy/StandardStrategyTests.java19
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExternalResourceProfileUtils.java59
6 files changed, 134 insertions, 73 deletions
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractChangeStrategyTests.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractChangeStrategyTests.java
index ca7d221a346..c3ec7b69438 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractChangeStrategyTests.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractChangeStrategyTests.java
@@ -15,11 +15,16 @@ package org.eclipse.papyrus.uml.profile.externalresource.tests;
import static org.junit.Assert.fail;
import java.io.IOException;
+import java.util.List;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.OperationHistoryFactory;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
+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;
@@ -40,12 +45,11 @@ import org.eclipse.uml2.uml.UMLPackage;
import org.junit.Assert;
import org.junit.Test;
-
/**
* Abstract class for all change strategy tests
*/
public abstract class AbstractChangeStrategyTests extends AbstractExternalResourcesTest {
-
+
@Test
public void testSaveAs() {
UmlModel umlModel = null;
@@ -57,7 +61,6 @@ public abstract class AbstractChangeStrategyTests extends AbstractExternalResour
}
Model rootModel = (Model)umlModel.getResource().getContents().get(0);
Assert.assertNotNull("Root model impossible to find", rootModel);
-
URI resultURI = getResultURI();
try {
getModelSet(getURI()).saveAs(resultURI);
@@ -88,7 +91,6 @@ public abstract class AbstractChangeStrategyTests extends AbstractExternalResour
@Test
public void changeToOneFileOnlyStrategy() {
changeToStrategy(StrategyRegistry.getInstance().getStrategy(OneResourceOnlyStrategy.ID));
-
// additionnal checks : strategy, location of the stereotype application, etc.
ModelSet resultModelSet = getModelSet(getResultURI());
UmlModel resultUmlModel = null;
@@ -100,22 +102,20 @@ public abstract class AbstractChangeStrategyTests extends AbstractExternalResour
}
Resource resultResource = resultUmlModel.getResource();
Model resultRootModel = (Model)resultResource.getContents().get(0);
-
// test some stereotype applications
// Model::class1 should have <<classStereotype>> Applied (verify root level stererotype)
Class class1_ = (Class)resultRootModel.getPackagedElement(MODEL_CLASS1, true, UMLPackage.eINSTANCE.getClass_(), false);
EObject application = class1_.getStereotypeApplication(class1_.getAppliedStereotype(CLASS_STEREOTYPE_QN));
- Assert.assertNotNull("No stereotype applied on "+ MODEL_CLASS1, application);
+ Assert.assertNotNull("No stereotype applied on " + MODEL_CLASS1, application);
Assert.assertNotNull(application.eResource());
URI stereotypeApplicationURI = application.eResource().getURI();
Assert.assertEquals("Stereotype is not in expected resource", getResultURI().trimFileExtension().appendFileExtension(OneResourceOnlyStrategy.PROFILE_DEFAULT_EXTENSION), stereotypeApplicationURI);
// check undo, check redo...
}
-
+
@Test
public void changeToOneFilePerProfileStrategy() {
changeToStrategy(StrategyRegistry.getInstance().getStrategy(ResourcePerProfileStrategy.ID));
-
// additionnal checks : strategy, location of the stereotype application, etc.
ModelSet resultModelSet = getModelSet(getResultURI());
UmlModel resultUmlModel = null;
@@ -127,21 +127,19 @@ public abstract class AbstractChangeStrategyTests extends AbstractExternalResour
}
Resource resultResource = resultUmlModel.getResource();
Model resultRootModel = (Model)resultResource.getContents().get(0);
-
// test some stereotype applications
// Model::class1 should have <<classStereotype>> Applied (verify root level stererotype)
Class class1_ = (Class)resultRootModel.getPackagedElement(MODEL_CLASS1, true, UMLPackage.eINSTANCE.getClass_(), false);
EObject application = class1_.getStereotypeApplication(class1_.getAppliedStereotype(CLASS_STEREOTYPE_QN));
- Assert.assertNotNull("No stereotype applied on "+ MODEL_CLASS1, application);
+ Assert.assertNotNull("No stereotype applied on " + MODEL_CLASS1, application);
Assert.assertNotNull(application.eResource());
URI stereotypeApplicationURI = application.eResource().getURI();
- Assert.assertEquals("Stereotype is not in expected resource", getResultURI().trimFileExtension().appendFileExtension(EXTERNAL_RESOURCES_TEST_PROFILE+"Profile"), stereotypeApplicationURI);
+ Assert.assertEquals("Stereotype is not in expected resource", getResultURI().trimFileExtension().appendFileExtension(EXTERNAL_RESOURCES_TEST_PROFILE + "Profile"), stereotypeApplicationURI);
}
-
+
@Test
public void changeToStandardStrategy() {
changeToStrategy(StrategyRegistry.getInstance().getStrategy(StandardApplicationLocationStrategy.ID));
-
// additionnal checks : strategy, location of the stereotype application, etc.
ModelSet resultModelSet = getModelSet(getResultURI());
UmlModel resultUmlModel = null;
@@ -153,18 +151,17 @@ public abstract class AbstractChangeStrategyTests extends AbstractExternalResour
}
Resource resultResource = resultUmlModel.getResource();
Model resultRootModel = (Model)resultResource.getContents().get(0);
-
// test some stereotype applications
// Model::class1 should have <<classStereotype>> Applied (verify root level stererotype)
Class class1_ = (Class)resultRootModel.getPackagedElement(MODEL_CLASS1, true, UMLPackage.eINSTANCE.getClass_(), false);
EObject application = class1_.getStereotypeApplication(class1_.getAppliedStereotype(CLASS_STEREOTYPE_QN));
- Assert.assertNotNull("No stereotype applied on "+ MODEL_CLASS1, application);
+ Assert.assertNotNull("No stereotype applied on " + MODEL_CLASS1, application);
Assert.assertNotNull(application.eResource());
URI stereotypeApplicationURI = application.eResource().getURI();
Assert.assertEquals("Stereotype is not in expected resource", resultUmlModel.getResourceURI(), stereotypeApplicationURI);
// check undo, check redo...
}
-
+
protected void changeToStrategy(IStereotypeApplicationLocationStrategy newStrategy) {
UmlModel umlModel = null;
// get The model. try to see applied stereotypes
@@ -175,8 +172,8 @@ public abstract class AbstractChangeStrategyTests extends AbstractExternalResour
}
Model rootModel = (Model)umlModel.getResource().getContents().get(0);
Assert.assertNotNull("Root model impossible to find", rootModel);
-
- ICommand command = ExternalResourceProfileUtils.createUpdateStereotypeApplicationsLocationCommand(rootModel, PapyrusStereotypeApplicationHelper.getCurrentLocationStrategy(rootModel), newStrategy);
+ IStereotypeApplicationLocationStrategy oldStrategy = PapyrusStereotypeApplicationHelper.getCurrentLocationStrategy(rootModel);
+ ICommand command = ExternalResourceProfileUtils.createUpdateStereotypeApplicationsLocationCommand(rootModel, oldStrategy, newStrategy);
Assert.assertNotNull("Impossible to create update command", command);
Assert.assertTrue("Command should be executable", command.canExecute());
IStatus status = null;
@@ -185,27 +182,36 @@ public abstract class AbstractChangeStrategyTests extends AbstractExternalResour
} catch (ExecutionException e1) {
fail(e1.getMessage());
}
-
if(!status.isOK()) {
fail(status.getMessage());
}
+// URI resultURI = getResultURI();
+// try {
+// getModelSet(getURI()).saveAs(resultURI);
+// } catch (IOException e) {
+// fail(e.getMessage());
+// }
- URI resultURI = getResultURI();
try {
- getModelSet(getURI()).saveAs(resultURI);
- } catch (IOException e) {
- fail(e.getMessage());
+ getModelSet(getURI()).save(new NullProgressMonitor());
+ } catch (IOException e1) {
+ fail(e1.getMessage());
}
checkModel(rootModel);
+
// check current model still have right stereotypes/values
tearDownRegistry();
- // try to load and read profiles in the result file
- ModelSet resultModelSet = getModelSet(resultURI);
- Assert.assertNotNull("TMP Model set should not be null", resultModelSet);
+
+ // check result files
+ checkFiles(getResultURI(), newStrategy);
+
+ // try to load and read models
+ ModelSet modelSet = getModelSet(getURI());
+ Assert.assertNotNull("TMP Model set should not be null", modelSet);
UmlModel resultUmlModel = null;
// get The result model. try to see applied stereotypes
try {
- resultUmlModel = (UmlModel)resultModelSet.getModelChecked(UmlModel.MODEL_ID);
+ resultUmlModel = (UmlModel)modelSet.getModelChecked(UmlModel.MODEL_ID);
} catch (NotFoundException e) {
fail(e.getMessage());
}
@@ -216,12 +222,30 @@ public abstract class AbstractChangeStrategyTests extends AbstractExternalResour
Assert.assertNotNull(resultRootModel);
checkModel(resultRootModel);
}
-
+
+ /**
+ * @param resultURI
+ * @param newStrategy
+ */
+ public void checkFiles(URI resultURI, IStereotypeApplicationLocationStrategy newStrategy) {
+ List<String> resultFileNames = STRATEGY_FILE_NAMES_MAPPING.get(newStrategy.getIdentifier());
+ for(String fileName : resultFileNames) {
+ URI fileURI = getResultFolderURI().appendSegment(fileName);
+ IPath path = new Path(fileURI.toPlatformString(true));
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ if(file == null || !file.exists()) {
+ fail(fileName + " does not exists. URI: " + fileURI);
+ }
+ }
+ }
+
public URI getResultFolderURI() {
- return URI.createPlatformResourceURI(getTestProjectName()+"/result", true);
+ // return URI.createPlatformResourceURI(getTestProjectName() + "/result", true);
+ return URI.createPlatformResourceURI(getTestProjectName(), true);
}
-
+
public URI getResultURI() {
- return getResultFolderURI().appendSegment("result.di");
+ // getResultFolderURI().appendSegment("result.di");
+ return getURI();
}
}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractExternalResourcesTest.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractExternalResourcesTest.java
index 5214313bb6b..26ecb1bf78a 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractExternalResourcesTest.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractExternalResourcesTest.java
@@ -15,9 +15,12 @@ package org.eclipse.papyrus.uml.profile.externalresource.tests;
import static org.junit.Assert.fail;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.OperationHistoryFactory;
@@ -25,17 +28,14 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.emf.workspace.EMFCommandOperation;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.resource.ModelMultiException;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
@@ -49,15 +49,13 @@ import org.eclipse.papyrus.infra.core.services.ServiceNotFoundException;
import org.eclipse.papyrus.infra.core.services.ServiceStartKind;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceInitializerService;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
import org.eclipse.papyrus.junit.utils.PapyrusProjectUtils;
import org.eclipse.papyrus.junit.utils.ProjectUtils;
-import org.eclipse.papyrus.uml.profile.externalresource.helper.ExternalResourceProfileUtils;
import org.eclipse.papyrus.uml.profile.externalresource.helper.OneResourceOnlyStrategy;
-import org.eclipse.papyrus.uml.profile.externalresource.helper.PapyrusStereotypeApplicationHelper;
-import org.eclipse.papyrus.uml.profile.externalresource.helper.StrategyRegistry;
+import org.eclipse.papyrus.uml.profile.externalresource.helper.ResourcePerProfileStrategy;
+import org.eclipse.papyrus.uml.profile.externalresource.helper.StandardApplicationLocationStrategy;
import org.eclipse.papyrus.uml.tools.commands.ApplyStereotypeCommand;
import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.ui.IEditorPart;
@@ -68,9 +66,9 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.UMLPackage;
-import org.eclipse.uml2.uml.Package;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -159,7 +157,27 @@ public abstract class AbstractExternalResourcesTest {
public static final String ONE_RESOURCE_FOR_ALL_PROFILES_FOLDER = "OneResourceForAllProfiles";
public static final String ONE_RESOURCE_PER_PROFILE_FOLDER = "OneResourcePerProfile";
-
+
+ public static final List<String> STANDARD_STRATEGY_FILE_NAMES = Arrays.asList(DI_FILE, UML_FILE, NOTATION_FILE,
+ /* Class3.di */ CLASS3_MODEL_DI_FILE, CLASS3_MODEL_NOTATION_FILE, CLASS3_MODEL_UML_FILE,
+ /* Package1_Class1.di */PACKAGE1_MODEL_DI_FILE, PACKAGE1_MODEL_NOTATION_FILE, PACKAGE1_MODEL_UML_FILE);
+
+ public static final List<String> ONE_RESOURCE_PER_PROFILE_FILE_NAMES = Arrays.asList(DI_FILE, NOTATION_FILE, UML_FILE, EXTERNAL_RESOURCES_TEST_PROFILE_EXTENSION_FILE,
+ /* PACKAGE1*/ PACKAGE1_MODEL_DI_FILE, PACKAGE1_MODEL_NOTATION_FILE, PACKAGE1_MODEL_UML_FILE, PACKAGE1_EXTERNAL_RESOURCES_TEST_PROFILE_EXTENSION_FILE,
+ /* CLASS3*/ CLASS3_MODEL_DI_FILE, CLASS3_MODEL_NOTATION_FILE, CLASS3_MODEL_UML_FILE, CLASS3_EXTERNAL_RESOURCES_TEST_PROFILE_EXTENSION_FILE
+ );
+
+ public static final List<String> ONE_RESOURCE_FOR_ALL_PROFILES_FILE_NAMES = Arrays.asList(DI_FILE, NOTATION_FILE, UML_FILE, ALL_PROFILES_FILE,
+ /* PACKAGE1*/ PACKAGE1_MODEL_DI_FILE, PACKAGE1_MODEL_NOTATION_FILE, PACKAGE1_MODEL_UML_FILE, PACKAGE1_ALL_PROFILES_FILE,
+ /* CLASS3*/ CLASS3_MODEL_DI_FILE, CLASS3_MODEL_NOTATION_FILE, CLASS3_MODEL_UML_FILE, CLASS3_ALL_PROFILES_FILE
+ );
+
+ public static final Map<String, List<String>> STRATEGY_FILE_NAMES_MAPPING = new HashMap<String, List<String>>(); {
+ STRATEGY_FILE_NAMES_MAPPING.put(OneResourceOnlyStrategy.ID, ONE_RESOURCE_FOR_ALL_PROFILES_FILE_NAMES);
+ STRATEGY_FILE_NAMES_MAPPING.put(ResourcePerProfileStrategy.ID, ONE_RESOURCE_PER_PROFILE_FILE_NAMES);
+ STRATEGY_FILE_NAMES_MAPPING.put(StandardApplicationLocationStrategy.ID, STANDARD_STRATEGY_FILE_NAMES);
+ }
+
@Before
public void initializeRegistry() {
ResourcesPlugin.getWorkspace().getDescription().setAutoBuilding(false);
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/oneresourceforallprofiles/OneResourceForAllProfilesTests.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/oneresourceforallprofiles/OneResourceForAllProfilesTests.java
index a7475756c15..252d0d677c2 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/oneresourceforallprofiles/OneResourceForAllProfilesTests.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/oneresourceforallprofiles/OneResourceForAllProfilesTests.java
@@ -37,7 +37,7 @@ public class OneResourceForAllProfilesTests extends AbstractChangeStrategyTests
*/
@Override
protected List<String> getModelFileNames() {
- return Arrays.asList(DI_FILE, NOTATION_FILE, UML_FILE, ALL_PROFILES_FILE);
+ return ONE_RESOURCE_FOR_ALL_PROFILES_FILE_NAMES;
}
/**
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/resourceperprofile/ResourcePerProfileTests.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/resourceperprofile/ResourcePerProfileTests.java
index 6701c6a2f6a..4344a4e6acc 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/resourceperprofile/ResourcePerProfileTests.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/resourceperprofile/ResourcePerProfileTests.java
@@ -36,10 +36,7 @@ public class ResourcePerProfileTests extends AbstractChangeStrategyTests {
*/
@Override
protected List<String> getModelFileNames() {
- return Arrays.asList(DI_FILE, NOTATION_FILE, UML_FILE, EXTERNAL_RESOURCES_TEST_PROFILE_EXTENSION_FILE,
- /* PACKAGE1*/ PACKAGE1_MODEL_DI_FILE, PACKAGE1_MODEL_NOTATION_FILE, PACKAGE1_MODEL_UML_FILE, PACKAGE1_EXTERNAL_RESOURCES_TEST_PROFILE_EXTENSION_FILE,
- /* CLASS3*/ CLASS3_MODEL_DI_FILE, CLASS3_MODEL_NOTATION_FILE, CLASS3_MODEL_UML_FILE, CLASS3_EXTERNAL_RESOURCES_TEST_PROFILE_EXTENSION_FILE
- );
+ return ONE_RESOURCE_PER_PROFILE_FILE_NAMES;
}
/**
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/standardstrategy/StandardStrategyTests.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/standardstrategy/StandardStrategyTests.java
index 5773a75ce99..9c8f958077f 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/standardstrategy/StandardStrategyTests.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/standardstrategy/StandardStrategyTests.java
@@ -12,21 +12,17 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.profile.externalresource.tests.standardstrategy;
-import java.util.Arrays;
import java.util.List;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.papyrus.uml.profile.externalresource.helper.ExternalResourceProfileUtils;
import org.eclipse.papyrus.uml.profile.externalresource.tests.AbstractChangeStrategyTests;
+import org.junit.Test;
/**
* Test class for load/unload
*/
public class StandardStrategyTests extends AbstractChangeStrategyTests {
-
-
- public static final List<String> FILE_NAMES = Arrays.asList(DI_FILE, UML_FILE, NOTATION_FILE,
- /* Class3.di */ CLASS3_MODEL_DI_FILE, CLASS3_MODEL_NOTATION_FILE, CLASS3_MODEL_UML_FILE,
- /* Package1_Class1.di */PACKAGE1_MODEL_DI_FILE, PACKAGE1_MODEL_NOTATION_FILE, PACKAGE1_MODEL_UML_FILE);
/**
* {@inheritDoc}
@@ -41,7 +37,7 @@ public class StandardStrategyTests extends AbstractChangeStrategyTests {
*/
@Override
protected List<String> getModelFileNames() {
- return FILE_NAMES;
+ return STANDARD_STRATEGY_FILE_NAMES;
}
/**
@@ -60,4 +56,13 @@ public class StandardStrategyTests extends AbstractChangeStrategyTests {
return URI.createPlatformResourceURI(getTestProjectName() + "/" + CLASS3_MODEL_UML_FILE, true);
}
+
+ @Test
+ public void testFindStereotypeApplicationsByDefinition() {
+
+
+ // ExternalResourceProfileUtils.findStereotypeApplicationsByDefinition(profileApplication, oldStrategy)
+
+
+ }
}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExternalResourceProfileUtils.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExternalResourceProfileUtils.java
index b5408dab312..802a38de3eb 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExternalResourceProfileUtils.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExternalResourceProfileUtils.java
@@ -13,9 +13,11 @@
package org.eclipse.papyrus.uml.profile.externalresource.helper;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -44,17 +46,48 @@ public class ExternalResourceProfileUtils {
public static IStatus updateStereotypeApplicationsLocation(ProfileApplication profileApplication, IStereotypeApplicationLocationStrategy oldStrategy, IStereotypeApplicationLocationStrategy newStrategy) {
// 1. retrieve all stereotype applications concerned by the given profile application
// 2. move the stereotype application in their new containment list
+ Map<EClass, List<EObject>> allStereotypeApplications = findStereotypeApplicationsByDefinition(profileApplication, oldStrategy);
+
+ // now have a map of all definitions of stereotypes contained in the profile applied, now they should be moved according to the new strategy
+ for(Entry<EClass, List<EObject>> entry : allStereotypeApplications.entrySet()) {
+ EClass definition = entry.getKey();
+ for(EObject stereotypeApplication : entry.getValue()) {
+ // move the EObject in the new containment list
+ Element baseElement = UMLUtil.getBaseElement(stereotypeApplication);
+ List<EObject> containmentList = newStrategy.getContainmentList(baseElement, definition);
+ if(!containmentList.contains(stereotypeApplication)) { // move the stereotype application only if it was not already there (to avoid useless moves)
+ containmentList.add(stereotypeApplication); // move stereotype at the right place
+ };
+ }
+ }
+
+ // update Eannotation that stores the new strategy
+ PapyrusStereotypeApplicationHelper.setCurrentLocationStrategy(profileApplication, newStrategy);
+
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * @param profileApplication
+ * @return
+ */
+ public static Map<EClass, List<EObject>> findStereotypeApplicationsByDefinition(ProfileApplication profileApplication, IStereotypeApplicationLocationStrategy oldStrategy) throws RuntimeException{
+ Map<EClass, List<EObject>> allStereotypeApplications = new HashMap<EClass, List<EObject>>();
+
Resource modelResource = profileApplication.eResource();
if(modelResource == null) {
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Impossible to find model resource");
+ Activator.log.error("Profile Application is not in a resource. "+profileApplication, null);
+ return Collections.emptyMap();
}
ModelSet modelSet = null;
if(!(modelResource.getResourceSet() instanceof ModelSet)) {
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Trying to modify the stereotype application outside a Papyrus Model Set");
+ Activator.log.error("Trying to modify the stereotype application outside a Papyrus Model Set", null);
+ return Collections.emptyMap();
+
} else {
modelSet = (ModelSet)modelResource.getResourceSet();
}
- Map<EClass, List<EObject>> allStereotypeApplications = new HashMap<EClass, List<EObject>>();
+
// For all resources, retrieve the containment list that should hold the stereotype application for the given profile, for all UML elements at the root of the resource (should test for all elements, but would be really slow)
// for all elements in the containment list that corresponds to the profile application, store in a new list
List<EClassifier> classifiers = profileApplication.getAppliedDefinition().getEClassifiers();
@@ -82,25 +115,9 @@ public class ExternalResourceProfileUtils {
allStereotypeApplications.put(definition, stereotypeApplications);
}
}
-
- // now have a map of all definitions of stereotypes contained in the profile applied, now they should be moved according to the new strategy
- for(EClass definition : allStereotypeApplications.keySet()) {
- for(EObject stereotypeApplication : allStereotypeApplications.get(definition)) {
- // move the EObject in the new containment list
- Element baseElement = UMLUtil.getBaseElement(stereotypeApplication);
- List<EObject> containmentList =newStrategy.getContainmentList(baseElement, definition);
- if(!containmentList.contains(stereotypeApplication)) { // move the stereotype application only if it was not already there (to avoid useless moves)
- containmentList.add(stereotypeApplication); // move stereotype at the right place
- };
- }
- }
-
- // update Eannotation that stores the new strategy
- PapyrusStereotypeApplicationHelper.setCurrentLocationStrategy(profileApplication, newStrategy);
-
- return Status.OK_STATUS;
+ return allStereotypeApplications;
}
-
+
public static ICommand createUpdateStereotypeApplicationsLocationCommand( ProfileApplication profileApplication, IStereotypeApplicationLocationStrategy oldStrategy, IStereotypeApplicationLocationStrategy newStrategy) {
if(profileApplication ==null) {
return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;

Back to the top