svn commit: r16693 - trunk/src: argouml-app/tests/org/argouml/model argouml-core-model-mdr/src/org/argouml/model/mdr

Tom Morris <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2009-01-24 08:38:30-0800
New Revision: 16693

Modified:
   trunk/src/argouml-app/tests/org/argouml/model/TestCoreFactory.java
   trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java

Log:
RESOLVED - issue 5647: faults in getMaxUpper and buildGeneralization 
http://argouml.tigris.org/issues/show_bug.cgi?id=5647

Modified: trunk/src/argouml-app/tests/org/argouml/model/TestCoreFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/model/TestCoreFactory.java?view=diff&pathrev=16693&r1=16692&r2=16693
==============================================================================
--- trunk/src/argouml-app/tests/org/argouml/model/TestCoreFactory.java	(original)
+++ trunk/src/argouml-app/tests/org/argouml/model/TestCoreFactory.java	2009-01-24 08:38:30-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2002-2007 The Regents of the University of California. All
+// Copyright (c) 2002-2009 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
@@ -632,5 +632,88 @@
         
     }
 
+    /**
+     * Test buildGeneralization
+     */
+    public void testBuildGeneralization() {
+        Object model = Model.getModelManagementFactory().createModel();
+        Object client = Model.getCoreFactory().buildClass("ClassA", model);
+        Object supplier = Model.getCoreFactory().buildInterface("ClassB",
+                model);
 
+        try {
+            Model.getCoreFactory().buildGeneralization(supplier, supplier);
+            fail("buildGeneralization to self didn't throw exception");
+        } catch (Exception e) {
+            // success
+        }
+
+        try {
+            Model.getCoreFactory().buildGeneralization(client, client);
+            fail("buildGeneralization to self didn't throw exception");
+        } catch (Exception e) {
+            // success
+        }
+
+        Object generalization = Model.getCoreFactory().buildGeneralization(
+                client, supplier);
+        assertTrue(Model.getFacade().isAGeneralization(generalization));
+
+        try {
+            Model.getCoreFactory().buildGeneralization(supplier, client);
+            fail("circular buildGeneralization didn't throw exception");
+        } catch (Exception e) {
+            // success
+        }
+        
+        Model.getUmlFactory().delete(supplier);
+        assertTrue(Model.getUmlFactory().isRemoved(generalization));
+        Model.getUmlFactory().delete(model);
+    }
+    
+    public void testBuildAssociationEnd() {
+        Object model = Model.getModelManagementFactory().createModel();
+        Object class1 = Model.getCoreFactory().buildClass("Class1", model);
+        Object class2 = Model.getCoreFactory().buildClass("Class2", model);
+        Object assoc = Model.getCoreFactory().createAssociation();
+        Object unlimited = Model.getDataTypesFactory().createMultiplicity(0, -1);
+        Object ordering = Model.getOrderingKind().getUnordered();
+        Object aggComposite = Model.getAggregationKind().getComposite();
+        Object scope = Model.getScopeKind().getInstance(); // not static
+        Object changeable = Model.getChangeableKind().getChangeable();
+        Object visibility = Model.getVisibilityKind().getPrivate();
+        try {
+            Model.getCoreFactory().buildAssociationEnd(assoc, "End", class1,
+                    unlimited, null, false, ordering, aggComposite, scope,
+                    changeable, visibility);
+            fail("Creation of aggregate association end with multiplicity "
+                    + "of 'unlimited' should throw an exception");
+        } catch (IllegalArgumentException e) {
+            // Test passed
+        }
+
+        Object multi2 = Model.getDataTypesFactory().createMultiplicity(0, 2);
+        try {
+            Model.getCoreFactory().buildAssociationEnd(assoc, "End", class1,
+                    multi2, null, false, ordering, aggComposite, scope,
+                    changeable, visibility);
+            fail("Creation of aggregate association end with multiplicity "
+                    + "of 2 should throw an exception");
+        } catch (IllegalArgumentException e) {
+            // Test passed
+        }
+        
+        Object aggNone = Model.getAggregationKind().getNone();
+        Object ae = Model.getCoreFactory().buildAssociationEnd(assoc, "End",
+                class1, multi2, null, false, ordering, aggNone, scope,
+                changeable, visibility);
+        assertTrue(Model.getFacade().isAAssociationEnd(ae));
+        
+        ae = null;
+        Object multi1 = Model.getDataTypesFactory().createMultiplicity(0, 1);
+        ae = Model.getCoreFactory().buildAssociationEnd(assoc, "End",
+                class1, multi1, null, false, ordering, aggComposite, scope,
+                changeable, visibility);
+        assertTrue(Model.getFacade().isAAssociationEnd(ae));
+    }
 }

Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java?view=diff&pathrev=16693&r1=16692&r2=16693
==============================================================================
--- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java	(original)
+++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java	2009-01-24 08:38:30-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Copyright (c) 1996-2009 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
@@ -603,7 +603,9 @@
 
         if (aggregation != null
                 && aggregation.equals(AggregationKindEnum.AK_COMPOSITE)
-                && multi != null && getMaxUpper((Multiplicity) multi) > 1) {
+                && multi != null 
+                && compareMultiplicity(getMaxUpper((Multiplicity) multi), 1) 
+                    > 0) {
             throw new IllegalArgumentException("aggregation is composite "
                     + "and multiplicity > 1");
         }
@@ -657,6 +659,8 @@
         return end;
     }
 
+    private static final int MULT_UNLIMITED = -1;
+    
     /**
      * Get the maximum value of a multiplicity
      * 
@@ -668,11 +672,33 @@
         int max = 0;
         for (MultiplicityRange mr : m.getRange()) {
             int value = mr.getUpper();
-            if (value > max) {
+            if (value == MULT_UNLIMITED) {
+                max = value;
+            } else if (max != MULT_UNLIMITED && value > max) {
                 max = value;
             }
         }
-        return 0;
+        return max;
+    }
+    
+    /**
+     * Compare two multiplicities taking care of the value 'unlimited' (-1).
+     * 
+     * @param mult1 first multiplicity
+     * @param mult2 second multiplicity
+     * @return 0 if equal, a positive integer (not necessarily 1) if mult1 is
+     *         greater than mult2 and a negative integer if mult2 is greater..
+     */
+    private static int compareMultiplicity(int mult1, int mult2) {
+        if (mult1 == MULT_UNLIMITED) {
+            if (mult2 == MULT_UNLIMITED) {
+                return 0; // equal
+            }
+            return 1; // greater
+        } else if (mult2 == MULT_UNLIMITED) {
+            return -1; // less than
+        }
+        return mult1 - mult2;
     }
 
     /**
@@ -938,9 +964,9 @@
         // TODO: This is a part implementation of well-formedness rule
         // UML1.4.2 - 4.5.3.20 [3] Circular inheritance is not allowed.
         // not self.allParents->includes(self)
-        if ((!(child1 instanceof GeneralizableElement) 
-                || !(parent1 instanceof GeneralizableElement))
-                && child1 != parent1) {
+        if (!(child1 instanceof GeneralizableElement
+                && parent1 instanceof GeneralizableElement
+                && child1 != parent1)) {
             throw new IllegalArgumentException(
                     "Both items must be different generalizable elements");
         }

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=1047182

To unsubscribe from this discussion, e-mail: [[email protected]].
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.