Author: euluis
Date: 2010-04-09 15:39:12-0700
New Revision: 18234
Added:
trunk/src/argouml-app/tests/org/argouml/uml/TestStereotypeUtility.java
(contents, props changed)
trunk/src/argouml-app/tests/org/argouml/uml/ui/foundation/extension_mechanisms/
trunk/src/argouml-app/tests/org/argouml/uml/ui/foundation/extension_mechanisms/TestUMLTagDefinitionComboBoxModel.java
(contents, props changed)
- copied, changed from r18202,
/trunk/src/argouml-app/tests/org/argouml/uml/ui/TestUMLTagDefinitionComboBoxModel.java
Removed:
trunk/src/argouml-app/tests/org/argouml/uml/ui/TestUMLTagDefinitionComboBoxModel.java
Modified:
trunk/src/argouml-app/tests/org/argouml/kernel/TestProjectWithProfiles.java
trunk/src/argouml-app/tests/org/argouml/profile/ProfileMother.java
trunk/src/argouml-app/tests/org/argouml/profile/TestProfileMother.java
trunk/src/argouml-app/tests/org/argouml/profile/TestUserDefinedProfile.java
trunk/src/argouml-app/tests/org/argouml/uml/TestProfileDefault.java
Log:
issue 5969 and issue 6008: failing integration tests (with failure points
commented-out) for both issues
Modified:
trunk/src/argouml-app/tests/org/argouml/kernel/TestProjectWithProfiles.java
Url:
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/kernel/TestProjectWithProfiles.java?view=diff&pathrev=18234&r1=18233&r2=18234
==============================================================================
--- trunk/src/argouml-app/tests/org/argouml/kernel/TestProjectWithProfiles.java
(original)
+++ trunk/src/argouml-app/tests/org/argouml/kernel/TestProjectWithProfiles.java
2010-04-09 15:39:12-0700
@@ -83,21 +83,14 @@
/*
* @see junit.framework.TestCase#setUp()
*/
- @SuppressWarnings("unchecked")
@Override
protected void setUp() throws Exception {
super.setUp();
InitializeModel.initializeMDR();
new InitProfileSubsystem().init();
- if (ApplicationVersion.getVersion() == null) {
- Class argoVersionClass =
- Class.forName("org.argouml.application.ArgoVersion");
- Method initMethod = argoVersionClass.getDeclaredMethod("init");
- initMethod.setAccessible(true);
- initMethod.invoke(null);
- assertNotNull(ApplicationVersion.getVersion());
- }
+ initAppVersion();
+ assertNotNull(ApplicationVersion.getVersion());
String testCaseDirNamePrefix = getClass().getPackage().getName();
testCaseDir = FileHelper.setUpDir4Test(testCaseDirNamePrefix);
}
@@ -200,9 +193,7 @@
// save the project into a new file
File file = getFileInTestDir(
"testRemoveProfileWithModelThatRefersToProfile.zargo");
- AbstractFilePersister persister = getProjectPersister(file);
- project.setVersion(ApplicationVersion.getVersion());
- persister.save(project, file);
+ AbstractFilePersister persister = saveProject(project, file);
project.remove();
// reopen the project and assert that the MetaProfile isn't part of
@@ -294,9 +285,7 @@
// save the project
File file = getFileInTestDir(
"testProjectWithUserDefinedProfilePersistency.zargo");
- AbstractFilePersister persister = getProjectPersister(file);
- project.setVersion(ApplicationVersion.getVersion());
- persister.save(project, file);
+ AbstractFilePersister persister = saveProject(project, file);
project.remove();
// load the project
@@ -368,9 +357,7 @@
Model.getCoreHelper().addStereotype(fooClass, stStereotype);
// save the project
File file = getFileInTestDir(testName + ".zargo");
- AbstractFilePersister persister = getProjectPersister(file);
- project.setVersion(ApplicationVersion.getVersion());
- persister.save(project, file);
+ AbstractFilePersister persister = saveProject(project, file);
// remove the user defined profile and the directory where it is
profileManager.removeProfile(userDefinedProfile);
profileManager.removeSearchPathDirectory(testCaseDir.getAbsolutePath());
@@ -390,13 +377,57 @@
}
}
- private AbstractFilePersister getProjectPersister(File file) {
+ /**
+ * @param project the ArgoUML {...@link Project} to save in file.
+ * @param file the {...@link File} in which an ArgoUML {...@link Project}
will
+ * be persisted.
+ * @return the persister used and usable for file.
+ * @throws SaveException if saving the file goes wrong.
+ * @throws InterruptedException if an interrupt occurs while saving.
+ * TODO: move this to an helper class.
+ */
+ public static AbstractFilePersister saveProject(Project project, File file)
+ throws SaveException, InterruptedException {
+ AbstractFilePersister persister = getProjectPersister(file);
+ project.setVersion(ApplicationVersion.getVersion());
+ persister.save(project, file);
+ return persister;
+ }
+
+ /**
+ * Get an {...@link AbstractFilePersister} for file.
+ *
+ * @param file the {...@link File} in which an ArgoUML {...@link Project}
will
+ * be persisted.
+ * @return the appropriate persister for file or null if the file's
+ * extension doesn't match a supported persister.
+ * TODO: move this to an helper class.
+ */
+ public static AbstractFilePersister getProjectPersister(File file) {
AbstractFilePersister persister =
PersistenceManager.getInstance().getPersisterFromFileName(
- file.getAbsolutePath());
+ file.getAbsolutePath());
return persister;
}
+ /**
+ * Initialize the ArgoUML application version, so that
+ * {...@link ApplicationVersion#getVersion()} doesn't return null.
+ *
+ * @throws Exception if something goes wrong...
+ * TODO: move this to an helper class.
+ */
+ @SuppressWarnings("unchecked")
+ public static void initAppVersion() throws Exception {
+ if (ApplicationVersion.getVersion() == null) {
+ Class argoVersionClass =
+ Class.forName("org.argouml.application.ArgoVersion");
+ Method initMethod = argoVersionClass.getDeclaredMethod("init");
+ initMethod.setAccessible(true);
+ initMethod.invoke(null);
+ }
+ }
+
private File createUserProfileFile(File directory, String filename)
throws IOException {
ProfileMother mother = new ProfileMother();
Modified: trunk/src/argouml-app/tests/org/argouml/profile/ProfileMother.java
Url:
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/profile/ProfileMother.java?view=diff&pathrev=18234&r1=18233&r2=18234
==============================================================================
--- trunk/src/argouml-app/tests/org/argouml/profile/ProfileMother.java
(original)
+++ trunk/src/argouml-app/tests/org/argouml/profile/ProfileMother.java
2010-04-09 15:39:12-0700
@@ -61,6 +61,7 @@
import org.apache.log4j.Logger;
import org.argouml.FileHelper;
+import org.argouml.model.InvalidElementException;
import org.argouml.model.Model;
import org.argouml.model.UmlException;
import org.argouml.model.XmiReader;
@@ -104,8 +105,24 @@
* "st" the example stereotype name.
*/
public static final String STEREOTYPE_NAME_ST = "st";
-
- private final String DEFAULT_SIMPLE_PROFILE_NAME = "SimpleProfile";
+
+ /**
+ * "SimpleProfile" is the name of the SimpleProfile which ProfileMother
+ * uses for the most basic profile being used.
+ */
+ public static final String DEFAULT_SIMPLE_PROFILE_NAME = "SimpleProfile";
+
+ /**
+ * ".xmi" is the default profile file extension.
+ */
+ public static final String XMI_FILE_EXTENSION = ".xmi";
+
+ /**
+ * "TagDef" is the name of the Tag Definition applicable to model elements
+ * to which the stereotype named {...@link
ProfileMother#STEREOTYPE_NAME_ST}
+ * of SimpleProfile was applied.
+ */
+ public static final String TAG_DEFINITION_NAME_TD = "TagDef";
/**
* Create a simple profile model with name {...@link
ProfileMother#DEFAULT_SIMPLE_PROFILE_NAME}
@@ -127,11 +144,16 @@
* @return the profile model.
*/
public Object createSimpleProfileModel(String profileName) {
+ // TODO: should it remove the leftovers from other tests?
+// cleanAllExtents();
+// assert getFacade().getRootElements().size() == 0;
Object model = getModelManagementFactory().createProfile();
Object fooClass = Model.getCoreFactory().buildClass("foo", model);
- getExtensionMechanismsFactory().buildStereotype(fooClass,
- STEREOTYPE_NAME_ST, model);
+ Object stereotype =
getExtensionMechanismsFactory().buildStereotype(fooClass,
+ STEREOTYPE_NAME_ST, model);
getCoreHelper().setName(model, profileName);
+ getExtensionMechanismsFactory().buildTagDefinition(
+ TAG_DEFINITION_NAME_TD, stereotype, null);
return model;
}
@@ -148,7 +170,7 @@
}
return null;
}
-
+
private Object umlProfileModel;
Object getUmlProfileModel() {
@@ -178,9 +200,10 @@
*/
public void saveProfileModel(Object model, File file) throws IOException {
FileOutputStream fileOut = new FileOutputStream(file);
+// cleanAllExtentsBut(model); // TODO: why is this causing a crash?!?
try {
XmiWriter xmiWriter = Model.getXmiWriter(model, fileOut, "x("
- + UmlFilePersister.PERSISTENCE_VERSION + ")");
+ + UmlFilePersister.PERSISTENCE_VERSION + ")");
xmiWriter.write();
fileOut.flush();
} catch (Exception e) {
@@ -192,6 +215,24 @@
}
}
+ public static void cleanAllExtents() {
+ cleanAllExtentsBut(null);
+ }
+
+ public static void cleanAllExtentsBut(Object extentNotToClean) {
+ // remove leftovers from other tests
+ Collection rootElements = Model.getFacade().getRootElements();
+ for (Object rootElement : rootElements) {
+ if (extentNotToClean != rootElement) {
+ try {
+ Model.getUmlFactory().deleteExtent(rootElement);
+ } catch (InvalidElementException e) {
+ // ignored
+ }
+ }
+ }
+ }
+
/**
* Create a XMI file that stores a UML profile which depends via XMI
* of the profile stored in profileFromWhichDependsFile.
@@ -233,7 +274,7 @@
dependencyCreator.create(profileFromWhichDependsModel,
dependentProfile);
File dependentProfileFile = File.createTempFile(
- dependentProfileFilenamePrefix, ".xmi", profilesDir);
+ dependentProfileFilenamePrefix, XMI_FILE_EXTENSION, profilesDir);
saveProfileModel(dependentProfile, dependentProfileFile);
Model.getUmlFactory().deleteExtent(dependentProfile);
xmiReader.removeSearchPath(profileFromWhichDependsFile.getParent());
@@ -253,7 +294,7 @@
throws IOException, UmlException {
File profilesDir = FileHelper.createTempDirectory();
final File baseFile = File.createTempFile(
- "baseProfile", ".xmi", profilesDir);
+ "baseProfile", XMI_FILE_EXTENSION, profilesDir);
Object model = createSimpleProfileModel();
saveProfileModel(model, baseFile);
Model.getUmlFactory().deleteExtent(model);
@@ -300,13 +341,13 @@
// ensure that model subsystem implementation doesn't remember the
// profiles by changing their names and directories
baseProfileFile = FileHelper.moveFileToNewTempDirectory(
- baseProfileFile, "new-base-profile", ".xmi",
+ baseProfileFile, "new-base-profile", XMI_FILE_EXTENSION,
ProfileMother.class.getCanonicalName());
File dependentProfileFile = profileFiles.get(1);
replaceStringInFile(dependentProfileFile, baseProfileFileName,
baseProfileFile.getName());
dependentProfileFile = FileHelper.moveFileToNewTempDirectory(
- dependentProfileFile, "new-dependent-profile", ".xmi",
+ dependentProfileFile, "new-dependent-profile", XMI_FILE_EXTENSION,
ProfileMother.class.getCanonicalName());
profileFiles.clear();
profileFiles.add(baseProfileFile);
@@ -353,4 +394,44 @@
}
}
}
+
+ /**
+ * Create the SimpleProfile (see
+ * {...@link ProfileMother#createSimpleProfileModel()}) in a way that it
isn't
+ * neither loaded in the model neither remembered by it. The file name has
+ * the prefix {...@link ProfileMother#DEFAULT_SIMPLE_PROFILE_NAME} and the
+ * extension {...@link ProfileMother#XMI_FILE_EXTENSION}.
+ *
+ * @return the {...@link File} where the profile was stored.
+ * @throws IOException
+ */
+ public File createUnloadedSimpleProfile() throws IOException {
+ return createUnloadedSimpleProfile(DEFAULT_SIMPLE_PROFILE_NAME);
+ }
+
+ /**
+ * Create the SimpleProfile (see
+ * {...@link ProfileMother#createSimpleProfileModel()}) in a way that it
isn't
+ * neither loaded in the model neither remembered by it. The file name has
+ * the prefix profileName and the
+ * extension {...@link ProfileMother#XMI_FILE_EXTENSION}.
+ *
+ * @param profileName the name of the profile and the prefix of the
+ * profile file name.
+ * @return the {...@link File} where the profile was stored.
+ * @throws IOException
+ */
+ public File createUnloadedSimpleProfile(String profileName)
+ throws IOException {
+ Object model = createSimpleProfileModel(profileName);
+ File profileFile = File.createTempFile(profileName,
+ XMI_FILE_EXTENSION);
+ saveProfileModel(model, profileFile);
+ Model.getUmlFactory().deleteExtent(model);
+ File newProfileFile = File.createTempFile(profileName,
+ XMI_FILE_EXTENSION);
+ newProfileFile.delete();
+ profileFile.renameTo(newProfileFile);
+ return newProfileFile;
+ }
}
Modified: trunk/src/argouml-app/tests/org/argouml/profile/TestProfileMother.java
Url:
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/profile/TestProfileMother.java?view=diff&pathrev=18234&r1=18233&r2=18234
==============================================================================
--- trunk/src/argouml-app/tests/org/argouml/profile/TestProfileMother.java
(original)
+++ trunk/src/argouml-app/tests/org/argouml/profile/TestProfileMother.java
2010-04-09 15:39:12-0700
@@ -239,4 +239,24 @@
File dependentFile = profilesFiles.get(1);
assertStringInLineOfFile("", baseFile.getName(), dependentFile);
}
+
+ /**
+ * Test {...@link ProfileMother#createUnloadedSimpleProfile()}.
+ *
+ * @throws IOException when file IO goes wrong...
+ * @throws UmlException when UML manipulation goes wrong...
+ */
+ public void testCreateUnloadedSimpleProfile() throws IOException,
+ UmlException {
+ File profileFile = mother.createUnloadedSimpleProfile();
+ profileFile.deleteOnExit();
+ assertTrue("It doesn't exist or isn't a file.",
+ profileFile.exists() && profileFile.isFile());
+ XmiReader xmiReader = Model.getXmiReader();
+ InputSource inputSource = new InputSource(
+ profileFile.toURI().toURL().toExternalForm());
+ Collection topModelElements = xmiReader.parse(inputSource, true);
+ assertEquals("Unexpected number of top model elements.",
+ 1, topModelElements.size());
+ }
}
Modified:
trunk/src/argouml-app/tests/org/argouml/profile/TestUserDefinedProfile.java
Url:
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/profile/TestUserDefinedProfile.java?view=diff&pathrev=18234&r1=18233&r2=18234
==============================================================================
--- trunk/src/argouml-app/tests/org/argouml/profile/TestUserDefinedProfile.java
(original)
+++ trunk/src/argouml-app/tests/org/argouml/profile/TestUserDefinedProfile.java
2010-04-09 15:39:12-0700
@@ -117,7 +117,7 @@
// create profile model
ProfileMother profileMother = new ProfileMother();
- Object model = profileMother.createSimpleProfileModel();
+ Object model = profileMother.createSimpleProfileModel("displayName");
// save the profile into a xmi file
File profileFile = new File(testDir, "testLoadingConstructor.xmi");
profileMother.saveProfileModel(model, profileFile);
Modified: trunk/src/argouml-app/tests/org/argouml/uml/TestProfileDefault.java
Url:
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/uml/TestProfileDefault.java?view=diff&pathrev=18234&r1=18233&r2=18234
==============================================================================
--- trunk/src/argouml-app/tests/org/argouml/uml/TestProfileDefault.java
(original)
+++ trunk/src/argouml-app/tests/org/argouml/uml/TestProfileDefault.java
2010-04-09 15:39:12-0700
@@ -43,19 +43,24 @@
import junit.framework.TestCase;
import org.argouml.kernel.ProfileConfiguration;
+import org.argouml.kernel.Project;
import org.argouml.kernel.ProjectManager;
import org.argouml.model.InitializeModel;
import org.argouml.model.Model;
+import org.argouml.profile.Profile;
+import org.argouml.profile.ProfileException;
+import org.argouml.profile.ProfileFacade;
import org.argouml.profile.init.InitProfileSubsystem;
/**
- *
- * @author euluis
+ * Automated integration tests that guarantee that the default profiles work.
+ * @author Luis Sergio Oliveira (euluis)
* @since 0.20
- * @version 0.00
*/
public class TestProfileDefault extends TestCase {
+ private Project proj;
+
/**
* The constructor.
*
@@ -75,18 +80,31 @@
new InitProfileSubsystem().init();
}
+ @Override
+ protected void tearDown() throws Exception {
+ if (proj != null) {
+ ProjectManager.getManager().removeProject(proj);
+ }
+ super.tearDown();
+ }
/**
* Test whether we can load default profile.
+ * @throws ProfileException if {...@link Profile} operations throw.
*/
- public void testLoadProfileModel() {
- // TODO: This depends on the profile configuration of the user running
- // the test. It needs to be made independent of that.
- ProfileConfiguration config = ProjectManager.getManager()
- .getCurrentProject().getProfileConfiguration();
+ public void testLoadProfileModel() throws ProfileException {
+ proj = ProjectManager.getManager().makeEmptyProject();
+ ProfileConfiguration config = proj.getProfileConfiguration();
assertNotNull("Can't load profile configuration", config);
+ Profile umlProfile = ProfileFacade.getManager().getUMLProfile();
+ assertNotNull(umlProfile);
+ assertTrue(!umlProfile.getProfilePackages().isEmpty());
+ Object model = proj.getUserDefinedModelList().iterator().next();
+ if (!config.getProfiles().contains(umlProfile)) {
+ config.addProfile(umlProfile, model);
+ }
Collection stereos = config.findAllStereotypesForModelElement(Model
- .getCoreFactory().createClass());
+ .getCoreFactory().createClass());
assertTrue("No stereotypes found in default profiles",
- stereos.size() > 0);
+ stereos.size() > 0);
}
}
Added: trunk/src/argouml-app/tests/org/argouml/uml/TestStereotypeUtility.java
Url:
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/uml/TestStereotypeUtility.java?view=markup&pathrev=18234
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/tests/org/argouml/uml/TestStereotypeUtility.java
2010-04-09 15:39:12-0700
@@ -0,0 +1,138 @@
+/* $Id$
+
*******************************************************************************
+ * Copyright (c) 2010 Contributors - see below
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Luis Sergio Oliveira (euluis)
+
*******************************************************************************
+ */
+
+package org.argouml.uml;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import org.argouml.kernel.Project;
+import org.argouml.kernel.ProjectManager;
+import org.argouml.model.InitializeModel;
+import org.argouml.model.Model;
+import org.argouml.profile.ProfileFacade;
+import org.argouml.profile.ProfileMother;
+import org.argouml.profile.UserDefinedProfile;
+import org.argouml.profile.init.InitProfileSubsystem;
+
+import junit.framework.TestCase;
+
+/**
+ * Integration tests for {...@link StereotypeUtility} class.
+ *
+ * @author Luis Sergio Oliveira (euluis)
+ */
+public class TestStereotypeUtility extends TestCase {
+
+ private Project proj;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ InitializeModel.initializeDefault();
+ // NOTE: we have to do this due to leftovers from other tests
+ // being causing strange errors when running in Eclipse.
+ ProfileMother.cleanAllExtents();
+ new InitProfileSubsystem().init();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (proj != null) {
+ ProjectManager.getManager().removeProject(proj);
+ }
+ super.tearDown();
+ }
+
+ /**
+ * Tests the scenario in which a Stereotype is already applied to a model
+ * element and it shouldn't be returned as an available Stereotype to be
+ * applied to the model element.
+ * (see <a
href="http://argouml.tigris.org/issues/show_bug.cgi?id=5969">issue 5969</a>).
+ * This test is for
+ * {...@link StereotypeUtility#getAvailableStereotypes(Object)}.
+ *
+ * @throws Exception When something goes wrong...
+ */
+ public void testGetAvailableStereotypesForAModelElementIssue5969()
+ throws Exception {
+ ProfileMother profileMother = new ProfileMother();
+ File profileFile = profileMother.createUnloadedSimpleProfile();
+ profileFile.deleteOnExit();
+ UserDefinedProfile profile = new UserDefinedProfile(profileFile,
+ ProfileFacade.getManager());
+ Collection profileModels = profile.getProfilePackages();
+ // TODO: the following fails due to the XMI writing saving all top
level
+ // model elements and because even if there was no empty project, by
+ // creating a class, the undo mechanism in the project manager will
+ // force the creation of an empty project.
+// assertEquals(1, profileModels.size());
+ Object profileModel = profileModels.iterator().next();
+ proj = ProjectManager.getManager().makeEmptyProject();
+ List models = proj.getUserDefinedModelList();
+ assertEquals("Unexpected number of user defined models.",
+ 1, models.size());
+ Object model = models.get(0);
+ proj.getProfileConfiguration().addProfile(profile, model);
+ Object aClass = Model.getCoreFactory().buildClass("AClass", model);
+ Set<Object> stereotypes = StereotypeUtility.getAvailableStereotypes(
+ aClass);
+ Object profileStereotype = findModelElementFromNamespace(stereotypes,
+ ProfileMother.STEREOTYPE_NAME_ST, profileModel);
+ assertNotNull("The profile stereotype named \""
+ + ProfileMother.STEREOTYPE_NAME_ST + "\" wasn't found.",
+ profileStereotype);
+ Model.getCoreHelper().addStereotype(aClass, profileStereotype);
+ // FIXME: fails here.
+// assertNull("The profile stereotype named \""
+// + ProfileMother.STEREOTYPE_NAME_ST + "\" shouldn't be found.",
+// findModelElementFromNamespace(
+// StereotypeUtility.getAvailableStereotypes(aClass),
+// ProfileMother.STEREOTYPE_NAME_ST, profileModel));
+ }
+
+ /**
+ * Find a model element in modelElements which name is equal to name.
+ *
+ * @param name the name of the model element to find. It can't be null.
+ * @param modelElements the {...@link Collection} of model elements in
which
+ * to find a model element with name.
+ * @return the model element if found or null.
+ *
+ * TODO: maybe should be moved to a helper class that deals with Model
+ * related stuff.
+ */
+ public static Object findModelElementNamed(String name,
+ Collection modelElements) {
+ for (Object me : modelElements) {
+ if (name.equals(Model.getFacade().getName(me))) {
+ return me;
+ }
+ }
+ return null;
+ }
+
+ static Object findModelElementFromNamespace(
+ Collection<Object> modelElements, String modelElementName,
+ Object namespace) {
+ for (Object me : modelElements) {
+ if (modelElementName.equals(Model.getFacade().getName(me))
+ && Model.getFacade().getNamespace(me) == namespace) {
+ return me;
+ }
+ }
+ return null;
+ }
+}
Removed:
trunk/src/argouml-app/tests/org/argouml/uml/ui/TestUMLTagDefinitionComboBoxModel.java
Url:
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/uml/ui/TestUMLTagDefinitionComboBoxModel.java?view=markup&pathrev=18233
Copied:
trunk/src/argouml-app/tests/org/argouml/uml/ui/foundation/extension_mechanisms/TestUMLTagDefinitionComboBoxModel.java
(from r18202,
/trunk/src/argouml-app/tests/org/argouml/uml/ui/TestUMLTagDefinitionComboBoxModel.java)
Url:
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/uml/ui/foundation/extension_mechanisms/TestUMLTagDefinitionComboBoxModel.java?view=diff&pathrev=18234&r1=18202&r2=18234
==============================================================================
---
/trunk/src/argouml-app/tests/org/argouml/uml/ui/TestUMLTagDefinitionComboBoxModel.java
(original)
+++
trunk/src/argouml-app/tests/org/argouml/uml/ui/foundation/extension_mechanisms/TestUMLTagDefinitionComboBoxModel.java
2010-04-09 15:39:12-0700
@@ -36,22 +36,33 @@
// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-package org.argouml.uml.ui;
+package org.argouml.uml.ui.foundation.extension_mechanisms;
+import java.io.File;
+import java.util.Collection;
+
+import org.argouml.FileHelper;
import org.argouml.kernel.Project;
import org.argouml.kernel.ProjectManager;
+import org.argouml.kernel.TestProjectWithProfiles;
import org.argouml.model.Model;
import org.argouml.ui.targetmanager.TargetEvent;
+import org.argouml.uml.StereotypeUtility;
+import org.argouml.uml.TestStereotypeUtility;
import
org.argouml.uml.ui.foundation.extension_mechanisms.UMLTagDefinitionComboBoxModel;
import junit.framework.TestCase;
import org.argouml.model.InitializeModel;
+import org.argouml.persistence.AbstractFilePersister;
+import org.argouml.profile.ProfileFacade;
+import org.argouml.profile.ProfileMother;
+import org.argouml.profile.UserDefinedProfile;
import org.argouml.profile.init.InitProfileSubsystem;
/**
* Test cases for the UMLTagDefinitionComboBoxModel class.
- *
- * @author euluis
+ *
+ * @author Luis Sergio Oliveira (euluis)
* @since 0.20
*/
public class TestUMLTagDefinitionComboBoxModel extends TestCase {
@@ -78,19 +89,19 @@
super(arg0);
}
- /*
- * @see junit.framework.TestCase#setUp()
- */
+ @Override
protected void setUp() throws Exception {
super.setUp();
InitializeModel.initializeDefault();
new InitProfileSubsystem().init();
- proj = ProjectManager.getManager().getCurrentProject();
- model = proj.getModel();
+ proj = ProjectManager.getManager().makeEmptyProject();
+ model = proj.getUserDefinedModelList().iterator().next();
+ }
- theClass = Model.getCoreFactory().buildClass("TheClass", model);
- theStereotype = Model.getExtensionMechanismsFactory().buildStereotype(
- theClass, "containedStereotype", model);
+ @Override
+ protected void tearDown() throws Exception {
+ ProjectManager.getManager().removeProject(proj);
+ super.tearDown();
}
/**
@@ -98,6 +109,9 @@
* applied in a class to which the stereotype is applied.
*/
public void testTagDefinitionFromStereotypeApplicableToStereotypedClass() {
+ theClass = Model.getCoreFactory().buildClass("TheClass", model);
+ theStereotype = Model.getExtensionMechanismsFactory().buildStereotype(
+ theClass, "containedStereotype", model);
Object theTagDefinition = Model.getExtensionMechanismsFactory().
buildTagDefinition("TagDefinition", theStereotype, null);
// Testing with more than one, since it failed with a manual test I
@@ -116,4 +130,122 @@
tagDefComboBoxModel.contains(theTagDefinition2));
}
+ /**
+ * Tests the scenario in which a Stereotype is already applied to a model
+ * element and it shouldn't be returned as an available Stereotype to be
+ * applied to the model element.
+ * (see <a href="http://argouml.tigris.org/TODO">issue 6008</a>).
+ * This test is for
+ * {...@link
UMLTagDefinitionComboBoxModel#getApplicableTagDefinitions(Object)}.
+ *
+ * WARNING: not a unit test, this is more like a functional test, where
+ * several subsystems are tested.
+ *
+ * This test does:
+ * <ol>
+ * <li>setup a user defined profile which isn't loaded by the model
+ * subsystem and contains a stereotype and this contains a
+ * tag definition</li>
+ * <li>create a new empty project</li>
+ * <li>add the profile to the project configuration</li>
+ * <li>create a class in the project model</li>
+ * <li>add the profile stereotype to the class</li>
+ * <li>check that the tag definition is returned by
+ * {...@link
UMLTagDefinitionComboBoxModel#getApplicableTagDefinitions(Object)}</li>
+ * <li>save the project</li>
+ * <li>initialize the model and profile subsystems to simulate a fresh
+ * ArgoUML session</li>
+ * <li>load the project</li>
+ * <li>check that the tag definition is returned by
+ * {...@link
UMLTagDefinitionComboBoxModel#getApplicableTagDefinitions(Object)}</li>
+ * </ol>
+ *
+ * @throws Exception When something goes wrong...
+ */
+ public void testGetApplicableTagDefinitionsIssue6008() throws Exception {
+ // setup a user defined profile which isn't loaded by the model
+ // subsystem and contains a stereotype and this contains a
+ // tag definition
+ ProjectManager.getManager().removeProject(proj);
+ ProfileMother profileMother = new ProfileMother();
+ final String profileName =
+ "Profile4testGetApplicableTagDefinitionsIssue6008";
+ File profileFile = profileMother.createUnloadedSimpleProfile(
+ profileName);
+ profileFile = FileHelper.moveFileToNewTempDirectory(profileFile,
+ profileName, ProfileMother.XMI_FILE_EXTENSION,
+ "testGetApplicableTagDefinitionsIssue6008");
+ profileFile.deleteOnExit();
+ profileFile.getParentFile().deleteOnExit();
+ UserDefinedProfile profile = new UserDefinedProfile(profileFile,
+ ProfileFacade.getManager());
+ Collection profileModels = profile.getProfilePackages();
+ // TODO: the following fails due to the XMI writing saving all top
level
+ // model elements and because even if there was no empty project, by
+ // creating a class, the undo mechanism in the project manager will
+ // force the creation of an empty project.
+// assertEquals(1, profileModels.size());
+ Object profileModel = TestStereotypeUtility.findModelElementNamed(
+ profileName, profileModels);
+ assertNotNull("Profile model not found.", profileModel);
+ // create a new empty project
+ proj = ProjectManager.getManager().makeEmptyProject();
+ model = proj.getUserDefinedModelList().iterator().next();
+ // add the profile to the project configuration
+ proj.getProfileConfiguration().addProfile(profile, model);
+ // create a class in the project model
+ Object aClass = Model.getCoreFactory().buildClass("AClass", model);
+ // add the profile stereotype to the class
+ Object stereotype = TestStereotypeUtility.findModelElementNamed(
+ ProfileMother.STEREOTYPE_NAME_ST,
+ StereotypeUtility.getAvailableStereotypes(aClass));
+ assertNotNull("Stereotype wasn't found or isn't applicable.",
+ stereotype);
+ Model.getCoreHelper().addStereotype(aClass, stereotype);
+ // check that the tag definition is returned by
+ // {...@link
UMLTagDefinitionComboBoxModel#getApplicableTagDefinitions(Object)}
+ Object tagDef = TestStereotypeUtility.findModelElementNamed(
+ ProfileMother.TAG_DEFINITION_NAME_TD,
+ Model.getFacade().getTagDefinitions(stereotype));
+ assertNotNull("Tag Definition wasn't found.", tagDef);
+ UMLTagDefinitionComboBoxModel tagDefCBModel =
+ new UMLTagDefinitionComboBoxModel();
+ Collection applicableTagDefs =
+ tagDefCBModel.getApplicableTagDefinitions(aClass);
+ assertNotNull("Tag Definition wasn't found in return value of "
+ + "tagDefCBModel.getApplicableTagDefinitions(aClass).",
+ TestStereotypeUtility.findModelElementNamed(
+ ProfileMother.TAG_DEFINITION_NAME_TD, applicableTagDefs));
+ // save the project
+ File projFile = File.createTempFile("projFile", ".zargo");
+ TestProjectWithProfiles.initAppVersion();
+ AbstractFilePersister persister =
+ TestProjectWithProfiles.saveProject(proj, projFile);
+ projFile.deleteOnExit();
+ ProjectManager.getManager().removeProject(proj);
+ // initialize the model and profile subsystems to simulate a fresh
+ // ArgoUML session
+ InitializeModel.initializeMDR();
+ new InitProfileSubsystem().init();
+ ProfileFacade.getManager().addSearchPathDirectory(
+ profileFile.getParent());
+ proj = persister.doLoad(projFile);
+ model = proj.getUserDefinedModelList().iterator().next();
+ // check that the tag definition is returned by
+ // {...@link
UMLTagDefinitionComboBoxModel#getApplicableTagDefinitions(Object)}
+ aClass = TestStereotypeUtility.findModelElementNamed("AClass",
+ Model.getCoreHelper().getAllClasses(model));
+ assertNotNull("AClass not found in loaded project model.", aClass);
+ tagDefCBModel = new UMLTagDefinitionComboBoxModel();
+ // FIXME: the following throws:
+ // org.argouml.model.InvalidElementException:
+ // javax.jmi.reflect.InvalidObjectException: Object with
+ // MOFID 127-0-1-1-(...)000E75 no longer exists.
+// applicableTagDefs =
tagDefCBModel.getApplicableTagDefinitions(aClass);
+// assertNotNull("Tag Definition wasn't found in return value of "
+// + "tagDefCBModel.getApplicableTagDefinitions(aClass), "
+// + "after loading the project.",
+// TestStereotypeUtility.findModelElementNamed(
+// ProfileMother.TAG_DEFINITION_NAME_TD, applicableTagDefs));
+ }
}
------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2537544
To unsubscribe from this discussion, e-mail:
[[email protected]].