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 javax.jmi.reflect.*; 38 import javax.jmi.model.*; 39 40 import staticfeatures.*; 41 42 45 public class StaticFeaturesTest extends MDRTestCase { 46 47 public StaticFeaturesTest(String testName) { 48 super (testName); 49 } 50 51 public static void main (String [] args) { 52 junit.textui.TestRunner.run (suite ()); 53 } 54 55 public static Test suite () { 56 TestSuite suite = new TestSuite (); 57 suite.addTestSuite (StaticFeaturesTest.class); 58 59 TestSetup setup = new TestSetup (suite) { 60 public void setUp () { 61 } 62 public void tearDown () { 63 } 64 }; 65 return setup; 66 } 67 68 public void test_1 () { 70 ModelPackage modelPackage = loadMOFModel ("staticFeatures.xml", "model"); 71 StaticFeaturesPackage pkg = (StaticFeaturesPackage) createExtent (findMofPackage (modelPackage, "StaticFeatures"), "staticFeatures"); 72 73 int x, y; 74 final int MAX = 100; 75 final int INT_VALUE = 678; 76 Random random = new Random (0); 77 78 ClassAClass proxyA = pkg.getClassA (); ClassBClass proxyB = pkg.getClassB (); 80 ClassCClass proxyC = pkg.getClassC (); ClassDClass proxyD = pkg.getClassD (); 83 if (proxyD.getStaticFieldD() != null) 84 fail (); 85 proxyD.setStaticFieldD("123"); 86 proxyB.setStaticFieldA("abcdef"); 87 88 for (x = 0; x < MAX; x++) { 89 int value = random.nextInt (); 90 proxyD.setStaticFieldB (value); 91 if ((proxyA.getStaticFieldB () != value) || (proxyD.getStaticFieldB () != value)) 92 fail (); 93 } 94 95 proxyD.setStaticFieldC (INT_VALUE); 96 97 if (!proxyD.getStaticFieldD().equals("123")) 98 fail(); 99 if (!proxyB.getStaticFieldA().equals("abcdef")) 100 fail(); 101 if (proxyD.getStaticFieldC() != INT_VALUE) 102 fail(); 103 104 proxyD.setStaticFieldC (22); 105 if (!proxyB.getStaticFieldA().equals("abcdef")) 106 fail(); 107 108 pkg.refDelete (); 109 modelPackage.refDelete (); 110 } 111 112 public void test_2 () { 114 ModelPackage modelPackage = loadMOFModel ("staticFeatures.xml", "model"); 115 StaticFeaturesPackage pkg = (StaticFeaturesPackage) createExtent (findMofPackage (modelPackage, "StaticFeatures"), "staticFeatures"); 116 117 ClassAClass proxyA = pkg.getClassA (); ClassBClass proxyB = pkg.getClassB (); 119 ClassCClass proxyC = pkg.getClassC (); ClassDClass proxyD = pkg.getClassD (); 122 ClassA objA = proxyA.createClassA (); 123 ClassB objB = proxyB.createClassB (); 124 ClassD objD = proxyD.createClassD (); 125 126 if (!(proxyC.returnParam (objA) == objA)) fail (); 128 if (!(proxyC.returnParam (objB) == objB)) 129 fail (); 130 if (!(proxyC.returnParam (objD) == objD)) 131 fail (); 132 133 if (!(proxyD.returnParam (objA) == objA)) 134 fail (); 135 if (!(proxyD.returnParam (objB) == objB)) 136 fail (); 137 if (!(proxyD.returnParam (objD) == objD)) 138 fail (); 139 140 List params = new LinkedList (); 141 params.add (objD); 142 try { 143 proxyD.refInvokeOperation ("compute", params); 144 } catch (RefException e) { 145 fail(); 146 } 147 148 if (proxyD.compute(objD) != 333) fail(); 150 151 pkg.refDelete (); 152 modelPackage.refDelete (); 153 } 154 155 public void test_3 () { 157 ModelPackage modelPackage = loadMOFModel ("staticFeatures.xml", "model"); 158 StaticFeaturesPackage pkg = (StaticFeaturesPackage) createExtent (findMofPackage (modelPackage, "StaticFeatures"), "staticFeatures"); 159 160 ClassDClass proxyD = pkg.getClassD (); 162 if (proxyD.getStaticDerivedField() != 123) 163 fail(); 164 165 pkg.refDelete (); 166 modelPackage.refDelete (); 167 } 168 169 public void test_reflective () { 171 ModelPackage modelPackage = loadMOFModel ("staticFeatures.xml", "model"); 172 StaticFeaturesPackage pkg = (StaticFeaturesPackage) createExtent (findMofPackage (modelPackage, "StaticFeatures"), "staticFeatures"); 173 174 int x, y; 175 final int MAX = 100; 176 final int INT_VALUE = 678; 177 Random random = new Random (0); 178 179 RefClass proxyA = pkg.getClassA (); RefClass proxyB = pkg.getClassB (); 181 RefClass proxyC = pkg.getClassC (); RefClass proxyD = pkg.getClassD (); 184 if (proxyD.refGetValue("staticFieldD") != null) 185 fail (); 186 proxyD.refSetValue("staticFieldD", "123"); 187 proxyB.refSetValue("staticFieldA", "abcdef"); 188 189 for (x = 0; x < MAX; x++) { 190 int value = random.nextInt (); 191 proxyD.refSetValue("staticFieldB", new Integer (value)); 192 if ( (((Integer )proxyA.refGetValue("staticFieldB")).intValue() != value) || (((Integer )proxyD.refGetValue("staticFieldB")).intValue() != value)) 193 fail (); 194 } 195 196 proxyD.refSetValue("staticFieldC", new Integer (INT_VALUE)); 197 198 if (!proxyD.refGetValue("staticFieldD").equals("123")) 199 fail(); 200 if (!proxyB.refGetValue("staticFieldA").equals("abcdef")) 201 fail(); 202 if (((Integer )proxyD.refGetValue("staticFieldC")).intValue() != INT_VALUE) 203 fail(); 204 205 proxyD.refSetValue("staticFieldC", new Integer (22)); 206 if (!proxyB.refGetValue("staticFieldA").equals("abcdef")) 207 fail(); 208 209 pkg.refDelete (); 210 modelPackage.refDelete (); 211 } 212 } 213 | Popular Tags |