KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > mdr > test > PackageInheritanceTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.mdr.test;
21
22 import java.io.*;
23 import java.util.*;
24 import java.net.*;
25
26 import junit.extensions.*;
27 import junit.framework.*;
28
29 import org.netbeans.api.mdr.*;
30 import org.openide.util.Lookup;
31
32 import org.netbeans.mdr.util.*;
33 import org.netbeans.mdr.NBMDRepositoryImpl;
34 import org.netbeans.lib.jmi.xmi.*;
35 import org.netbeans.lib.jmi.mapping.*;
36
37 import org.xml.sax.*;
38
39 import javax.jmi.reflect.*;
40 import javax.jmi.model.*;
41
42 /**
43  * Test case verifying functionality of package instantiation, especially cases when a package
44  * is a subclass of another package.
45  */

46 public class PackageInheritanceTest extends MDRTestCase {
47     
48     public PackageInheritanceTest(String JavaDoc testName) {
49         super (testName);
50     }
51     
52     public static void main (String JavaDoc[] args) {
53         junit.textui.TestRunner.run (suite ());
54     }
55     
56     public static Test suite () {
57         TestSuite suite = new TestSuite ();
58         suite.addTestSuite (PackageInheritanceTest.class);
59         
60         TestSetup setup = new TestSetup (suite) {
61             public void setUp () {
62 // org.netbeans.mdr.handlers.BaseObjectHandler.setDefaultClassLoader (this.getClass ().getClassLoader ());
63
}
64             public void tearDown () {
65             }
66         };
67         return setup;
68     }
69
70     public void test () {
71         ModelPackage pkg = loadMOFModel ("pkg_inher.xml", "PureMOF");
72         MofPackage mofPkg = findMofPackage (pkg, "Package_1");
73         RefPackage pkg_1 = createExtent (mofPkg, "Package_1");
74         mofPkg = findMofPackage (pkg, "Package_2");
75         RefPackage pkg_2 = createExtent (mofPkg, "Package_2");
76         mofPkg = findMofPackage (pkg, "Package_3");
77         RefPackage pkg_3 = createExtent (mofPkg, "Package_3");
78         
79         try {
80             for (char x = 'A'; x <= 'E'; x++)
81                 pkg_3.refClass ("Class_" + x);
82             for (char x = 'A'; x <= 'D'; x++)
83                 pkg_2.refClass ("Class_" + x);
84             
85             new RandomDataGenerator ().generate (pkg_3, 0, 5);
86             new RandomDataGenerator ().generate (pkg_2, 0, 5);
87             new RandomDataGenerator ().generate (pkg_1, 0, 5);
88             
89             pkg_1.refDelete ();
90             pkg_2.refDelete ();
91             pkg_3.refDelete ();
92             pkg.refDelete ();
93         } catch (Exception JavaDoc e) {
94             System.out.println(e);
95             e.printStackTrace ();
96             fail (e.getMessage ());
97         }
98     }
99     
100 }
101
Popular Tags