svn commit: r13316 - branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: maurelio1234
Date: 2007-08-13 15:52:41-0700
New Revision: 13316

Added:
   branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/
   branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileConfiguration1.java
   branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileConfiguration2.java
   branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileJava.java
   branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileManagerImpl.java

Log:
updating tests

Added: branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileConfiguration1.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileConfiguration1.java?view=auto&rev=13316
==============================================================================
--- (empty file)
+++ branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileConfiguration1.java	2007-08-13 15:52:41-0700
@@ -0,0 +1,122 @@
+// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $

+// 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.uml.profile;

+

+import java.io.File;

+

+import junit.framework.TestCase;

+

+import org.argouml.kernel.Project;

+import org.argouml.kernel.ProjectImpl;

+import org.argouml.model.InitializeModel;

+

+/**

+ * Tests the ProfileConfiguration

+ *

+ * @author Marcos Aurélio

+ */

+public class TestProfileConfiguration1 extends TestCase {

+    /**

+     * The constructor.

+     *

+     * @param name the name of the test.

+     */

+    public TestProfileConfiguration1(String name) {

+        super(name);

+    }

+    

+    /*

+     * @see junit.framework.TestCase#setUp()

+     */

+    public void setUp() throws Exception {

+	super.setUp();

+        InitializeModel.initializeDefault();

+    }

+    

+    /**

+         * Tests whether the UML profile and formating strategy is set as the

+         * default ones

+         */

+    public void testUMLDefaultStrategyAndModel() {

+		Project p = new ProjectImpl();

+		ProfileConfiguration pc = new ProfileConfiguration(p);

+

+		assertTrue("UML profile has not been set as the default one!", pc

+				.getProfiles().contains(ProfileUML.getInstance()));

+		assertTrue("Java formating strategy has not been "

+				+ "set as the default one!",

+				pc.getFormatingStrategy() instanceof JavaFormatingStrategy);

+		assertTrue("Java's defaulf profile formating strategy is not being "

+				+ "used as the default formating strategy!", pc

+				.getFormatingStrategy() == ProfileUML.getInstance()

+				.getFormatingStrategy());

+	}

+    

+    /**

+     * Tests whether a new profile can be successfully added

+     */

+    public void testAddingNewProfile() {

+    	Project p = new ProjectImpl();

+    	ProfileConfiguration pc = new ProfileConfiguration(p);

+        Profile pr = new UserDefinedProfile(new File("someprofile"));

+

+        pc.addProfile(pr);

+        assertTrue("Profile was not correctly added to the configuration!", pc

+		.getProfiles().contains(pr));        

+    }

+

+    /**

+     * Tests whether a new profile can be successfully removed 

+     * from the configuration

+     */

+    public void testRemovingProfile() {

+    	Project p = new ProjectImpl();

+    	ProfileConfiguration pc = new ProfileConfiguration(p);

+        Profile pr = new UserDefinedProfile(new File("someprofile"));

+

+        if (!pc.getProfiles().contains(pr)) {

+            pc.addProfile(pr);

+            pc.removeProfile(pr);

+            assertTrue(

+		    "Profile was not correctly removed from the configuration!",

+		    !pc.getProfiles().contains(pr));

+        }

+    }

+    

+    /**

+     * Tests whether the configuration reacts properly when an unknow profile 

+     * is being removed. It should not throw any exceptions.

+     */

+    public void testRemovingUnknownProfile() {

+    	Project p = new ProjectImpl();

+		ProfileConfiguration pc = new ProfileConfiguration(p);

+		Profile pr = new UserDefinedProfile(new File("someprofile"));

+

+		if (!pc.getProfiles().contains(pr)) {

+			pc.removeProfile(pr);

+		}

+    }    

+    

+}


Added: branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileConfiguration2.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileConfiguration2.java?view=auto&rev=13316
==============================================================================
--- (empty file)
+++ branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileConfiguration2.java	2007-08-13 15:52:41-0700
@@ -0,0 +1,223 @@
+// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $

+// 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.uml.profile;

+

+import java.awt.Image;

+import java.awt.image.BufferedImage;

+import java.util.ArrayList;

+import java.util.Collection;

+import java.util.Iterator;

+

+import javax.swing.ImageIcon;

+

+import junit.framework.TestCase;

+

+import org.argouml.kernel.Project;

+import org.argouml.kernel.ProjectImpl;

+import org.argouml.model.InitializeModel;

+import org.argouml.model.Model;

+

+/**

+ * Tests the handling of the strategies and models provided by the installed

+ * profiles. 

+ *

+ * @author Marcos Aurélio

+ */

+public class TestProfileConfiguration2 extends TestCase {

+    /**

+     * The constructor.

+     *

+     * @param name the name of the test.

+     */

+    public TestProfileConfiguration2(String name) {

+        super(name);

+    }

+    

+    /*

+     * @see junit.framework.TestCase#setUp()

+     */

+    public void setUp() throws Exception {

+	super.setUp();

+        InitializeModel.initializeDefault();

+    }

+    

+    /**

+     * This class simulates a real profile, containing a model and 

+     * some strategies

+     * 

+     * @author Marcos Aurélio

+     */

+    private class FakeProfile extends Profile {

+	private Object model = null;

+	private FigNodeStrategy figNodeStrategy = null;

+	private FormatingStrategy formatStrategy = null;

+	

+	public FakeProfile() {

+	    model = Model.getModelManagementFactory().createModel();

+	    figNodeStrategy = new FakeFigNodeStrategy();

+	    formatStrategy = new FakeFormatingStrategy();

+	}

+	

+	public String getDisplayName() {

+	    return toString();

+	}

+

+	public FigNodeStrategy getFigureStrategy() {

+	    return figNodeStrategy;

+	}

+

+	public FormatingStrategy getFormatingStrategy() {

+	    return formatStrategy;

+	}

+

+	public Object getModel() {

+	    return model;

+	}

+

+	public FigNodeStrategy getFigNodeStrategy() {

+	    return figNodeStrategy;

+	}

+

+	public void setFigNodeStrategy(FigNodeStrategy figNodeStrategy) {

+	    this.figNodeStrategy = figNodeStrategy;

+	}

+

+	public FormatingStrategy getFormatStrategy() {

+	    return formatStrategy;

+	}

+

+	public void setFormatStrategy(FormatingStrategy formatStrategy) {

+	    this.formatStrategy = formatStrategy;

+	}

+

+	@Override

+	public Collection getProfilePackages() throws ProfileException {

+		return new ArrayList();

+	}

+	

+    }

+    

+    /**

+     * This class simulates a FigNodeStrategy

+     * 

+     * @author Marcos Aurélio

+     */

+    private class FakeFigNodeStrategy implements FigNodeStrategy {

+	

+	public Image getIconForStereotype(Object stereotype) {

+	    return null;

+	}

+	

+    }

+

+    /**

+     * This class simulates a FormatingStrategy

+     * 

+     * @author Marcos Aurélio

+     */

+    private class FakeFormatingStrategy implements FormatingStrategy {

+

+	public String formatCollection(Iterator iter, Object namespace) {

+	    return "";

+	}

+

+	public String formatElement(Object element, Object namespace) {

+	    return "";

+	}

+	

+    }

+    

+    /**

+     * Whether a formating strategy can be property activated

+     */

+    public void testActivateFormatingStrategy() {

+    	Project p = new ProjectImpl();

+		ProfileConfiguration pc = new ProfileConfiguration(p);

+

+		Profile pr = new FakeProfile();

+

+		pc.addProfile(pr);

+		pc.activateFormatingStrategy(pr);

+

+		assertTrue("FormatingStrategy was not properly activated!", pc

+				.getFormatingStrategy() == pr.getFormatingStrategy());

+    }

+

+    /**

+     * When a profile is removed its formating strategy should also be removed  

+     */

+    public void testActivateFormatingStrategyAndRemoveProfile() {

+    	Project p = new ProjectImpl();

+		ProfileConfiguration pc = new ProfileConfiguration(p);

+

+		Profile pr = new FakeProfile();

+

+		pc.addProfile(pr);

+		pc.activateFormatingStrategy(pr);

+		pc.removeProfile(pr);

+

+		assertTrue("FormatingStrategy was not properly removed "

+				+ "when the profile was removed!",

+				pc.getFormatingStrategy() != pr.getFormatingStrategy());

+    }

+    

+    /**

+     * The formating strategy should come from a profile that has been 

+     * registered and provide one.   

+     */

+    public void testActivateInvalidFormatingStrategy() {

+    	Project p = new ProjectImpl();

+		ProfileConfiguration pc = new ProfileConfiguration(p);

+

+		Profile pr1 = new FakeProfile();

+		Profile pr2 = new FakeProfile();

+		Profile pr3 = new FakeProfile();

+

+		((FakeProfile) pr2).setFormatStrategy(null);

+

+		pc.addProfile(pr1);

+		pc.addProfile(pr2);

+

+		// this should not raise any exception

+		pc.activateFormatingStrategy(null);

+

+		pc.activateFormatingStrategy(pr1);

+		pc.activateFormatingStrategy(pr2);

+		assertTrue("Activating the formating strategy of a profile that "

+				+ "does not provide one should not take any effect!", pc

+				.getFormatingStrategy() == pr1.getFormatingStrategy());

+

+		pc.removeProfile(pr1);

+		assertTrue("FormatingStrategy was not properly removed "

+				+ "when the providing profile was removed!", pc

+				.getFormatingStrategy() == null);

+

+		FormatingStrategy before = pc.getFormatingStrategy();

+		pc.activateFormatingStrategy(pr3);

+		assertTrue("Activating the formating strategy of a profile that "

+				+ "is has not been registered should not take any effect!", pc

+				.getFormatingStrategy() == before);

+    }

+}


Added: branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileJava.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileJava.java?view=auto&rev=13316
==============================================================================
--- (empty file)
+++ branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileJava.java	2007-08-13 15:52:41-0700
@@ -0,0 +1,72 @@
+// $Id: TestProfileJava.java 13253 2007-08-06 16:24:12Z maurelio1234 $

+// Copyright (c) 1996-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.uml.profile;

+

+import java.util.Collection;

+

+import junit.framework.TestCase;

+

+import org.argouml.model.InitializeModel;

+import org.argouml.model.Model;

+

+/**

+ * 

+ * @author euluis

+ * @since 0.20

+ * @version 0.00

+ */

+public class TestProfileJava extends TestCase {

+    

+    /**

+     * The constructor.

+     *

+     * @param name the name of the test.

+     */

+    public TestProfileJava(String name) {

+        super(name);

+    }

+    

+    /*

+     * @see junit.framework.TestCase#setUp()

+     */

+    public void setUp() throws Exception {

+	super.setUp();

+        InitializeModel.initializeDefault();

+    }

+

+    /**

+     * Test whether we can load default model (profile). ProfileJava will just 

+     * create and return an empty model if the file for the profile doesn't 

+     * exist.

+     */

+    public void testLoadProfileModel() {

+        ProfileUML profile = ProfileUML.getInstance();

+        Object model = profile.getModel();

+        Collection stereos = Model.getModelManagementHelper()

+                .getAllModelElementsOfKind(model,

+                        Model.getMetaTypes().getStereotype());

+        assertTrue("No stereotypes found in profile model", stereos.size() > 0);

+    }

+}


Added: branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileManagerImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileManagerImpl.java?view=auto&rev=13316
==============================================================================
--- (empty file)
+++ branches/gsoc2007/maurelio1234/branch2/tests/org/argouml/uml/profile/TestProfileManagerImpl.java	2007-08-13 15:52:41-0700
@@ -0,0 +1,85 @@
+// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $

+// 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.uml.profile;

+

+import java.io.File;

+

+import junit.framework.TestCase;

+

+/**

+ * Tests for the default implementation of the ProfileManager

+ *

+ * @author Marcos Aurélio

+ */

+public class TestProfileManagerImpl extends TestCase {

+    /**

+     * The constructor.

+     *

+     * @param name the name of the test.

+     */

+    public TestProfileManagerImpl(String name) {

+        super(name);

+    }

+    

+    /**

+     * Test whether the ProfileManager can register a new profile

+     */

+    public void testRegisterProfile() {

+        Profile profile = new UserDefinedProfile(new File("someprofile"));

+        ProfileManager manager = ProfileManagerImpl.getInstance();

+        manager.registerProfile(profile);        

+        assertTrue("Profile was not correctly registered", manager

+		.getRegisteredProfiles().contains(profile));

+    }

+

+    /**

+     * Test whether the ProfileManager can remove a previously registered 

+     * profile

+     */

+    public void testUnregisterRegisteredProfile() {

+        Profile profile = new UserDefinedProfile(new File("someprofile"));

+        ProfileManager manager = ProfileManagerImpl.getInstance();

+        

+        if (!manager.getRegisteredProfiles().contains(profile)) {

+            manager.registerProfile(profile);

+            manager.removeProfile(profile);

+            assertTrue("Profile was not correctly unregistered", !manager

+    		.getRegisteredProfiles().contains(profile));

+        }

+    }

+    

+    /**

+     * Test whether the ProfileManager can handle a non proviously registered 

+     * profile being removed. In this case it should not raise any exception.

+     */

+    public void testUnregisterUnknownProfile() {

+        Profile profile = new UserDefinedProfile(new File("someprofile"));

+        ProfileManager manager = ProfileManagerImpl.getInstance();

+        

+        if (!manager.getRegisteredProfiles().contains(profile)) {

+            manager.removeProfile(profile);

+        }

+    }       

+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.