1 19 20 package org.netbeans.mdr.test; 21 22 import java.util.*; 23 24 import junit.framework.*; 25 import junit.extensions.*; 26 27 import org.netbeans.api.mdr.*; 28 import org.openide.util.Lookup; 29 30 import org.netbeans.mdr.NBMDRepositoryImpl; 31 import org.netbeans.lib.jmi.xmi.*; 32 import org.netbeans.junit.*; 33 34 import javax.jmi.model.*; 35 import javax.jmi.model.ModelPackage; 36 import javax.jmi.reflect.*; 37 import javax.xml.parsers.ParserConfigurationException ; 38 39 import java.io.File ; 40 41 public class MDRLoadModelTest extends NbTestCase implements MDRTestConstants { 42 43 private MDRepository repository = null; 44 45 public MDRLoadModelTest(String testName) { 46 super(testName); 47 } 48 49 public static void main(String [] args) { 50 junit.textui.TestRunner.run(suite()); 51 } 52 53 public static NbTest suite() { 54 55 NbTestSuite suite = new NbTestSuite(); 56 suite.addTestSuite(MDRLoadModelTest.class); 57 58 NbTestSetup setup = new NbTestSetup(suite) { 59 public void setUp() { 60 org.netbeans.mdr.handlers.BaseObjectHandler.setDefaultClassLoader( 61 this.getClass().getClassLoader() ); 62 } 63 public void tearDown() { 64 System.out.println("Saving MDR data ..."); 65 NBMDRepositoryImpl.saveAll(); 66 } 67 }; 68 69 return setup; 70 71 } 72 73 public void testLoadTestModel_1() { 74 75 ModelPackage mp = null; 76 77 try { 78 System.out.println("Loading Test Model ..." ); 79 mp = (ModelPackage) repository.getExtent(TEST_MODEL); 80 } catch (Exception e) { 81 System.out.println("Name not resolved, loading ..."); 83 } 84 if (mp == null) { 85 loadModel(TEST_MODEL, "data/testmodel_1.xml"); 86 } 87 88 assertTrue("Model " + TEST_MODEL + " was not loaded!", 89 isModelLoaded(TEST_MODEL)); 90 91 } 92 93 public void testLoadTestModel_2() { 94 95 ModelPackage mp = null; 96 97 try { 98 System.out.println("Loading Inheritance Model ..." ); 99 mp = (ModelPackage) repository.getExtent(TEST_MODEL2); 100 } catch (Exception e) { 101 System.out.println("Name not resolved, loading ..."); 103 } 104 if (mp == null) { 105 loadModel(TEST_MODEL2, "data/testmodel_2.xml"); 106 } 107 108 assertTrue("Model " + TEST_MODEL2 + " was not loaded!", 109 isModelLoaded(TEST_MODEL2)); 110 111 } 112 113 public void testLoadFilesystemsModel() { 114 115 ModelPackage mp = null; 116 117 try { 118 System.out.println("Loading Inheritance Model ..." ); 119 mp = (ModelPackage) repository.getExtent(FILESYSTEMS_MODEL); 120 } catch (Exception e) { 121 System.out.println("Name not resolved, loading ..."); 123 } 124 if (mp == null) { 125 loadModel(FILESYSTEMS_MODEL, "data/filesystems.xml"); 126 } 127 128 assertTrue("Model " + FILESYSTEMS_MODEL + " was not loaded!", 129 isModelLoaded(FILESYSTEMS_MODEL)); 130 131 } 132 133 public void testLoadJavaModel() { 134 135 ModelPackage mp = null; 136 137 try { 138 System.out.println("Loading Java Model ..." ); 139 mp = (ModelPackage)repository.getExtent(JAVA_MODEL); 140 } catch (Exception e) { 141 System.out.println("Name not resolved, loading ..."); 143 } 144 if (mp == null) { 145 loadModel(JAVA_MODEL, "data/java.xml"); 146 } 147 148 assertTrue("Model " + JAVA_MODEL + " was not loaded!", 149 isModelLoaded(JAVA_MODEL)); 150 151 } 152 153 private void loadModel(String name, String xmi_location) { 154 155 try { 156 ModelPackage model = (ModelPackage) repository.createExtent(name); 157 XMIReader xmiReaderTest = XMIReader.getDefault(); 158 xmiReaderTest.read(MDRLoadModelTest.class.getResource(xmi_location).toExternalForm(), new RefPackage[] { model } ); 159 } catch (Exception exc) { 160 fail(exc.toString()); 161 } 162 163 } 164 165 private boolean isModelLoaded(String name) { 166 167 ModelPackage vmp = null; 168 169 try { 170 vmp = (ModelPackage) repository.getExtent(name); 171 } catch (Exception e) { 172 fail("Model not loaded, name not resolved."); 173 } 174 if (vmp != null && vmp instanceof ModelPackage) { 175 return true; 176 } else { 177 return false; 178 } 179 180 } 181 182 protected void setUp() { 183 184 String workDir = System.getProperty("work.dir"); 185 186 if (System.getProperty("org.openide.version") == null) { 188 System.setProperty("org.netbeans.mdr.persistence.Dir", workDir + File.separator + "test_repository_1"); 189 System.setProperty("org.netbeans.mdr.storagemodel.StorageFactoryClassName", 190 "org.netbeans.mdr.persistence.btreeimpl.btreestorage.BtreeFactory"); 191 System.setProperty("org.openide.util.Lookup", "org.netbeans.mdr.test.MDRTestLookup"); 192 System.setProperty("org.netbeans.mdr.SaveStorageOnExit", "true"); 193 } 194 195 repository = MDRManager.getDefault().getDefaultRepository(); 196 if (repository == null) { 197 fail("Repository not found!"); 198 } else { 199 repository.getExtentNames(); 201 } 202 203 } 204 205 protected void tearDown() { 206 207 } 208 209 } 210 | Popular Tags |