Author: euluis
Date: 2008-01-07 16:20:26-0800
New Revision: 14029

Added:
   trunk/tests/org/argouml/FileHelper.java   (contents, props changed)
   trunk/tests/org/argouml/profile/ProfileMother.java   (contents, props 
changed)
   trunk/tests/org/argouml/profile/TestProfileMother.java   (contents, props 
changed)
   trunk/tests/org/argouml/profile/TestUserDefinedProfile.java   (contents, 
props changed)
Modified:
   trunk/src_new/org/argouml/profile/ProfileFacade.java
   trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java
   trunk/tests/org/argouml/profile/TestProfileManager.java
   trunk/tests/org/argouml/profile/internal/TestProfileManagerImpl.java

Log:
Issue 4946: adding a failing test.

Modified: trunk/src_new/org/argouml/profile/ProfileFacade.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/profile/ProfileFacade.java?view=diff&rev=14029&p1=trunk/src_new/org/argouml/profile/ProfileFacade.java&p2=trunk/src_new/org/argouml/profile/ProfileFacade.java&r1=14028&r2=14029
==============================================================================
--- trunk/src_new/org/argouml/profile/ProfileFacade.java        (original)
+++ trunk/src_new/org/argouml/profile/ProfileFacade.java        2008-01-07 
16:20:26-0800
@@ -77,5 +77,12 @@
     }
 
     private static ProfileManager manager;
+
+    /**
+     * @return true is subsystem is initialized or false otherwise
+     */
+    public static boolean isInitiated() {
+        return manager != null;
+    }
     
 }

Added: trunk/tests/org/argouml/FileHelper.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/FileHelper.java?view=auto&rev=14029
==============================================================================
--- (empty file)
+++ trunk/tests/org/argouml/FileHelper.java     2008-01-07 16:20:26-0800
@@ -0,0 +1,70 @@
+// $Id$
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml;
+
+import java.io.File;
+
+/**
+ * Helper for common File related operations used in automated tests.
+ *
+ * @author Luis Sergio Oliveira (euluis)
+ */
+public class FileHelper {
+
+    /**
+     * System temporary directory property name.
+     */
+    public static final String SYSPROPNAME_TMPDIR = "java.io.tmpdir";
+
+
+    public static File getTmpDir() {
+        return new File(System.getProperty(SYSPROPNAME_TMPDIR));
+    }
+
+    /**
+     * Setup a directory with the given name for the caller test.
+     * 
+     * @param dirName the directory to be created in the system temporary dir
+     * @return the created directory
+     */
+    public static File setUpDir4Test(String dirName) {
+        File generationDir = new File(getTmpDir(), dirName);
+        generationDir.mkdirs();
+        return generationDir;
+    }
+    
+    public static File setUpDir4Test(Class<?> testClass) {
+        String name = testClass.getPackage().getName() + "." 
+            + testClass.getSimpleName();
+        return setUpDir4Test(name);
+    }
+    
+    public static void deleteDir(File dir) {
+        if (dir != null && dir.exists()) {
+            dir.delete();
+        }
+    }
+
+}

Modified: trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java?view=diff&rev=14029&p1=trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java&p2=trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java&r1=14028&r2=14029
==============================================================================
--- trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java (original)
+++ trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java 2008-01-07 
16:20:26-0800
@@ -24,13 +24,18 @@
 
 package org.argouml.kernel;
 
+import static org.argouml.model.Model.getCoreFactory;
+import static org.argouml.model.Model.getExtensionMechanismsHelper;
 import static org.argouml.model.Model.getFacade;
+import static org.argouml.model.Model.getModelManagementFactory;
 
 import java.io.File;
 import java.lang.reflect.Method;
+import java.util.Collection;
 
 import junit.framework.TestCase;
 
+import org.argouml.FileHelper;
 import org.argouml.application.helpers.ApplicationVersion;
 import org.argouml.model.InitializeModel;
 import org.argouml.model.Model;
@@ -39,6 +44,8 @@
 import org.argouml.profile.Profile;
 import org.argouml.profile.ProfileFacade;
 import org.argouml.profile.ProfileManager;
+import org.argouml.profile.ProfileMother;
+import org.argouml.profile.UserDefinedProfile;
 import org.argouml.profile.init.InitProfileSubsystem;
 
 /**
@@ -50,6 +57,8 @@
  */
 public class TestProjectWithProfiles extends TestCase {
 
+    private File testCaseDir;
+
     /*
      * @see junit.framework.TestCase#setUp()
      */
@@ -60,13 +69,21 @@
         new InitProfileSubsystem().init();
         
         if (ApplicationVersion.getVersion() == null) {
-            Class<?> argoVersionClass = 
+            Class argoVersionClass = 
                 Class.forName("org.argouml.application.ArgoVersion");
             Method initMethod = argoVersionClass.getDeclaredMethod("init");
             initMethod.setAccessible(true);
             initMethod.invoke(null);
             assertNotNull(ApplicationVersion.getVersion());
         }
+        String testCaseDirName = getClass().getPackage().getName();
+        testCaseDir = FileHelper.setUpDir4Test(testCaseDirName);
+    }
+    
+    @Override
+    protected void tearDown() throws Exception {
+        FileHelper.deleteDir(testCaseDir);
+        super.tearDown();
     }
 
     public void testCreatedProjectContainsProfileConfiguration() {
@@ -142,11 +159,9 @@
                 returnParamType);
         assertNotNull(project.findType("Foo", false));
         // save the project into a new file
-        File file = getFileInUsersTemporaryDirectory(
+        File file = getFileInTestDir(
                 "testRemoveProfileWithModelThatRefersToProfile.zargo");
-        AbstractFilePersister persister = 
-            PersistenceManager.getInstance().getPersisterFromFileName(
-                    file.getAbsolutePath());
+        AbstractFilePersister persister = getProjectPersister(file);
         project.setVersion(ApplicationVersion.getVersion());
         persister.save(project, file);
         // reopen the project and assert that the Java profile isn't part of 
@@ -179,15 +194,82 @@
                 getFacade().getNamespace(returnParamType));
     }
 
-    private static final String SYSPROPNAME_TMPDIR = "java.io.tmpdir";
-
-    private File getFileInUsersTemporaryDirectory(String fileName) {
-        String tmpDirName = System.getProperty(SYSPROPNAME_TMPDIR);
-        String testCaseDirName = getClass().getPackage().getName();
-        File tmpDir = new File(tmpDirName);
-        File testCaseDir = new File(tmpDir, testCaseDirName);
-        testCaseDir.mkdir();
+    private File getFileInTestDir(String fileName) {
         return new File(testCaseDir, fileName);
     }
+    
+    /**
+     * 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</li>
+     *   <li>add it to the project configuration</li>
+     *   <li>create a dependency between the project's model and the user 
+     *   defined profile</li>
+     *   <li>save the project</li>
+     *   <li>load the project and assert that the model element that depends 
on 
+     *   the profile is consistent</li>
+     * </ol>
+     * 
+     * @throws Exception when things go wrong
+     */
+    public void testProjectWithUserDefinedProfilePersistency() 
+        throws Exception {
+        // setup a user defined profile
+        ProfileMother mother = new ProfileMother();
+        Object profileModel = mother.createSimpleProfileModel();
+        File userDefinedProfileFile = new File(testCaseDir, 
+                "testProjectWithUserDefinedProfilePersistency.xmi");
+        mother.saveProfileModel(profileModel, userDefinedProfileFile);
+        // add it to the project configuration
+        Profile userDefinedProfile = 
+            new UserDefinedProfile(userDefinedProfileFile);
+        ProfileManager profileManager = ProfileFacade.getManager();
+        profileManager.registerProfile(userDefinedProfile);
+        Project project = ProjectManager.getManager().makeEmptyProject();
+        project.getProfileConfiguration().addProfile(userDefinedProfile);
+        // create a dependency between the project's model and the user 
defined 
+        // profile
+        Object model = getModelManagementFactory().getRootModel();
+        Object fooClass = getCoreFactory().buildClass("Foo", model);
+        Collection stereotypes = getExtensionMechanismsHelper().getStereotypes(
+                project.getModels());
+        Object stStereotype = null;
+        for (Object stereotype : stereotypes) {
+            if (ProfileMother.STEREOTYPE_NAME_ST.equals(
+                    getFacade().getName(stereotype))) {
+                stStereotype = stereotype;
+                break;
+            }
+        }
+        Model.getCoreHelper().addStereotype(fooClass, stStereotype);
+        // save the project
+        File file = getFileInTestDir(
+            "testProjectWithUserDefinedProfilePersistency.zargo");
+        AbstractFilePersister persister = getProjectPersister(file);
+        project.setVersion(ApplicationVersion.getVersion());
+        persister.save(project, file);
+        // load the project
+        // FIXME: known failure here as documented in issue #4946
+        project = persister.doLoad(file);
+        project.postLoad();
+        // assert that the model element that depends on the profile is 
+        // consistent
+        fooClass = project.findType("Foo", false);
+        assertNotNull(fooClass);
+        Collection fooStereotypes = getFacade().getStereotypes(fooClass);
+        assertEquals(1, fooStereotypes.size());
+        assertEquals(ProfileMother.STEREOTYPE_NAME_ST, 
+                getFacade().getNamespace(fooStereotypes.iterator().next()));
+    }
+
+    private AbstractFilePersister getProjectPersister(File file) {
+        AbstractFilePersister persister = 
+            PersistenceManager.getInstance().getPersisterFromFileName(
+                    file.getAbsolutePath());
+        return persister;
+    }
 
 }

Added: trunk/tests/org/argouml/profile/ProfileMother.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/profile/ProfileMother.java?view=auto&rev=14029
==============================================================================
--- (empty file)
+++ trunk/tests/org/argouml/profile/ProfileMother.java  2008-01-07 16:20:26-0800
@@ -0,0 +1,127 @@
+// $Id$
+// Copyright (c) 2007 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.profile;
+
+import static org.argouml.model.Model.getCoreHelper;
+import static org.argouml.model.Model.getExtensionMechanismsFactory;
+import static org.argouml.model.Model.getExtensionMechanismsHelper;
+import static org.argouml.model.Model.getFacade;
+import static org.argouml.model.Model.getModelManagementFactory;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+
+import org.argouml.model.Model;
+import org.argouml.model.XmiWriter;
+import org.argouml.persistence.UmlFilePersister;
+
+/**
+ * Based on the 
+ * <a href="http://www.xpuniverse.com/2001/pdfs/Testing03.pdf";>ObjectMother 
+ * design pattern</a>, provides reusable facilities to create profiles.
+ *
+ * @author Luis Sergio Oliveira (euluis)
+ */
+public class ProfileMother {
+    
+    private static final Logger LOG = Logger.getLogger(ProfileMother.class);
+
+    /**
+     * "profile"
+     */
+    public static final String STEREOTYPE_NAME_PROFILE = "profile";
+    /**
+     * "st" the example stereotype name.
+     */
+    public static final String STEREOTYPE_NAME_ST = "st";
+
+    public Object createSimpleProfileModel() {
+        Object model = getModelManagementFactory().createModel();
+        Object profileStereotype = getProfileStereotype();
+        getCoreHelper().addStereotype(model, profileStereotype);
+        Object fooClass = Model.getCoreFactory().buildClass("foo", model);
+        getExtensionMechanismsFactory().buildStereotype(fooClass, 
+                STEREOTYPE_NAME_ST, model);
+        return model;
+    }
+
+    Object getProfileStereotype() {
+        Object umlProfile = getUmlProfileModel();
+        Collection<Object> models = new ArrayList<Object>();
+        models.add(umlProfile);
+        Collection stereotypes = getExtensionMechanismsHelper().getStereotypes(
+            models);
+        for (Object stereotype : stereotypes) {
+            if (STEREOTYPE_NAME_PROFILE.equals(
+                    Model.getFacade().getName(stereotype)))
+                return stereotype;
+        }
+        return null;
+    }
+    
+    private Object umlProfileModel;
+
+    Object getUmlProfileModel() {
+        if (ProfileFacade.isInitiated()) {
+            try {
+                umlProfileModel = ProfileFacade.getManager().getUMLProfile().
+                    getProfilePackages().iterator().next();
+                TestCase.assertTrue(getFacade().isAModel(umlProfileModel));
+            } catch (ProfileException e) {
+                LOG.error("Exception", e);
+            }
+        }
+        if (umlProfileModel == null) {
+            umlProfileModel = getModelManagementFactory().createModel();
+            getExtensionMechanismsFactory().buildStereotype(
+                umlProfileModel, STEREOTYPE_NAME_PROFILE, umlProfileModel);
+        }
+        return umlProfileModel;
+    }
+
+    public void saveProfileModel(Object model, File file) throws IOException {
+        FileOutputStream fileOut = new FileOutputStream(file);
+        try {
+            XmiWriter xmiWriter = Model.getXmiWriter(model, fileOut, "x(" 
+                    + UmlFilePersister.PERSISTENCE_VERSION + ")");
+            xmiWriter.write();
+            fileOut.flush();
+        } catch (Exception e) {
+            String msg = "Exception while saving profile model.";
+            LOG.error(msg, e);
+            throw new IOException(msg);
+        } finally {
+            fileOut.close();
+        }
+    }
+
+}

Modified: trunk/tests/org/argouml/profile/TestProfileManager.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/profile/TestProfileManager.java?view=diff&rev=14029&p1=trunk/tests/org/argouml/profile/TestProfileManager.java&p2=trunk/tests/org/argouml/profile/TestProfileManager.java&r1=14028&r2=14029
==============================================================================
--- trunk/tests/org/argouml/profile/TestProfileManager.java     (original)
+++ trunk/tests/org/argouml/profile/TestProfileManager.java     2008-01-07 
16:20:26-0800
@@ -46,7 +46,6 @@
 
     @Override
     protected void setUp() throws Exception {
-        super.setUp();
         InitializeModel.initializeDefault();
         new InitProfileSubsystem().init();
         mockProfile = new Profile() {

Added: trunk/tests/org/argouml/profile/TestProfileMother.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/profile/TestProfileMother.java?view=auto&rev=14029
==============================================================================
--- (empty file)
+++ trunk/tests/org/argouml/profile/TestProfileMother.java      2008-01-07 
16:20:26-0800
@@ -0,0 +1,92 @@
+// $Id$
+// Copyright (c) 2007 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.profile;
+
+import static org.argouml.model.Model.getExtensionMechanismsHelper;
+import static org.argouml.model.Model.getFacade;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.argouml.model.InitializeModel;
+import org.argouml.model.Model;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author Luis Sergio Oliveira (euluis)
+ */
+public class TestProfileMother extends TestCase {
+    
+    private ProfileMother mother;
+    private File testDir;
+
+    @Override
+    protected void setUp() throws Exception {
+        InitializeModel.initializeDefault();
+        mother = new ProfileMother();
+    }
+    
+    public void testCreateProfileModel() {
+        Object model = mother.createSimpleProfileModel();
+        assertNotNull(model);
+        Collection profileStereotypes = getFacade().getStereotypes(model);
+        assertEquals(1, profileStereotypes.size());
+        assertEquals(ProfileMother.STEREOTYPE_NAME_PROFILE, 
+            getFacade().getName(profileStereotypes.iterator().next()));
+    }
+    
+    public void testCreateSimpleProfileModel() throws Exception {
+        final Object model = mother.createSimpleProfileModel();
+        Collection<Object> models = new ArrayList<Object>() { {
+                add(model);
+            }
+        };
+        Collection stereotypes = 
+            getExtensionMechanismsHelper().getStereotypes(models);
+        Object st = null;
+        for (Object stereotype : stereotypes) {
+            if (ProfileMother.STEREOTYPE_NAME_ST.equals(
+                    getFacade().getName(stereotype))) {
+                st = stereotype;
+                break;
+            }
+        }
+        assertNotNull("\"st\" stereotype not found in model.", st);
+        assertTrue(Model.getExtensionMechanismsHelper().isStereotype(st, 
+                ProfileMother.STEREOTYPE_NAME_ST, "Class"));
+    }
+    
+    public void testSaveProfileModel() throws Exception {
+        Object model = mother.createSimpleProfileModel();
+        File file = new File(testDir, "testSaveProfileModel.xmi");
+        mother.saveProfileModel(model, file);
+        assertTrue("The file to where the file was supposed to be saved " 
+                + "doesn't exist.", file.exists());
+    }
+    
+}

Added: trunk/tests/org/argouml/profile/TestUserDefinedProfile.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/profile/TestUserDefinedProfile.java?view=auto&rev=14029
==============================================================================
--- (empty file)
+++ trunk/tests/org/argouml/profile/TestUserDefinedProfile.java 2008-01-07 
16:20:26-0800
@@ -0,0 +1,73 @@
+// $Id$
+// Copyright (c) 2007 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.profile;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.argouml.FileHelper;
+import org.argouml.model.InitializeModel;
+
+/**
+ * Some basic tests for the [EMAIL PROTECTED] UserDefinedProfile} class.
+ * 
+ * @author Luis Sergio Oliveira (euluis)
+ */
+public class TestUserDefinedProfile extends TestCase {
+    
+    private File testDir;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        InitializeModel.initializeDefault();
+        testDir = FileHelper.setUpDir4Test(getClass());
+    }
+    
+    @Override
+    protected void tearDown() throws Exception {
+        FileHelper.deleteDir(testDir);
+        super.tearDown();
+    }
+    
+    /**
+     * Test loading of a very simple profile via its constructor. Check that 
its
+     * display name contains the file name.
+     * 
+     * @throws Exception if something goes wrong
+     */
+    public void testLoadingConstructor() throws Exception {
+        // create profile model
+        ProfileMother profileMother = new ProfileMother();
+        Object model = profileMother.createSimpleProfileModel();
+        // save the profile into a xmi file
+        File profileFile = new File(testDir, "testLoadingConstructor.xmi");
+        profileMother.saveProfileModel(model, profileFile);
+        Profile profile = new UserDefinedProfile(profileFile);
+        assertTrue(profile.getDisplayName().contains(profileFile.getName()));
+    }
+
+}

Modified: trunk/tests/org/argouml/profile/internal/TestProfileManagerImpl.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/profile/internal/TestProfileManagerImpl.java?view=diff&rev=14029&p1=trunk/tests/org/argouml/profile/internal/TestProfileManagerImpl.java&p2=trunk/tests/org/argouml/profile/internal/TestProfileManagerImpl.java&r1=14028&r2=14029
==============================================================================
--- trunk/tests/org/argouml/profile/internal/TestProfileManagerImpl.java        
(original)
+++ trunk/tests/org/argouml/profile/internal/TestProfileManagerImpl.java        
2008-01-07 16:20:26-0800
@@ -52,14 +52,14 @@
 
     public void testProfileManagerImpl() {
         List<Profile> registeredProfiles = manager.getRegisteredProfiles();
-        assertEquals(2, registeredProfiles.size());
-        Set<String> profileNameSet = new HashSet<String>();
+        assertTrue(2 <= registeredProfiles.size());
+        Set<String> internalProfileNameSet = new HashSet<String>();
         for (Profile profile : registeredProfiles) {
-            assertTrue(profile.getDisplayName().equals(ProfileUML.NAME) 
-                    || profile.getDisplayName().equals(ProfileJava.NAME));
-            profileNameSet.add(profile.getDisplayName());
+            if (profile.getDisplayName().equals(ProfileUML.NAME) 
+                    || profile.getDisplayName().equals(ProfileJava.NAME))
+                internalProfileNameSet.add(profile.getDisplayName());
         }
-        assertEquals(2, profileNameSet.size());
+        assertEquals(2, internalProfileNameSet.size());
     }
     
     public void testRemoveProfileThatIsntDefault() {

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to