1 7 8 package org.netbeans.mdr.test; 9 10 import java.util.Collection ; 11 import java.util.HashMap ; 12 import java.util.Iterator ; 13 import java.util.LinkedList ; 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 32 public class MDRTestExtentEvents extends MDREventsTestCase implements MDRChangeListener { 33 34 private static final String PKG_NAME_MOF = "MOF_EXTENT"; 35 private static final String PKG_NAME_JAVA = "JAVA_EXTENT"; 36 private static final String MDL_NAME_JAVA = "JAVA_MODEL"; 37 private static final String PKG_NAME_TEXT = "TEXT_EXTENT"; 38 private static final String MDL_NAME_TEXT = "TEXT_MODEL"; 39 40 private java.io.PrintStream goldenRef = null; 41 private EventsList eventsList = new EventsList(); 42 43 public MDRTestExtentEvents(java.lang.String 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 59 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 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 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 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 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 ie) { } 124 } 125 assertTrue(eventsList.checkEvents(PKG_NAME_JAVA, EventsList._DELETE | EventsList._CHANGED)); 126 eventsList.clear(); 127 128 } 129 130 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)) { 140 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 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 |