1 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.netbeans.api.mdr.events.*; 38 39 import javax.jmi.reflect.*; 40 import javax.jmi.model.*; 41 import javax.jmi.xmi.*; 42 43 47 public abstract class MDREventsTestCase extends TestCase { 48 49 public static final int PLANNED = 2; 51 public static final int CHANGED = 4; 52 public static final int CANCELED = 8; 53 54 protected LinkedList eventsQueue = new LinkedList(); 56 57 protected MDRepository repository = null; 59 protected ModelPackage modelPackage = null; 61 62 public MDREventsTestCase(String testName) { 63 super (testName); 64 } 65 66 74 public ModelPackage loadMOFModel (String docName, String pkgName) { 75 76 ModelPackage pkg = null; 77 78 Lookup lookup = Lookup.getDefault (); 79 XmiReader reader = (XmiReader) lookup.lookup (XmiReader.class); 80 URL url = this.getClass ().getResource ("data" + File.separator + docName); 81 if (url == null) { 82 fail ("Resource not found."); 83 } 84 85 try { 86 pkg = (ModelPackage) repository.createExtent(pkgName); 87 } catch (CreationFailedException cfe) { 88 fail ("Package instantiation failed: " + pkgName); 89 } 90 91 try { 92 repository.beginTrans (true); 93 reader.read (url.toExternalForm(), pkg); 94 } catch (Exception e) { 95 fail (e.getMessage ()); 96 } finally { 97 repository.endTrans (); 98 } 99 return pkg; 100 101 } 102 103 public MofPackage findMofPackage (ModelPackage modelPackage, String name) { 104 MofPackageClass proxy = modelPackage.getMofPackage (); 105 Iterator iter = proxy.refAllOfType ().iterator (); 106 MofPackage thePackage = null; 107 while (iter.hasNext ()) { 108 MofPackage pkg = (MofPackage) iter.next (); 109 if (pkg.getName ().equals (name)) { 110 thePackage = pkg; 111 break; 112 } } if (thePackage == null) 115 fail ("Cannot find package " + name); 116 return thePackage; 117 } 118 119 122 public RefPackage createExtent (MofPackage pkg, String name) { 123 try { 124 return repository.createExtent (name, pkg); 125 } catch (CreationFailedException e) { 126 } 127 fail ("Package instantiation failed: " + name); 128 return null; 129 } 130 131 134 public ModelPackage getExtent (String name) { 135 ModelPackage vmp = null; 136 try { 137 vmp = (ModelPackage) repository.getExtent (name); 138 } catch (Exception e) { 139 fail ("Model not loaded, name not resolved."); 140 } 141 return vmp; 142 } 143 144 public RefPackage createMOFExtent(String extentName) { 145 try { 146 return repository.createExtent(extentName); 147 } catch (CreationFailedException cfe) { 148 cfe.printStackTrace(); 149 } 150 return null; 151 } 152 153 155 protected void setUp() { 156 if (System.getProperty("org.openide.version") == null) { 158 System.setProperty("org.netbeans.mdr.persistence.Dir", System.getProperty("work.dir") + "/TestEventsRepository_" + System.currentTimeMillis()); 159 System.setProperty("org.netbeans.mdr.storagemodel.StorageFactoryClassName", 160 "org.netbeans.mdr.persistence.btreeimpl.btreestorage.BtreeFactory"); 161 System.setProperty("org.netbeans.lib.jmi.Logger.fileName", ""); 162 } 163 164 repository = MDRManager.getDefault().getDefaultRepository(); 165 if (repository == null) { 166 fail("Repository not found!"); 167 } else { 168 repository.getExtentNames(); 170 } 171 172 } 173 174 protected void tearDown() { 175 176 } 177 178 199 304 305 protected void log(String message) { 306 getLog().println(message); 307 } 308 309 protected PrintStream getLog() { 310 return System.err; 311 } 312 } 313 | Popular Tags |