Uml data import/export test added, Java metamodel slightly modified for testing purposes. BLD200207110100
authordprusa@netbeans.org
Wed, 10 Jul 2002 09:52:51 +0000
changeset 931eac36e2aaa03
parent 930 d79a2ac19364
child 932 071a3ce7f057
Uml data import/export test added, Java metamodel slightly modified for testing purposes.
mdr/test/build-unit.xml
mdr/test/unit/src/org/netbeans/mdr/test/MDRExportImportTest.java
mdr/test/unit/src/org/netbeans/mdr/test/MDRTestCase.java
mdr/test/unit/src/org/netbeans/mdr/test/data/Java.xml
     1.1 --- a/mdr/test/build-unit.xml	Tue Jul 09 19:44:00 2002 +0000
     1.2 +++ b/mdr/test/build-unit.xml	Wed Jul 10 09:52:51 2002 +0000
     1.3 @@ -220,6 +220,7 @@
     1.4  	    <pathelement location="../test/unit/src/org/netbeans/mdr/test/data/component.jar"/>
     1.5              <pathelement location="../test/unit/src/org/netbeans/mdr/test/data/indexedModel.jar"/>
     1.6              <pathelement location="../test/unit/src/org/netbeans/mdr/test/data/staticFeatures.jar"/>
     1.7 +            <pathelement location="../test/unit/src/org/netbeans/mdr/test/data/uml-14.jar"/>
     1.8      	</path>
     1.9      </target>
    1.10          
     2.1 --- a/mdr/test/unit/src/org/netbeans/mdr/test/MDRExportImportTest.java	Tue Jul 09 19:44:00 2002 +0000
     2.2 +++ b/mdr/test/unit/src/org/netbeans/mdr/test/MDRExportImportTest.java	Wed Jul 10 09:52:51 2002 +0000
     2.3 @@ -108,6 +108,68 @@
     2.4      }
     2.5      
     2.6      /**
     2.7 +     * Loads and instantiates UML metamodel, generates random instances, exports
     2.8 +     * them to xmi files and loades them back (in another extent).
     2.9 +     *
    2.10 +     * Note that UML 1.4 metamodel is not part of open source. It have to be
    2.11 +     * added to 'data' directory (together with related Diff file), otherwise
    2.12 +     * this test always fails.
    2.13 +     */    
    2.14 +    public void testUML () {
    2.15 +        URL url = this.getClass ().getResource ("data//01-02-15.xml");
    2.16 +        if (url == null)
    2.17 +            fail ("Resource not found: " + "data//01-02-15.xml (UML 1.4 metamodel have to be downloaded from www.omg.org and placed in data directory)");
    2.18 +        url = this.getClass ().getResource ("data//01-02-15_Diff.xml");
    2.19 +        if (url == null)
    2.20 +            fail ("Resource not found: " + "data//01-02-15_Diff.xml (UML 1.4 metamodel Diff file have to be downloaded from mdr.netbeans.org and placed in data directory)");
    2.21 +        try {
    2.22 +            Class.forName ("org.omg.uml.UmlPackage");
    2.23 +        } catch (ClassNotFoundException e) {
    2.24 +            fail ("UML jmi interfaces not included in path.");
    2.25 +        }
    2.26 +
    2.27 +        // load UML metamodel
    2.28 +        ModelPackage model = loadMOFModel("01-02-15_Diff.xml", "model");                
    2.29 +        // instantiate UML metamodel
    2.30 +        RefPackage pkg_1 = createExtent (findMofPackage(model, "UML"), "UML");
    2.31 +        // generate random instances and links
    2.32 +        new RandomDataGenerator ().generate (pkg_1, 0, 12);
    2.33 +        
    2.34 +        Lookup lookup = Lookup.getDefault ();
    2.35 +        XMIReader reader = (XMIReader) lookup.lookup (XMIReader.class);
    2.36 +        XMIWriter writer = (XMIWriter) lookup.lookup (XMIWriter.class);
    2.37 +        
    2.38 +        // export generated data
    2.39 +        File file = new File ("uml_data.xml");
    2.40 +        try {
    2.41 +            OutputStream os = new FileOutputStream (file);
    2.42 +            repository.beginTrans (true);
    2.43 +            writer.write (os, pkg_1);
    2.44 +            os.flush ();
    2.45 +            os.close ();
    2.46 +        } catch (Exception e) {
    2.47 +            fail (e.getMessage ());
    2.48 +        } finally {
    2.49 +            repository.endTrans ();
    2.50 +        }
    2.51 +        
    2.52 +        // create second extent of UML metamodel
    2.53 +        RefPackage pkg_2 = createExtent (findMofPackage(model, "UML"), "UML");
    2.54 +        // read back exported data
    2.55 +        try {
    2.56 +            repository.beginTrans (true);
    2.57 +            reader.read (file.toURL ().toExternalForm(), new RefPackage[] {pkg_2});            
    2.58 +        } catch (Exception e) {            
    2.59 +            fail (e.getMessage ());
    2.60 +        } finally {
    2.61 +            repository.endTrans ();
    2.62 +        }
    2.63 +        
    2.64 +        // compare number of instances and links in both extents
    2.65 +        compareData (pkg_1, pkg_2, new HashSet ());
    2.66 +    }
    2.67 +    
    2.68 +    /**
    2.69       * Creates instance of Model package, loads Java metamodel into it, exports the loaded
    2.70       * data and compares the created XMI file to the original one.
    2.71       */
    2.72 @@ -137,6 +199,36 @@
    2.73      }
    2.74       */
    2.75      
    2.76 +    private void compareData (RefPackage pkg_1, RefPackage pkg_2, Set checkedPackages) {
    2.77 +        Set set = new HashSet ();
    2.78 +        checkedPackages.add (pkg_1);
    2.79 +        Iterator iter = pkg_1.refAllClasses ().iterator ();
    2.80 +        while (iter.hasNext ()) {
    2.81 +            RefClass proxy = (RefClass) iter.next ();
    2.82 +            ModelElement meta = (ModelElement) proxy.refMetaObject ();
    2.83 +            int count = proxy.refAllOfType ().size ();
    2.84 +            int count2 = pkg_2.refClass (meta).refAllOfType ().size ();
    2.85 +            if (count != count2)
    2.86 +                fail ("Number of instances does not match: " + meta.getName ());            
    2.87 +        }
    2.88 +        iter = pkg_1.refAllAssociations ().iterator ();
    2.89 +        while (iter.hasNext ()) {
    2.90 +            RefAssociation proxy = (RefAssociation) iter.next ();
    2.91 +            ModelElement meta = (ModelElement) proxy.refMetaObject ();
    2.92 +            int count = proxy.refAllLinks ().size ();
    2.93 +            int count2 = pkg_2.refAssociation (meta).refAllLinks ().size ();
    2.94 +            if (count != count2)
    2.95 +                fail ("Number of links does not match: " + meta.getName ());            
    2.96 +        }
    2.97 +        iter = pkg_1.refAllPackages ().iterator ();
    2.98 +        while (iter.hasNext ()) {
    2.99 +            RefPackage p1 = (RefPackage) iter.next ();
   2.100 +            ModelElement meta = (ModelElement) p1.refMetaObject ();
   2.101 +            RefPackage p2 = pkg_2.refPackage (meta);
   2.102 +            compareData (p1, p2, checkedPackages);
   2.103 +        }
   2.104 +    }
   2.105 +    
   2.106      /**
   2.107       * Creates instance of Model package, loads a metamodel into it, exports the loaded
   2.108       * data and compares the created XMI file to the original one.
   2.109 @@ -205,11 +297,7 @@
   2.110          RefPackage result = createExtent (
   2.111              findMofPackage (pkg, mainPackageName),
   2.112              mainPackageName
   2.113 -        );
   2.114 -        try {
   2.115 -            pkg.refDelete ();
   2.116 -        } catch (Exception e) {
   2.117 -        }
   2.118 +        );        
   2.119          return result;
   2.120      }
   2.121      
     3.1 --- a/mdr/test/unit/src/org/netbeans/mdr/test/MDRTestCase.java	Tue Jul 09 19:44:00 2002 +0000
     3.2 +++ b/mdr/test/unit/src/org/netbeans/mdr/test/MDRTestCase.java	Wed Jul 10 09:52:51 2002 +0000
     3.3 @@ -59,7 +59,7 @@
     3.4          XMIReader reader = (XMIReader) lookup.lookup (XMISaxReaderImpl.class);        
     3.5          URL url = this.getClass ().getResource ("data//" + docName);
     3.6          if (url == null)
     3.7 -            fail ("Resource not found.");
     3.8 +            fail ("Resource not found: " + "data//" + docName);
     3.9          ModelPackage pkg = (ModelPackage) createExtent (
    3.10              findMofPackage (modelPackage, "Model"), pkgName
    3.11          );
     4.1 --- a/mdr/test/unit/src/org/netbeans/mdr/test/data/Java.xml	Tue Jul 09 19:44:00 2002 +0000
     4.2 +++ b/mdr/test/unit/src/org/netbeans/mdr/test/data/Java.xml	Wed Jul 10 09:52:51 2002 +0000
     4.3 @@ -139,7 +139,7 @@
     4.4                </Model:TypedElement.type>
     4.5              </Model:Attribute>
     4.6              <Model:Attribute xmi.id = 'a24' name = 'isPrimitive' annotation = '' scope = 'instance_level'
     4.7 -              visibility = 'public_vis' isChangeable = 'false' isDerived = 'true'>
     4.8 +              visibility = 'public_vis' isChangeable = 'false' isDerived = 'false'>
     4.9                <Model:StructuralFeature.multiplicity>
    4.10                  <XMI.field>1</XMI.field>
    4.11                  <XMI.field>1</XMI.field>
    4.12 @@ -193,61 +193,7 @@
    4.13                <Model:Reference.referencedEnd>
    4.14                  <Model:AssociationEnd xmi.idref = 'a30'/>
    4.15                </Model:Reference.referencedEnd>
    4.16 -            </Model:Reference>
    4.17 -            <Model:Operation xmi.id = 'a31' name = 'lookupElement' annotation = '' scope = 'instance_level'
    4.18 -              visibility = 'public_vis' isQuery = 'false'>
    4.19 -              <Model:Namespace.contents>
    4.20 -                <Model:Parameter xmi.id = 'a32' name = '*return' annotation = '' direction = 'return_dir'>
    4.21 -                  <Model:Parameter.multiplicity>
    4.22 -                    <XMI.field>1</XMI.field>
    4.23 -                    <XMI.field>1</XMI.field>
    4.24 -                    <XMI.field>false</XMI.field>
    4.25 -                    <XMI.field>false</XMI.field>
    4.26 -                  </Model:Parameter.multiplicity>
    4.27 -                  <Model:TypedElement.type>
    4.28 -                    <Model:Class xmi.idref = 'a27'/>
    4.29 -                  </Model:TypedElement.type>
    4.30 -                </Model:Parameter>
    4.31 -                <Model:Parameter xmi.id = 'a33' name = 'name' annotation = '' direction = 'in_dir'>
    4.32 -                  <Model:Parameter.multiplicity>
    4.33 -                    <XMI.field>1</XMI.field>
    4.34 -                    <XMI.field>1</XMI.field>
    4.35 -                    <XMI.field>false</XMI.field>
    4.36 -                    <XMI.field>false</XMI.field>
    4.37 -                  </Model:Parameter.multiplicity>
    4.38 -                  <Model:TypedElement.type>
    4.39 -                    <Model:AliasType xmi.idref = 'a34'/>
    4.40 -                  </Model:TypedElement.type>
    4.41 -                </Model:Parameter>
    4.42 -              </Model:Namespace.contents>
    4.43 -            </Model:Operation>
    4.44 -            <Model:Operation xmi.id = 'a35' name = 'lookupElementExtended' annotation = ''
    4.45 -              scope = 'instance_level' visibility = 'public_vis' isQuery = 'false'>
    4.46 -              <Model:Namespace.contents>
    4.47 -                <Model:Parameter xmi.id = 'a36' name = '*return' annotation = '' direction = 'return_dir'>
    4.48 -                  <Model:Parameter.multiplicity>
    4.49 -                    <XMI.field>1</XMI.field>
    4.50 -                    <XMI.field>1</XMI.field>
    4.51 -                    <XMI.field>false</XMI.field>
    4.52 -                    <XMI.field>false</XMI.field>
    4.53 -                  </Model:Parameter.multiplicity>
    4.54 -                  <Model:TypedElement.type>
    4.55 -                    <Model:Class xmi.idref = 'a27'/>
    4.56 -                  </Model:TypedElement.type>
    4.57 -                </Model:Parameter>
    4.58 -                <Model:Parameter xmi.id = 'a37' name = 'name' annotation = '' direction = 'in_dir'>
    4.59 -                  <Model:Parameter.multiplicity>
    4.60 -                    <XMI.field>1</XMI.field>
    4.61 -                    <XMI.field>1</XMI.field>
    4.62 -                    <XMI.field>false</XMI.field>
    4.63 -                    <XMI.field>false</XMI.field>
    4.64 -                  </Model:Parameter.multiplicity>
    4.65 -                  <Model:TypedElement.type>
    4.66 -                    <Model:AliasType xmi.idref = 'a34'/>
    4.67 -                  </Model:TypedElement.type>
    4.68 -                </Model:Parameter>
    4.69 -              </Model:Namespace.contents>
    4.70 -            </Model:Operation>
    4.71 +            </Model:Reference>            
    4.72            </Model:Namespace.contents>
    4.73            <Model:GeneralizableElement.supertypes>
    4.74              <Model:Class xmi.idref = 'a27'/>
    4.75 @@ -284,7 +230,7 @@
    4.76                </Model:Reference.referencedEnd>
    4.77              </Model:Reference>
    4.78              <Model:Attribute xmi.id = 'a41' name = 'qualifiedName' annotation = '' scope = 'instance_level'
    4.79 -              visibility = 'public_vis' isChangeable = 'false' isDerived = 'true'>
    4.80 +              visibility = 'public_vis' isChangeable = 'false' isDerived = 'false'>
    4.81                <Model:StructuralFeature.multiplicity>
    4.82                  <XMI.field>1</XMI.field>
    4.83                  <XMI.field>-1</XMI.field>
    4.84 @@ -294,34 +240,7 @@
    4.85                <Model:TypedElement.type>
    4.86                  <Model:AliasType xmi.idref = 'a34'/>
    4.87                </Model:TypedElement.type>
    4.88 -            </Model:Attribute>
    4.89 -            <Model:Operation xmi.id = 'a42' name = 'resolveQualifiedName' annotation = ''
    4.90 -              scope = 'classifier_level' visibility = 'public_vis' isQuery = 'true'>
    4.91 -              <Model:Namespace.contents>
    4.92 -                <Model:Parameter xmi.id = 'a43' name = '*return' annotation = '' direction = 'return_dir'>
    4.93 -                  <Model:Parameter.multiplicity>
    4.94 -                    <XMI.field>1</XMI.field>
    4.95 -                    <XMI.field>1</XMI.field>
    4.96 -                    <XMI.field>false</XMI.field>
    4.97 -                    <XMI.field>false</XMI.field>
    4.98 -                  </Model:Parameter.multiplicity>
    4.99 -                  <Model:TypedElement.type>
   4.100 -                    <Model:Class xmi.idref = 'a27'/>
   4.101 -                  </Model:TypedElement.type>
   4.102 -                </Model:Parameter>
   4.103 -                <Model:Parameter xmi.id = 'a44' name = 'qualifiedName' annotation = '' direction = 'in_dir'>
   4.104 -                  <Model:Parameter.multiplicity>
   4.105 -                    <XMI.field>1</XMI.field>
   4.106 -                    <XMI.field>1</XMI.field>
   4.107 -                    <XMI.field>false</XMI.field>
   4.108 -                    <XMI.field>false</XMI.field>
   4.109 -                  </Model:Parameter.multiplicity>
   4.110 -                  <Model:TypedElement.type>
   4.111 -                    <Model:AliasType xmi.idref = 'a34'/>
   4.112 -                  </Model:TypedElement.type>
   4.113 -                </Model:Parameter>
   4.114 -              </Model:Namespace.contents>
   4.115 -            </Model:Operation>
   4.116 +            </Model:Attribute>            
   4.117            </Model:Namespace.contents>
   4.118          </Model:Class>
   4.119          <Model:Class xmi.id = 'a45' name = 'Throwable' annotation = '' isRoot = 'false'