KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * HandlerStorageTest.java
3  *
4  * Created on May 27, 2002, 5:32 PM
5  */

6
7 package org.netbeans.mdr.test;
8
9 import java.io.*;
10 import java.util.*;
11 import java.net.*;
12 import java.text.MessageFormat JavaDoc;
13
14 import junit.extensions.*;
15 import junit.framework.*;
16
17 import org.netbeans.api.mdr.*;
18 import org.openide.util.Lookup;
19
20 import org.netbeans.mdr.util.*;
21 import org.netbeans.mdr.NBMDRepositoryImpl;
22 import org.netbeans.lib.jmi.xmi.*;
23 import org.netbeans.lib.jmi.mapping.*;
24
25 import javax.jmi.reflect.*;
26 import javax.jmi.model.*;
27
28 /**
29  *
30  * @author tz97951
31  */

32 public class HandlerStorageTest extends MDRTestCase {
33     
34     private static final String JavaDoc MODEL_XMI = "component.xml";
35     private static final String JavaDoc MODEL_PACKAGE = "HandlerStorageTestModel";
36     private static final String JavaDoc PKG_ELEMENT = "Test";
37     private static final String JavaDoc PACKAGE = "HandlerStorageTest";
38     private static final String JavaDoc PROP_NAME ="NAME";
39     private static final String JavaDoc PROP_VALUE = "VALUE";
40     
41     /** Creates a new instance of HandlerStorageTest */
42     public HandlerStorageTest (String JavaDoc name) {
43         super (name);
44     }
45     
46     public void test () {
47         try {
48             this.loadMOFModel (MODEL_XMI, MODEL_PACKAGE);
49             ModelPackage pkg = (ModelPackage) this.repository.getExtent (MODEL_PACKAGE);
50             RefObject pkgObj = findMofPackage (pkg, PKG_ELEMENT);
51             test.TestPackage tpkg = (test.TestPackage) this.repository.createExtent (PACKAGE, pkgObj, null);
52             test.Component comp = tpkg.getComponent().createComponent ("TestComponent",1);
53             ((org.netbeans.mdr.handlers.InstanceHandler)comp)._getDelegate().putProperty (PROP_NAME,PROP_VALUE);
54             Object JavaDoc propValue = ((org.netbeans.mdr.handlers.InstanceHandler)comp)._getDelegate().getProperty (PROP_NAME);
55             if (!PROP_VALUE.equals (propValue)) {
56                 fail ("Invalid property value");
57             }
58             ((org.netbeans.mdr.handlers.InstanceHandler)comp)._getDelegate().removeProperty (PROP_NAME);
59             propValue = ((org.netbeans.mdr.handlers.InstanceHandler)comp)._getDelegate().getProperty (PROP_NAME);
60             if (propValue != null) {
61                 fail ("Invalid property value");
62             }
63         }catch (org.netbeans.api.mdr.CreationFailedException cfe) {
64             fail ("Extent creation failed");
65         }
66     }
67     
68     
69     public static Test suite() {
70         TestSuite suite = new TestSuite();
71         suite.addTestSuite(HandlerStorageTest.class);
72         TestSetup setup = new TestSetup(suite) {
73             public void setUp() {
74             }
75             public void tearDown() {
76             }
77         };
78         return setup;
79     }
80     
81     public static void main(String JavaDoc[] args) {
82         junit.textui.TestRunner.run(suite());
83     }
84     
85 }
86
Popular Tags