Author: tfmorris
Date: 2007-05-09 07:19:16-0700
New Revision: 12576
Modified:
trunk/tests/org/argouml/model/CheckUMLModelHelper.java
trunk/tests/org/argouml/model/TestActivityGraphsFactory.java
trunk/tests/org/argouml/model/TestActivityGraphsHelper.java
trunk/tests/org/argouml/model/TestAgainstUmlModel.java
trunk/tests/org/argouml/model/TestCollaborationsFactory.java
trunk/tests/org/argouml/model/TestCommonBehaviorFactory.java
trunk/tests/org/argouml/model/TestCommonBehaviorHelper.java
trunk/tests/org/argouml/model/TestCoreFactory.java
trunk/tests/org/argouml/model/TestCoreHelper.java
trunk/tests/org/argouml/model/TestExtensionMechanismsFactory.java
trunk/tests/org/argouml/model/TestModelManagementFactory.java
trunk/tests/org/argouml/model/TestStateMachinesFactory.java
trunk/tests/org/argouml/model/TestStateMachinesHelper.java
trunk/tests/org/argouml/model/TestUseCasesFactory.java
Log:
Extend Model subsystem tests to cover recognizers and DataTypesFactory
Fix method lookup to use public API only
Reduce visibility of all implementation classes to default (package)
Modified: trunk/tests/org/argouml/model/CheckUMLModelHelper.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/CheckUMLModelHelper.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/CheckUMLModelHelper.java&p2=trunk/tests/org/argouml/model/CheckUMLModelHelper.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/CheckUMLModelHelper.java (original)
+++ trunk/tests/org/argouml/model/CheckUMLModelHelper.java 2007-05-09 07:19:16-0700
@@ -1,5 +1,5 @@
// $Id$
-// Copyright (c) 2002-2006 The Regents of the University of California. All
+// Copyright (c) 2002-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
@@ -26,6 +26,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.List;
import junit.framework.TestCase;
@@ -47,7 +48,7 @@
}
/**
- * Deleted a model object, looses the refence and then checks that
+ * Delete a model object, frees the reference and then checks that
* the object is reclaimed.
*
* This must be called with just one reference to the object or
@@ -71,7 +72,7 @@
}
/**
- * Deleted a model object, looses the reference and then checks that
+ * Delete a model object, frees the reference and then checks that
* the object is reclaimed.
*
* This must be called with just one reference to the object or
@@ -101,45 +102,70 @@
}
/**
- * Creates a UML modelelement (i.e. check if a creation function exists).
+ * Create a UML modelelement (i.e. check if a creation function exists).
* Then deletes it, looses the reference and then checks that
* the object is reclaimed.
*
* @param factory the DataTypesFactory
* @param names the UML elements to test
- * @param args the arguments of the UML elements
+ * @param arguments the arguments of the UML elements
*/
public static void createAndRelease(Object factory,
String[] names,
- Object[] args) {
- Class [] classes = new Class[args.length];
- for (int i = 0; i < args.length; i++) {
- classes[i] = args[i].getClass();
+ Object[] arguments) {
+ Class [] argTypes = new Class[arguments.length];
+ for (int i = 0; i < arguments.length; i++) {
+ argTypes[i] = arguments[i].getClass();
}
+
+ // Multiplicity, MultiplicityRange, and all Expression subtypes
+ // don't have 0-argument create methods, so we special case them.
+ Integer[] multArgs = {1, 1};
+ Class[] multArgTypes = {int.class, int.class};
+ String [] exprArgs = {"body text", "language text"};
+ Class[] exprArgTypes = {String.class, String.class};
for (int i = 0; i < names.length; i++) {
+ Class[] types;
+ Object[] args;
if (names[i] == null) {
continue;
- }
+ } else if (names[i].startsWith("Multiplicity")) {
+ types = multArgTypes;
+ args = multArgs;
+ } else if (names[i].endsWith("Expression")) {
+ types = exprArgTypes;
+ args = exprArgs;
+ } else {
+ types = argTypes;
+ args = arguments;
+ }
String methodName = "create" + names[i];
- Method method;
- try {
- // Make sure the create method is in the official interface
- if (!checkInterface(factory.getClass(), Factory.class,
- methodName, classes)) {
- TestCase.fail("Method " + methodName
- + " does not exist in any interface of factory "
- + factory.getClass().getName());
- return;
- } else {
- // Now get the factory implementation method to be invoked
- method =
- factory.getClass().getDeclaredMethod(methodName,
- classes);
- }
- } catch (NoSuchMethodException e) {
- TestCase.fail("Method " + methodName
- + " does not exist in factory " + factory);
+ Method createMethod;
+
+ // Find the create method in the offical API
+ createMethod = findMethod(factory.getClass(), Factory.class,
+ methodName, types);
+ if (createMethod == null) {
+ TestCase.fail("Method " + methodName
+ + " does not exist in any interface of factory "
+ + factory.getClass().getName());
+ return;
+ }
+
+
+ Method isAMethod;
+ String isAMethodName = "isA" + names[i];
+ Object facade = Model.getFacade();
+ try {
+ // Now get the factory implementation method to be invoked
+ isAMethod =
+ Facade.class.getDeclaredMethod(
+ isAMethodName,
+ new Class[] {Object.class});
+ } catch (NoSuchMethodException e) {
+ TestCase.fail("Method " + isAMethodName
+ + " does not exist in Facade");
return;
}
@@ -147,13 +173,21 @@
// Extra careful now, not to keep any references to the
// second argument.
try {
- deleteAndRelease(method.invoke(factory, args), names[i]);
+ Object element = invoke(createMethod, factory, args);
+ TestCase.assertTrue("Facade method " + isAMethodName
+ + " returned false", (Boolean) invoke(
+ isAMethod, facade, new Object[] {
+ element
+ }));
+
+ deleteAndRelease(
+ createMethod.invoke(factory, args), names[i]);
} catch (ClassCastException e) {
// Here it is another object sent to the test.
- deleteAndRelease(method.invoke(factory, args));
+ deleteAndRelease(createMethod.invoke(factory, args));
} catch (IllegalArgumentException e) {
// Here it is another object sent to the test.
- deleteAndRelease(method.invoke(factory, args));
+ deleteAndRelease(createMethod.invoke(factory, args));
}
} catch (IllegalAccessException e) {
TestCase.fail("Method create" + names[i]
@@ -166,11 +200,30 @@
}
}
}
+
+ /**
+ * Convenience method to invoke a method and convert any thrown exceptions
+ * to test failures with a useful message.
+ */
+ private static Object invoke(Method method, Object object, Object[] args) {
+ try {
+ return method.invoke(object, args);
+ } catch (IllegalAccessException e) {
+ TestCase.fail("Method " + method.getName() + " in " + object
+ + " cannot be called");
+ } catch (InvocationTargetException e) {
+ TestCase.fail("Method " + method.getName() + " in " + object
+ + " throws an exception.");
+ }
+ return null;
+ }
+
/**
- * Check all interfaces of the given class for an interface which both:
- * 1) extends the given marker interface (in our case called 'Factory')
- * 2) contains the given method.<p>
+ * Check all interfaces of the given class for an interface which both: 1)
+ * extends the given marker interface (in our case called 'Factory') 2)
+ * contains the given method.
+ * <p>
*
* This extra check is to make sure that the public methods of the given
* factory are actually part of the public API interface.
@@ -181,35 +234,37 @@
* the class of the marker interface to look for
* @param methodName
* the name of the object that we want to create
- * @param classes
- * the types of the argments for the method
+ * @param argTypes
+ * the types of the arguments for the method
+ * @return the requested method or null if no match is found
*/
- private static boolean checkInterface(Class factory, Class markerInterface,
- String methodName, Class[] classes) {
+ private static Method findMethod(Class factory,
+ Class markerInterface, String methodName, Class[] argTypes) {
Class[] interfaces = factory.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
if (markerInterface.equals(interfaces[i])) {
- if (hasMethod(factory, methodName, classes)) {
- return true;
+ Method m = getMethod(factory, methodName, argTypes);
+ if (m != null) {
+ return m;
}
} else {
- if (checkInterface(interfaces[i], markerInterface, methodName,
- classes)) {
- return true;
+ Method m =
+ findMethod(
+ interfaces[i], markerInterface, methodName,
+ argTypes);
+ if (m != null) {
+ return m;
}
}
}
- return false;
+ return null;
}
-
-
- private static boolean hasMethod(Class clazz, String methodName,
+ private static Method getMethod(Class clazz, String methodName,
Class[] classes) {
try {
- clazz.getDeclaredMethod(methodName, classes);
- return true;
+ return clazz.getDeclaredMethod(methodName, classes);
} catch (NoSuchMethodException e) {
- return false;
+ return null;
}
}
@@ -222,10 +277,17 @@
public static void createAndRelease(Object f, String[] names) {
Object[] noarguments = {
};
-
createAndRelease(f, names, noarguments);
}
+ public static void createAndRelease(Object f, List<String>names) {
+ Object[] noarguments = {
+ };
+ String[] elementNames = new String[names.size()];
+ names.toArray(elementNames);
+ createAndRelease(f, elementNames, noarguments);
+ }
+
/**
* Test the presence of deletion methods for a list of modelelements.
*
@@ -263,25 +325,25 @@
/**
* Check if for every metamodel element name a create function exists.
*
- * @param f the modelfactory that should contain the creation function
+ * @param factory the modelfactory that should contain the create function
* @param names the metamodel class names
*/
- public static void metaModelNameCorrect(Object f, String[] names) {
+ public static void metaModelNameCorrect(Object factory, String[] names) {
try {
for (int i = 0; i < names.length; i++) {
- try {
- Method m =
- f.getClass()
- .getMethod("create" + names[i], new Class[] {});
- Object base = m.invoke(f, new Object[] {});
- if (Model.getFacade().isAModelElement(base)) {
- TestCase.assertTrue(
+ Method m = findMethod(factory.getClass(), Factory.class,
+ "create" + names[i], new Class[] {});
+ if (m == null) {
+ TestCase.fail("Failed to find method create" + names[i]);
+ }
+ Object base = m.invoke(factory, new Object[] {});
+ if (Model.getFacade().isAModelElement(base)) {
+ TestCase.assertTrue(
"not a valid metaModelName " + names[i],
Model.getExtensionMechanismsHelper()
- .getMetaModelName(base)
- .equals(names[i]));
- }
- } catch (NoSuchMethodException ns) { }
+ .getMetaModelName(base)
+ .equals(names[i]));
+ }
}
} catch (Exception ex) {
ex.printStackTrace();
@@ -291,6 +353,11 @@
}
}
+ public static void metaModelNameCorrect(Object factory,
+ List<String> names) {
+ metaModelNameCorrect(factory, names.toArray(new String[names.size()]));
+ }
+
/**
* Try creating a stereotype for every modelelement type.
*
@@ -306,38 +373,39 @@
Model.getExtensionMechanismsFactory()
.buildStereotype(clazz, "test1", ns);
for (int i = 0; i < names.length; i++) {
- try {
- Method m =
- f.getClass()
- .getMethod("create" + names[i], new Class[] {});
- Object base = m.invoke(f, new Object[] {});
- if (Model.getFacade().isAModelElement(base)) {
- Object stereo2 =
+ Method m = findMethod(f.getClass(), Factory.class,
+ "create" + names[i], new Class[] {});
+ if (m == null) {
+ TestCase.fail("Failed to find method create" + names[i]);
+ }
+ Object base = m.invoke(f, new Object[] {});
+ if (Model.getFacade().isAModelElement(base)) {
+ Object stereo2 =
Model.getExtensionMechanismsFactory()
- .buildStereotype(base, "test2", ns);
- TestCase.assertTrue(
+ .buildStereotype(base, "test2", ns);
+ TestCase.assertTrue(
"Unexpected invalid stereotype",
Model.getExtensionMechanismsHelper()
- .isValidStereoType(base, stereo2));
- if (!(Model.getFacade().isAClass(base))) {
- TestCase.assertTrue(
+ .isValidStereoType(base, stereo2));
+ if (!(Model.getFacade().isAClass(base))) {
+ TestCase.assertTrue(
"Stereotype with base class of Class"
- + " incorrectly allowed for this metaclass",
+ + " incorrectly allowed for this metaclass",
!Model.getExtensionMechanismsHelper()
- .isValidStereoType(base, stereo1));
- } else {
- Object inter =
- Model.getCoreFactory().createInterface();
- Object stereo3 =
- Model.getExtensionMechanismsFactory()
- .buildStereotype(inter, "test3", ns);
- TestCase.assertTrue(
+ .isValidStereoType(base, stereo1));
+ } else {
+ Object inter =
+ Model.getCoreFactory().createInterface();
+ Object stereo3 =
+ Model.getExtensionMechanismsFactory()
+ .buildStereotype(inter, "test3", ns);
+ TestCase.assertTrue(
"Unexpected invalid stereotype",
!Model.getExtensionMechanismsHelper()
- .isValidStereoType(base, stereo3));
- }
+ .isValidStereoType(base, stereo3));
}
- } catch (NoSuchMethodException ns2) { }
+ }
+
}
} catch (Exception ex) {
ex.printStackTrace();
@@ -346,4 +414,8 @@
+ ex.getMessage());
}
}
+
+ public static void isValidStereoType(Object f, List<String> names) {
+ isValidStereoType(f, names.toArray(new String[names.size()]));
+ }
}
Modified: trunk/tests/org/argouml/model/TestActivityGraphsFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/TestActivityGraphsFactory.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/TestActivityGraphsFactory.java&p2=trunk/tests/org/argouml/model/TestActivityGraphsFactory.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/TestActivityGraphsFactory.java (original)
+++ trunk/tests/org/argouml/model/TestActivityGraphsFactory.java 2007-05-09 07:19:16-0700
@@ -24,8 +24,10 @@
package org.argouml.model;
+import java.util.Arrays;
+import java.util.List;
+
import junit.framework.TestCase;
-import org.argouml.model.InitializeModel;
/**
@@ -77,19 +79,8 @@
* The test for creation.
*/
public void testCreates() {
- String [] objs = {
- "ActionState",
- "ActivityGraph",
- "CallState",
- "ClassifierInState",
- "ObjectFlowState",
- "Partition",
- "SubactivityState",
- null,
- };
-
CheckUMLModelHelper.createAndRelease(Model.getActivityGraphsFactory(),
- objs);
+ getTestableModelElements());
}
/**
@@ -98,4 +89,11 @@
static String[] getAllModelElements() {
return allModelElements;
}
+
+ /**
+ * @return all testable model elements
+ */
+ static List<String> getTestableModelElements() {
+ return Arrays.asList(allModelElements);
+ }
}
Modified: trunk/tests/org/argouml/model/TestActivityGraphsHelper.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/TestActivityGraphsHelper.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/TestActivityGraphsHelper.java&p2=trunk/tests/org/argouml/model/TestActivityGraphsHelper.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/TestActivityGraphsHelper.java (original)
+++ trunk/tests/org/argouml/model/TestActivityGraphsHelper.java 2007-05-09 07:19:16-0700
@@ -25,7 +25,6 @@
package org.argouml.model;
import junit.framework.TestCase;
-import org.argouml.model.InitializeModel;
/**
* @since Oct 10, 2002
@@ -56,7 +55,7 @@
public void testGetMetaModelName() {
CheckUMLModelHelper.metaModelNameCorrect(
Model.getActivityGraphsFactory(),
- TestActivityGraphsFactory.getAllModelElements());
+ TestActivityGraphsFactory.getTestableModelElements());
}
/**
@@ -65,6 +64,6 @@
public void testIsValidStereoType() {
CheckUMLModelHelper.isValidStereoType(
Model.getActivityGraphsFactory(),
- TestActivityGraphsFactory.getAllModelElements());
+ TestActivityGraphsFactory.getTestableModelElements());
}
}
Modified: trunk/tests/org/argouml/model/TestAgainstUmlModel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/TestAgainstUmlModel.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/TestAgainstUmlModel.java&p2=trunk/tests/org/argouml/model/TestAgainstUmlModel.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/TestAgainstUmlModel.java (original)
+++ trunk/tests/org/argouml/model/TestAgainstUmlModel.java 2007-05-09 07:19:16-0700
@@ -184,18 +184,18 @@
}
static {
- refs.put("Multiplicity", new CannotTestFactoryMethod());
- refs.put("MultiplicityRange", new CannotTestFactoryMethod());
- refs.put("Expression", new CannotTestFactoryMethod());
- refs.put("ObjectSetExpression", new CannotTestFactoryMethod());
- refs.put("TimeExpression", new CannotTestFactoryMethod());
- refs.put("BooleanExpression", new CannotTestFactoryMethod());
- refs.put("ActionExpression", new CannotTestFactoryMethod());
- refs.put("IterationExpression", new CannotTestFactoryMethod());
- refs.put("TypeExpression", new CannotTestFactoryMethod());
- refs.put("ArgListsExpression", new CannotTestFactoryMethod());
- refs.put("MappingExpression", new CannotTestFactoryMethod());
- refs.put("ProcedureExpression", new CannotTestFactoryMethod());
+ refs.put("Multiplicity", Model.getDataTypesFactory());
+ refs.put("MultiplicityRange", Model.getDataTypesFactory());
+ refs.put("Expression", Model.getDataTypesFactory());
+ refs.put("ObjectSetExpression", Model.getDataTypesFactory());
+ refs.put("TimeExpression", Model.getDataTypesFactory());
+ refs.put("BooleanExpression", Model.getDataTypesFactory());
+ refs.put("ActionExpression", Model.getDataTypesFactory());
+ refs.put("IterationExpression", Model.getDataTypesFactory());
+ refs.put("TypeExpression", Model.getDataTypesFactory());
+ refs.put("ArgListsExpression", Model.getDataTypesFactory());
+ refs.put("MappingExpression", Model.getDataTypesFactory());
+ refs.put("ProcedureExpression", Model.getDataTypesFactory());
}
static {
Modified: trunk/tests/org/argouml/model/TestCollaborationsFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/TestCollaborationsFactory.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/TestCollaborationsFactory.java&p2=trunk/tests/org/argouml/model/TestCollaborationsFactory.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/TestCollaborationsFactory.java (original)
+++ trunk/tests/org/argouml/model/TestCollaborationsFactory.java 2007-05-09 07:19:16-0700
@@ -24,6 +24,9 @@
package org.argouml.model;
+import java.util.Arrays;
+import java.util.List;
+
import junit.framework.TestCase;
@@ -64,24 +67,25 @@
}
/**
+ * @return Returns the allModelElements.
+ */
+ static String[] getAllModelElements() {
+ return allModelElements;
+ }
+
+ /**
+ * @return all testable model elements
+ */
+ static List<String> getTestableModelElements() {
+ return Arrays.asList(allModelElements);
+ }
+
+ /**
* Test the creation of the elements.
*/
public void testCreates() {
-
- String[] objs = {
- "AssociationEndRole",
- "AssociationRole",
- "ClassifierRole",
- "Collaboration",
- "Interaction",
- "Message",
- null,
- };
-
CheckUMLModelHelper.createAndRelease(
- Model.getCollaborationsFactory(),
- objs);
-
+ Model.getCollaborationsFactory(), getTestableModelElements());
}
/**
@@ -144,13 +148,7 @@
Model.getUmlFactory().isRemoved(inter));
}
- /**
- * @return Returns the allModelElements.
- */
- static String[] getAllModelElements() {
- return allModelElements;
- }
-
+
/**
* Test that an Exception is thrown when a null is sent. We don't
* really care which exception is thrown.
Modified: trunk/tests/org/argouml/model/TestCommonBehaviorFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/TestCommonBehaviorFactory.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/TestCommonBehaviorFactory.java&p2=trunk/tests/org/argouml/model/TestCommonBehaviorFactory.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/TestCommonBehaviorFactory.java (original)
+++ trunk/tests/org/argouml/model/TestCommonBehaviorFactory.java 2007-05-09 07:19:16-0700
@@ -24,8 +24,9 @@
package org.argouml.model;
-import java.util.Collection;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import junit.framework.TestCase;
@@ -40,7 +41,7 @@
*/
private static String[] allModelElements =
{
- "Action",
+ "Action", // abstract
"ActionSequence",
"Argument",
"AttributeLink",
@@ -50,7 +51,7 @@
"DataValue",
"DestroyAction",
"Exception",
- "Instance",
+ "Instance", // abstract
"Link",
"LinkEnd",
"LinkObject",
@@ -80,42 +81,15 @@
public void setUp() {
InitializeModel.initializeDefault();
}
-
+
/**
- * Test for creation.
+ * @return concrete ModelElement types
*/
- public void testCreates() {
-
- Collection objs = new Vector();
-
- // Action is abstract
- objs.add("ActionSequence");
- objs.add("Argument");
- objs.add("AttributeLink");
- objs.add("CallAction");
- objs.add("ComponentInstance");
- objs.add("CreateAction");
- objs.add("DataValue");
- objs.add("DestroyAction");
- objs.add("Exception");
- // Instance is abstract
- objs.add("Link");
- objs.add("LinkEnd");
- objs.add("NodeInstance");
- objs.add("Object");
- objs.add("Reception");
- objs.add("ReturnAction");
- objs.add("SendAction");
- objs.add("Signal");
- objs.add("Stimulus");
- objs.add("TerminateAction");
- objs.add("UninterpretedAction");
-
- CheckUMLModelHelper.createAndRelease(
- Model.getCommonBehaviorFactory(),
- // +1 in array size because we also test the null value
- (String[]) objs.toArray(new String[objs.size() + 1]));
-
+ static List<String> getTestableModelElements() {
+ ArrayList c = new ArrayList(Arrays.asList(allModelElements));
+ c.remove("Action");
+ c.remove("Instance");
+ return c;
}
/**
@@ -124,4 +98,13 @@
static String[] getAllModelElements() {
return allModelElements;
}
+
+ /**
+ * Test for creation.
+ */
+ public void testCreates() {
+ CheckUMLModelHelper.createAndRelease(
+ Model.getCommonBehaviorFactory(), getTestableModelElements());
+ }
+
}
Modified: trunk/tests/org/argouml/model/TestCommonBehaviorHelper.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/TestCommonBehaviorHelper.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/TestCommonBehaviorHelper.java&p2=trunk/tests/org/argouml/model/TestCommonBehaviorHelper.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/TestCommonBehaviorHelper.java (original)
+++ trunk/tests/org/argouml/model/TestCommonBehaviorHelper.java 2007-05-09 07:19:16-0700
@@ -24,6 +24,9 @@
package org.argouml.model;
+import java.util.Arrays;
+import java.util.Collection;
+
import junit.framework.TestCase;
/**
@@ -54,7 +57,7 @@
public void testGetMetaModelName() {
CheckUMLModelHelper.metaModelNameCorrect(
Model.getCommonBehaviorFactory(),
- TestCommonBehaviorFactory.getAllModelElements());
+ TestCommonBehaviorFactory.getTestableModelElements());
}
/**
@@ -63,6 +66,8 @@
public void testIsValidStereoType() {
CheckUMLModelHelper.isValidStereoType(
Model.getCommonBehaviorFactory(),
- TestCommonBehaviorFactory.getAllModelElements());
+ TestCommonBehaviorFactory.getTestableModelElements());
}
+
+
}
Modified: trunk/tests/org/argouml/model/TestCoreFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/TestCoreFactory.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/TestCoreFactory.java&p2=trunk/tests/org/argouml/model/TestCoreFactory.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/TestCoreFactory.java (original)
+++ trunk/tests/org/argouml/model/TestCoreFactory.java 2007-05-09 07:19:16-0700
@@ -25,10 +25,9 @@
package org.argouml.model;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
-import java.util.Vector;
import junit.framework.TestCase;
@@ -97,52 +96,40 @@
}
/**
+ * @return Returns the allModelElements.
+ */
+ static String[] getAllModelElements() {
+ return allModelElements;
+ }
+
+ /**
+ * @return the concrete ModelElements which are testable
+ */
+ static List<String> getTestableModelElements() {
+ List<String> c = new ArrayList<String>(Arrays.asList(allModelElements));
+ c.remove("BehavioralFeature");
+ c.remove("Element");
+ c.remove("ModelElement");
+ c.remove("Namespace");
+ c.remove("GeneralizableElement");
+ c.remove("Classifier");
+ c.remove("Feature");
+ c.remove("StructuralFeature");
+ c.remove("BehavioralFeature");
+ c.remove("Relationship");
+ c.remove("PresentationElement");
+ return c;
+ }
+
+ /**
* Test creation of metatypes.
*
* TODO: we could add tests here to make sure that
* we can NOT create abstract types
*/
public void testCreates() {
- Collection objs = new Vector();
-
- // The abstract metaclasses in UML 1.3 include Element, ModelElement,
- // Feature, Namespace, GeneralizableElement, Classifier,
- // StructuralFeature, BehavioralFeature, Relationship,
- // PresentationElement, Action, StateVertex, and
- // Event.
- // UML 1.4 changes Instance and State to be abstract also.
-
- objs.add("Abstraction");
- //Association are abstract metaclass but we return an UmlAssociation
- //from the createAssociation method of the CoreFactory interface
- objs.add("Association");
- objs.add("AssociationClass");
- objs.add("AssociationEnd");
- objs.add("Attribute");
- objs.add("Binding");
- objs.add("Class");
- objs.add("Comment");
- objs.add("Component");
- objs.add("Constraint");
- objs.add("DataType");
- objs.add("Dependency");
- objs.add("ElementResidence");
- objs.add("Flow");
- objs.add("Generalization");
- objs.add("Interface");
- objs.add("Method");
- objs.add("Node");
- objs.add("Operation");
- objs.add("Parameter");
- objs.add("Permission");
- objs.add("TemplateArgument");
- objs.add("TemplateParameter");
- objs.add("Usage");
-
- CheckUMLModelHelper.createAndRelease(
- Model.getCoreFactory(),
- // +1 in the size of the array because we also test the null value
- (String[]) objs.toArray(new String[objs.size() + 1]));
+ CheckUMLModelHelper.createAndRelease(
+ Model.getCoreFactory(), getTestableModelElements());
}
/**
@@ -405,7 +392,8 @@
*/
public void testBuildTemplate() {
Object model = Model.getModelManagementFactory().createModel();
- Object templatedClass = Model.getCoreFactory().buildClass("Template", model);
+ Object templatedClass =
+ Model.getCoreFactory().buildClass("Template", model);
Object parameterizedClass = Model.getCoreFactory().buildClass(
"ParameterizedClass", model);
@@ -542,11 +530,13 @@
args.add(ta3);
Object binding2 = Model.getCoreFactory().buildBinding(
parameterizedClass2, templatedClass, args);
- assertNotNull("Failed to create 2nd binding to same template", binding2);
+ assertNotNull("Failed to create 2nd binding to same template",
+ binding2);
assertEquals("Binding arguments don't match", args,
Model.getFacade().getArguments(binding2));
- Collection deps = Model.getFacade().getClientDependencies(parameterizedClass2);
+ Collection deps =
+ Model.getFacade().getClientDependencies(parameterizedClass2);
assertEquals(1, deps.size());
Object dep = deps.iterator().next();
assertEquals(binding2, dep);
@@ -557,10 +547,5 @@
assertEquals(templatedClass, suppliers.iterator().next());
}
- /**
- * @return Returns the allModelElements.
- */
- static String[] getAllModelElements() {
- return allModelElements;
- }
+
}
Modified: trunk/tests/org/argouml/model/TestCoreHelper.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/TestCoreHelper.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/TestCoreHelper.java&p2=trunk/tests/org/argouml/model/TestCoreHelper.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/TestCoreHelper.java (original)
+++ trunk/tests/org/argouml/model/TestCoreHelper.java 2007-05-09 07:19:16-0700
@@ -67,7 +67,7 @@
public void testGetMetaModelName() {
CheckUMLModelHelper.metaModelNameCorrect(
Model.getCoreFactory(),
- TestCoreFactory.getAllModelElements());
+ TestCoreFactory.getTestableModelElements());
}
/**
@@ -76,9 +76,10 @@
public void testIsValidStereoType() {
CheckUMLModelHelper.isValidStereoType(
Model.getCoreFactory(),
- TestCoreFactory.getAllModelElements());
+ TestCoreFactory.getTestableModelElements());
}
+
/**
* Test subtype check.
*/
Modified: trunk/tests/org/argouml/model/TestExtensionMechanismsFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/TestExtensionMechanismsFactory.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/TestExtensionMechanismsFactory.java&p2=trunk/tests/org/argouml/model/TestExtensionMechanismsFactory.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/TestExtensionMechanismsFactory.java (original)
+++ trunk/tests/org/argouml/model/TestExtensionMechanismsFactory.java 2007-05-09 07:19:16-0700
@@ -24,7 +24,10 @@
package org.argouml.model;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
import junit.framework.TestCase;
@@ -51,6 +54,24 @@
super(n);
}
+ /**
+ * @return Returns the allModelElements.
+ */
+ static String[] getAllModelElements() {
+ return allModelElements;
+ }
+
+ /**
+ * @return the concrete ModelElements which are testable
+ */
+ static List<String> getTestableModelElements() {
+ List<String> c = new ArrayList<String>(Arrays.asList(allModelElements));
+ // TODO: Stereotype was untested before, but I'm not sure if it was
+ // intentional. Seems more like an oversight. - tfm
+// c.remove("Stereotype");
+ return c;
+ }
+
/*
* @see junit.framework.TestCase#setUp()
*/
@@ -71,17 +92,9 @@
* Test creation.
*/
public void testCreates() {
-
- String[] objs = {
- "TagDefinition",
- "TaggedValue",
- null,
- };
-
CheckUMLModelHelper.createAndRelease(
Model.getExtensionMechanismsFactory(),
- objs);
-
+ getTestableModelElements());
ExtensionMechanismsFactory emFactory =
Model.getExtensionMechanismsFactory();
@@ -136,10 +149,4 @@
assertEquals("TagDefinition not deleted", 0, tds.size());
}
- /**
- * @return Returns the allModelElements.
- */
- static String[] getAllModelElements() {
- return allModelElements;
- }
}
Modified: trunk/tests/org/argouml/model/TestModelManagementFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/TestModelManagementFactory.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/TestModelManagementFactory.java&p2=trunk/tests/org/argouml/model/TestModelManagementFactory.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/TestModelManagementFactory.java (original)
+++ trunk/tests/org/argouml/model/TestModelManagementFactory.java 2007-05-09 07:19:16-0700
@@ -24,6 +24,9 @@
package org.argouml.model;
+import java.util.Arrays;
+import java.util.List;
+
import junit.framework.TestCase;
/**
@@ -35,18 +38,33 @@
* The model elements to test.
*/
private static String[] allModelElements = {
- "ElementImport", "Model", "Package", "Subsystem",
+ "ElementImport", "Model", "Package", "Subsystem",
};
/**
* The constructor.
- *
- * @param n the name
+ *
+ * @param n
+ * the name
*/
public TestModelManagementFactory(String n) {
super(n);
}
+ /**
+ * @return Returns the allModelElements.
+ */
+ protected static String[] getAllModelElements() {
+ return allModelElements;
+ }
+
+ /**
+ * @return all testable model elements
+ */
+ static List<String> getTestableModelElements() {
+ return Arrays.asList(allModelElements);
+ }
+
/*
* @see junit.framework.TestCase#setUp()
*/
@@ -58,35 +76,18 @@
* Test if this class is really a singleton.
*/
public void testSingleton() {
-
Object o1 = Model.getModelManagementFactory();
-
Object o2 = Model.getModelManagementFactory();
-
assertTrue("Different singletons", o1 == o2);
-
}
/**
* Test creation.
*/
public void testCreates() {
-
- String[] objs = {
- "ElementImport", "Model", "Package", "Subsystem",
- null,
- };
-
CheckUMLModelHelper.createAndRelease(
Model.getModelManagementFactory(),
- objs);
-
+ getTestableModelElements());
}
- /**
- * @return Returns the allModelElements.
- */
- protected static String[] getAllModelElements() {
- return allModelElements;
- }
}
Modified: trunk/tests/org/argouml/model/TestStateMachinesFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/TestStateMachinesFactory.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/TestStateMachinesFactory.java&p2=trunk/tests/org/argouml/model/TestStateMachinesFactory.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/TestStateMachinesFactory.java (original)
+++ trunk/tests/org/argouml/model/TestStateMachinesFactory.java 2007-05-09 07:19:16-0700
@@ -24,6 +24,10 @@
package org.argouml.model;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
import junit.framework.TestCase;
/**
@@ -39,15 +43,15 @@
"CallEvent",
"ChangeEvent",
"CompositeState",
- "Event",
+ "Event", // abstract
"FinalState",
"Guard",
"Pseudostate",
"SignalEvent",
"SimpleState",
- "State",
+ "State", // abstract
"StateMachine",
- "StateVertex",
+ "StateVertex", // abstract
"StubState",
"SubmachineState",
"SynchState",
@@ -64,6 +68,24 @@
super(n);
}
+ /**
+ * @return the concrete ModelElements which are testable
+ */
+ static List<String> getTestableModelElements() {
+ List<String> c = new ArrayList<String>(Arrays.asList(allModelElements));
+ c.remove("Event");
+ c.remove("State");
+ c.remove("StateVertex");
+ return c;
+ }
+
+ /**
+ * @return Returns the allModelElements.
+ */
+ static String[] getAllModelElements() {
+ return allModelElements;
+ }
+
/*
* @see junit.framework.TestCase#setUp()
*/
@@ -75,50 +97,18 @@
* Test if this class is really a singleton.
*/
public void testSingleton() {
-
Object o1 = Model.getStateMachinesFactory();
-
Object o2 = Model.getStateMachinesFactory();
-
assertTrue("Different singletons", o1 == o2);
-
}
/**
* Test creation.
*/
public void testCreates() {
- // Do not test State, Event or StateVertex. They are abstract.
- String[] objs = {
- "CallEvent",
- "ChangeEvent",
- "CompositeState",
- // "Event",
- "FinalState",
- "Guard",
- "Pseudostate",
- "SignalEvent",
- "SimpleState",
- // "State",
- "StateMachine",
- // "StateVertex",
- "StubState",
- "SubmachineState",
- "SynchState",
- "TimeEvent",
- "Transition",
- null,
- };
-
- CheckUMLModelHelper.createAndRelease(
- Model.getStateMachinesFactory(),
- objs);
+ CheckUMLModelHelper.createAndRelease(
+ Model.getStateMachinesFactory(), getTestableModelElements());
}
- /**
- * @return Returns the allModelElements.
- */
- static String[] getAllModelElements() {
- return allModelElements;
- }
+
}
Modified: trunk/tests/org/argouml/model/TestStateMachinesHelper.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/TestStateMachinesHelper.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/TestStateMachinesHelper.java&p2=trunk/tests/org/argouml/model/TestStateMachinesHelper.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/TestStateMachinesHelper.java (original)
+++ trunk/tests/org/argouml/model/TestStateMachinesHelper.java 2007-05-09 07:19:16-0700
@@ -54,7 +54,7 @@
public void testGetMetaModelName() {
CheckUMLModelHelper.metaModelNameCorrect(
Model.getStateMachinesFactory(),
- TestStateMachinesFactory.getAllModelElements());
+ TestStateMachinesFactory.getTestableModelElements());
}
/**
@@ -63,6 +63,6 @@
public void testIsValidStereoType() {
CheckUMLModelHelper.isValidStereoType(
Model.getStateMachinesFactory(),
- TestStateMachinesFactory.getAllModelElements());
+ TestStateMachinesFactory.getTestableModelElements());
}
}
Modified: trunk/tests/org/argouml/model/TestUseCasesFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/model/TestUseCasesFactory.java?view=diff&rev=12576&p1=trunk/tests/org/argouml/model/TestUseCasesFactory.java&p2=trunk/tests/org/argouml/model/TestUseCasesFactory.java&r1=12575&r2=12576
==============================================================================
--- trunk/tests/org/argouml/model/TestUseCasesFactory.java (original)
+++ trunk/tests/org/argouml/model/TestUseCasesFactory.java 2007-05-09 07:19:16-0700
@@ -24,6 +24,9 @@
package org.argouml.model;
+import java.util.Arrays;
+import java.util.List;
+
import junit.framework.TestCase;
@@ -54,6 +57,20 @@
super(n);
}
+ /**
+ * @return Returns the allModelElements.
+ */
+ static String[] getAllModelElements() {
+ return allModelElements;
+ }
+
+ /**
+ * @return all testable model elements
+ */
+ static List<String> getTestableModelElements() {
+ return Arrays.asList(allModelElements);
+ }
+
/*
* @see junit.framework.TestCase#setUp()
*/
@@ -74,18 +91,8 @@
* Test creation.
*/
public void testCreates() {
- String [] objs = {
- "Actor",
- "Extend",
- "ExtensionPoint",
- "Include",
- "UseCase",
- "UseCaseInstance",
- null,
- };
-
- CheckUMLModelHelper.createAndRelease(Model.getUseCasesFactory(),
- objs);
+ CheckUMLModelHelper.createAndRelease(
+ Model.getUseCasesFactory(), getTestableModelElements());
}
/**
@@ -110,13 +117,5 @@
&& Model.getFacade().getExtensionPoints(extend).size() == 1));
}
-
-
- /**
- * @return Returns the allModelElements.
- */
- static String[] getAllModelElements() {
- return allModelElements;
- }
}
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.