gt:         checkValue(attr, ATTR10, "2 * (b+c) - 10");
context: // $Id: TestAttributeAndOperationNotationUml.java 43 2010-04-03 20:28:12Z marcusvnac $
  // Copyright (c) 2006-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.notation.providers.uml;
  
  import java.text.ParseException;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.List;
  
  import junit.framework.TestCase;
  
  import org.argouml.kernel.Project;
  import org.argouml.kernel.ProjectManager;
  import org.argouml.model.InitializeModel;
  import org.argouml.model.Model;
  import org.argouml.notation.InitNotation;
  import org.argouml.notation.NotationProvider;
  import org.argouml.notation.NotationSettings;
  import org.argouml.notation.providers.java.InitNotationJava;
  import org.argouml.profile.init.InitProfileSubsystem;
  
  /**
   * @author michiel
   */
  public class TestAttributeAndOperationNotationUml extends TestCase {
  
  
      private static final String ATTR01 = "name";
      private static final String ATTR02 = "+name";
      private static final String ATTR03 = "-name : void";
      private static final String ATTR04 = "#name [1..1] : int {a=b}";
      private static final String ATTR05 =
          "public name {a=b, c = d } : [1..*] int = 0";
      private static final String ATTR06 =
          "private name {a=b, c = d } [*..*] : int = 15 {frozen}";
      private static final String ATTR07 = "+name : String = \'val[15] \'";
      private static final String ATTR08 =
          "  + name : String = \"a <<string>>\"";
      private static final String ATTR09 = "+name : String = (a * (b+c) - d)";
      private static final String ATTR10 =
          "+name << attrstereo1 >> : String = 2 * (b+c) - 10";
      private static final String ATTR11 =
          "<<attrstereo2>> +name : String = a[15]";
      private static final String ATTR12 = "+ name : String = a << 5";
      private static final String ATTR13 =
          "<<attrstereo1,attrstereo2>> +name : String = a[15]";
      private static final String ATTR14 = "a : int; b : Foo";
      
      private static final String NATTR01 = "too many string in an attribute";
      private static final String NATTR02 = "+vis name";
      private static final String NATTR03 = "vis name : type : type";
      private static final String NATTR04 = "vis name = 0 = 1";
      private static final String NATTR05 = "vis name [1..1] [1..1]";
      private static final String NATTR06 = "vis name [1..1";
      private static final String NATTR07 = "vis name { a = b, cv = ";
      private static final String NATTR08 = "vis \"name\"";
      private static final String NATTR09 = "\"vis\" name";
      private static final String NATTR10 = "vis (name)";
      private static final String NATTR11 = "(vis) name";
      private static final String NATTR12 = "vis name : \"type\"";
      private static final String NATTR13 = "vis name : (type)";
  
      private static final String OPER01 = "name()";
      private static final String OPER02 =
          "<<opstereo1>> -name(in foo: float = 0) "
          + "{root, abstract = false} : int";
      private static final String OPER03 =
          "<< opstereo2 >> protected name2("
          + "out foo: double = 0., inout bar = \"\"some\"\":String) "
          + "{leaf,query} : String";
      private static final String OPER04 = "<<>> # name2()";
      private static final String OPER05 = "<< opstereo1, opstereo2 >>  name5()";
  
      private static final String NOPER01 = "name(";
      private static final String NOPER02 = "\"name\"()";
      private static final String NOPER03 = "\"vis\" name()";
      private static final String NOPER04 = "\'name\'()";
      private static final String NOPER05 = "\'vis\' name()";
      private static final String NOPER06 = "(name)()";
      private static final String NOPER07 = "(vis) name()";
      private static final String NOPER08 = "name() : \"type\"";
      private static final String NOPER09 = "name() : \'type\'";
      private static final String NOPER10 = "name() : (type)";
  
      /**
       * The constructor.
       *
       * @param str the name of the test
       */
      public TestAttributeAndOperationNotationUml(String str) {
          super(str);
          InitializeModel.initializeDefault();
      }
  
      /*
       * @see junit.framework.TestCase#setUp()
       */
      @Override
      protected void setUp() {
          (new InitProfileSubsystem()).init();
          (new InitNotation()).init();
          (new InitNotationUml()).init();
          (new InitNotationJava()).init();
      }
  
      /**
       * Test the parsing of an attribute name.
       *
       * @throws ParseException if the parsing fails.
       */
      public void testAttributeName()
          throws ParseException {
          Object attr;
  
          Project p = ProjectManager.getManager().getCurrentProject();
          Object model = p.getModel();
          Object attrType = p.getDefaultAttributeType();
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, model);
  
          checkName(attr, ATTR01, "name");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, model);
  
          checkName(attr, ATTR02, "name");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, model);
  
          checkName(attr, ATTR03, "name");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, model);
  
          checkName(attr, ATTR04, "name");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, model);
  
          checkName(attr, ATTR05, "name");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, model);
  
          checkName(attr, ATTR06, "name");
      }
  
  
      /**
       * Test the parsing of an attribute's type.
       *
       * @throws ParseException if the parsing fails.
       */
      public void testAttributeType() throws ParseException {
          Object attr;
  
          Project project = ProjectManager.getManager().getCurrentProject();
          Object ns = project.getModel();
          Object attrType = project.getDefaultAttributeType();
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkType(attr, ATTR03, "void");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkType(attr, ATTR04, "int");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkType(attr, ATTR05, "int");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkType(attr, ATTR06, "int");
      }
      
      /**
       * Test the parsing of several attributes with semicolons,
       * and the correct assignation of the new datatypes to
       * the same namespace of the owner
       * See issue 5229 (http://argouml.tigris.org/issues/show_bug.cgi?id=5229) 
       * @throws ParseException
       */
      public void testAttributeNewTypeNamespace() throws ParseException {
          Object attr;
  
          Project project = ProjectManager.getManager().getCurrentProject();
          Object ns = project.getModel();
          
          Object cl = Model.getCoreFactory().buildClass();
          Model.getCoreHelper().setNamespace(cl, ns);
          
          Object attrType = project.getDefaultAttributeType();
          attr = Model.getCoreFactory().buildAttribute2(cl, attrType);       
  
          AttributeNotationUml anu = new AttributeNotationUml(); 
          anu.parse(attr, ATTR14);
                  
          List attrs = Model.getFacade().getAttributes(cl);
          assertEquals("Wrong number of attributes", 2, attrs.size());
          
          // we want the b: Foo attribute, that is the second in the list
          attr = attrs.get(1);
          
          attrType = Model.getFacade().getType(attr);
          Object namespace = Model.getFacade().getNamespace(attrType);
          
          assertNotNull("Namespace of the created type for the attribute must not be null",
                  namespace);
          assertEquals("The namespace of the created type is not the same than" +
          		" the namespace of the original class.", ns, namespace);
          
      }
  
      /**
       * Test the parsing of the attribute's visibility.
       *
       * @throws ParseException if the parsing fails.
       */
      public void testAttributeVisibility() throws ParseException {
          Object attr;
  
          Project project = ProjectManager.getManager().getCurrentProject();
          Object ns = project.getModel();
          Object attrType = project.getDefaultAttributeType();
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkVisibility(attr, ATTR02, "public");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkVisibility(attr, ATTR03, "private");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkVisibility(attr, ATTR04, "protected");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkVisibility(attr, ATTR05, "public");
          checkVisibility(attr, ATTR01, "public");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkVisibility(attr, ATTR06, "private");
          checkVisibility(attr, ATTR01, "private");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkVisibility(attr, ATTR08, "public");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkVisibility(attr, ATTR11, "public");
      }
  
      /**
       * Test the parsing of an attribute's property.
       *
       * @throws ParseException if the parsing fails.
       */
      public void testAttributeProperty() throws ParseException {
          Object attr;
          String[] res1 = {
              "a", "b",
          };
          String[] res2 = {
              "a", "b", "c", "d",
          };
          String[] res3 = {
              "a", "b", "c", "d", "frozen",
              null,
          };
  
          Object ns =
              ProjectManager.getManager().getCurrentProject().getModel();
          Object attrType = ProjectManager.getManager().getCurrentProject()
                  .getDefaultAttributeType();
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkProperties(attr, ATTR04, res1);
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkProperties(attr, ATTR05, res2);
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkProperties(attr, ATTR06, res3);
      }
  
      /**
       * Test parsing an attribute's multiplicity.
       *
       * @throws ParseException if the parsing fails.
       */
      public void testAttributeMultiplicity() throws ParseException {
          Object attr;
  
          Object ns =
              ProjectManager.getManager().getCurrentProject().getModel();
          Object attrType = ProjectManager.getManager().getCurrentProject()
                  .getDefaultAttributeType();
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkMultiplicity(attr, ATTR04,
                  Model.getDataTypesFactory().createMultiplicity("1..1"));
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkMultiplicity(attr, ATTR05,
                  Model.getDataTypesFactory().createMultiplicity("1..*"));
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkMultiplicity(attr, ATTR06,
                  Model.getDataTypesFactory().createMultiplicity("*..*"));
      }
  
      /**
       * Test that the parser throws the correct exceptions.
       */
      public void testAttributeParseExceptions() {
          Object attr;
  
          Object ns =
              ProjectManager.getManager().getCurrentProject().getModel();
          Object attrType = ProjectManager.getManager().getCurrentProject()
                  .getDefaultAttributeType();
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkThrows(attr, NATTR01, true, false, false);
          checkThrows(attr, NATTR02, true, false, false);
          checkThrows(attr, NATTR03, true, false, false);
          checkThrows(attr, NATTR04, true, false, false);
          checkThrows(attr, NATTR05, true, false, false);
          checkThrows(attr, NATTR06, true, false, false);
          checkThrows(attr, NATTR07, true, false, false);
          checkThrows(attr, NATTR08, true, false, false);
          checkThrows(attr, NATTR09, true, false, false);
          checkThrows(attr, NATTR10, true, false, false);
          checkThrows(attr, NATTR11, true, false, false);
          checkThrows(attr, NATTR12, true, false, false);
          checkThrows(attr, NATTR13, true, false, false);
      }
  
      /**
       * Test the parsing of an attribute's value.
       *
       * @throws ParseException if the parsing fails.
       */
      public void testAttributeValue() throws ParseException {
          Object attr;
  
          Object ns =
              ProjectManager.getManager().getCurrentProject().getModel();
          Object attrType = ProjectManager.getManager().getCurrentProject()
                  .getDefaultAttributeType();
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkValue(attr, ATTR05, "0");
          checkValue(attr, ATTR01, "0");
          checkValue(attr, ATTR06, "15");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkValue(attr, ATTR07, "\'val[15] \'");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkValue(attr, ATTR08, "\"a <<string>>\"");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
          checkValue(attr, ATTR09, "(a * (b+c) - d)");
  
          attr = Model.getCoreFactory().buildAttribute2(attrType);
          Model.getCoreHelper().setNamespace(attr, ns);
  
  