KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * TestListeners.java
3  * NetBeans JUnit based test
4  *
5  * Created on 5. duben 2002, 17:00
6  */

7
8 package org.netbeans.mdr.test;
9
10 import java.util.Collection JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.LinkedList JavaDoc;
14 import junit.framework.*;
15
16 import org.netbeans.mdr.handlers.BaseObjectHandler;
17 import org.netbeans.mdr.NBMDRepositoryImpl;
18
19 import org.netbeans.api.mdr.MDRManager;
20 import org.netbeans.api.mdr.MDRepository;
21 import org.netbeans.api.mdr.CreationFailedException;
22
23 import org.netbeans.api.mdr.events.*;
24
25 import javax.jmi.reflect.*;
26 import javax.jmi.model.*;
27
28 /**
29  *
30  * @author mk97936
31  */

32 public class MDRTestExtentEvents extends MDREventsTestCase implements MDRChangeListener {
33     
34     private static final String JavaDoc PKG_NAME_MOF = "MOF_EXTENT";
35     private static final String JavaDoc PKG_NAME_JAVA = "JAVA_EXTENT";
36     private static final String JavaDoc MDL_NAME_JAVA = "JAVA_MODEL";
37     private static final String JavaDoc PKG_NAME_TEXT = "TEXT_EXTENT";
38     private static final String JavaDoc MDL_NAME_TEXT = "TEXT_MODEL";
39     
40     private java.io.PrintStream JavaDoc goldenRef = null;
41     private EventsList eventsList = new EventsList();
42     
43     public MDRTestExtentEvents(java.lang.String JavaDoc testName) {
44         super(testName);
45     }
46     
47     protected void setUp() {
48         super.setUp();
49         ((MDRChangeSource) repository).addListener(this);
50     }
51     
52     protected void tearDown() {
53         super.tearDown();
54         ((MDRChangeSource) repository).removeListener(this);
55     }
56     
57     // -------------------------------------------------------------------------
58

59     // Instantiate MOF
60
public void testCreateMOFExtent() {
61         
62         RefPackage mofExtent = null;
63         try {
64             eventsList.addPattern2(PKG_NAME_MOF, EventsList._CREATE & EventsList._CHANGED, System.currentTimeMillis());
65             mofExtent = repository.createExtent(PKG_NAME_MOF);
66             for (int i = 0; i < 10; i++) {
67                 try { Thread.currentThread().sleep(100); }
68                    catch (InterruptedException JavaDoc ie) { }
69             }
70             assertTrue(eventsList.checkEvents(PKG_NAME_MOF, EventsList._CREATE | EventsList._CHANGED));
71             eventsList.clear();
72         } catch (CreationFailedException cfe) {
73             fail(cfe.toString());
74         }
75         
76     }
77     
78     // Load Java model and instantiate it
79
public void testCreateJavaExtent() {
80         
81         RefPackage javaExtent = null;
82         
83         eventsList.addPattern2(MDL_NAME_JAVA, EventsList._CREATE & EventsList._CHANGED, System.currentTimeMillis());
84         ModelPackage javaMOFModel = loadMOFModel("Java.xml", MDL_NAME_JAVA);
85         assertTrue(eventsList.checkEvents(MDL_NAME_JAVA, EventsList._CREATE | EventsList._CHANGED));
86         eventsList.clear();
87         try {
88             eventsList.addPattern2(PKG_NAME_JAVA, EventsList._CREATE & EventsList._CHANGED, System.currentTimeMillis());
89             javaExtent = repository.createExtent(PKG_NAME_JAVA, findMofPackage(javaMOFModel, "Core"));
90             for (int i = 0; i < 10; i++) {
91                 try { Thread.currentThread().sleep(100); }
92                     catch (InterruptedException JavaDoc ie) { }
93             }
94             assertTrue(eventsList.checkEvents(PKG_NAME_JAVA, EventsList._CREATE | EventsList._CHANGED));
95             eventsList.clear();
96         } catch (CreationFailedException cfe) {
97             fail(cfe.toString());
98         }
99         
100     }
101     
102     public void testDeleteMOFExtent() {
103         
104         RefPackage mofExtent = repository.getExtent(PKG_NAME_MOF);
105         eventsList.addPattern2(PKG_NAME_MOF, EventsList._DELETE & EventsList._CHANGED, System.currentTimeMillis());
106         mofExtent.refDelete();
107         for (int i = 0; i < 10; i++) {
108             try { Thread.currentThread().sleep(100); }
109                 catch (InterruptedException JavaDoc ie) { }
110         }
111         assertTrue(eventsList.checkEvents(PKG_NAME_MOF, EventsList._DELETE | EventsList._CHANGED));
112         eventsList.clear();
113         
114     }
115     
116     public void testDeleteJavaExtent() {
117         
118         RefPackage javaExtent = repository.getExtent(PKG_NAME_JAVA);
119         eventsList.addPattern2(PKG_NAME_JAVA, EventsList._DELETE & EventsList._CHANGED, System.currentTimeMillis());
120         javaExtent.refDelete();
121         for (int i = 0; i < 10; i++) {
122             try { Thread.currentThread().sleep(100); }
123                 catch (InterruptedException JavaDoc ie) { }
124         }
125         assertTrue(eventsList.checkEvents(PKG_NAME_JAVA, EventsList._DELETE | EventsList._CHANGED));
126         eventsList.clear();
127         
128     }
129     
130     // -------------------------------------------------------------------------
131

132     public void change(MDRChangeEvent e) {
133         processEvent(e, CHANGED);
134     }
135     
136     private void processEvent(MDRChangeEvent e, int type) {
137         
138         if (e.isOfType(ExtentEvent.EVENTMASK_EXTENT)) { // ExtentEvent
139

140             // EVENT_EXTENT_CREATE
141
if (e.isOfType(ExtentEvent.EVENT_EXTENT_CREATE) && (type == PLANNED)) {
142                 eventsList.addEvent(((ExtentEvent) e).getExtentName(), e, System.currentTimeMillis(),
143                                     EventsList._CREATE | EventsList._PLANNED);
144             } else if (e.isOfType(ExtentEvent.EVENT_EXTENT_CREATE) && (type == CHANGED)) {
145                 eventsList.addEvent(((ExtentEvent) e).getExtentName(), e, System.currentTimeMillis(),
146                                     EventsList._CREATE | EventsList._CHANGED);
147             } else if (e.isOfType(ExtentEvent.EVENT_EXTENT_CREATE) && (type == CANCELED)) {
148                 eventsList.addEvent(((ExtentEvent) e).getExtentName(), e, System.currentTimeMillis(),
149                                     EventsList._CREATE | EventsList._CANCELED);
150             }
151             // EVENT_EXTENT_DELETE
152
else if (e.isOfType(ExtentEvent.EVENT_EXTENT_DELETE) && (type == PLANNED)) {
153                 eventsList.addEvent(((ExtentEvent) e).getExtentName(), e, System.currentTimeMillis(),
154                                     EventsList._DELETE | EventsList._PLANNED);
155             } else if (e.isOfType(ExtentEvent.EVENT_EXTENT_DELETE) && (type == CHANGED)) {
156                 eventsList.addEvent(((ExtentEvent) e).getExtentName(), e, System.currentTimeMillis(),
157                                     EventsList._DELETE | EventsList._CHANGED);
158             } else if (e.isOfType(ExtentEvent.EVENT_EXTENT_DELETE) && (type == CANCELED)) {
159                 eventsList.addEvent(((ExtentEvent) e).getExtentName(), e, System.currentTimeMillis(),
160                                     EventsList._DELETE | EventsList._CANCELED);
161             }
162             
163         }
164     }
165     
166 }
167
Popular Tags