1 19 package org.netbeans.mdr.test; 20 21 import java.util.*; 22 import junit.framework.*; 23 24 import org.netbeans.api.mdr.*; 25 26 import javax.jmi.reflect.*; 27 import javax.jmi.model.*; 28 29 33 public class InterceptionTest extends MDRTestCase { 34 35 private static final String MODEL_XMI = "component.xml"; 36 private static final String MODEL_PKG_NAME = "InterceptionTest"; 37 private static final String PKG_ELEMENT = "Test"; 38 private static final String PKG_NAME = "InterceptionExtent"; 39 40 public static short componentPreSet = 0; 41 public static short componentPostSet = 0; 42 public static boolean componentPreSetVersion = false; 43 public static short servicePreSet = 0; 44 public static short servicePostSet = 0; 45 public static boolean providesPreAdd = false; 46 public static boolean providesPostAdd = false; 47 48 49 public InterceptionTest(String testName) { 50 super(testName); 51 } 52 53 public static Test suite() { 54 return new TestSuite(InterceptionTest.class); 55 } 56 57 public static void main(String [] args) { 58 junit.textui.TestRunner.run(suite()); 59 } 60 61 public void test() { 62 ModelPackage pkg = this.loadMOFModel(MODEL_XMI, MODEL_PKG_NAME); 64 test.TestPackage testPkg = (test.TestPackage) createExtent(findMofPackage(pkg, PKG_ELEMENT), PKG_NAME); 66 if (testPkg == null) 67 fail("Extent creation failed."); 68 69 test.ComponentClass cClass = testPkg.getComponent(); 70 test.Component comp = cClass.createComponent("A", 1); 71 72 if (comp == null) 73 fail("Object creation failed."); 74 75 test.Component testComp = cClass.createComponent("A", 2); 76 if (testComp != null) 77 fail("Component creation interception failed."); 78 79 ArrayList list = new ArrayList(2); 80 list.add("A"); 81 list.add(new Integer (3)); 82 testComp = (test.Component)cClass.refCreateInstance(list); 83 if (testComp != null) 84 fail("Component creation interception failed."); 85 86 list = new ArrayList(2); 87 list.add("A"); 88 try { 89 cClass.refCreateInstance(list); 90 } catch (WrongSizeException tme) { 91 System.out.println("---> WrongSizeException is OK !!!"); 92 } 93 list.add("B"); 94 try { 95 cClass.refCreateInstance(list); 96 } catch (TypeMismatchException tme) { 97 System.out.println("---> TypeMismatchException is OK !!!"); 98 } 99 100 101 comp.setName("X"); 103 if (! comp.getName().equals("X")) 104 fail("Invalid attribute value"); 105 comp.setName("TestObjectInterceptor"); 106 if (! comp.getName().equals("X")) 107 fail("Setting component attribute interception failed."); 108 comp.refSetValue("name", "TestObjectInterceptor"); 109 if (! comp.getName().equals("X")) 110 fail("Setting component attribute via reflective interface interception failed."); 111 112 test.ServiceClass sClass = testPkg.getService(); 114 test.Service serv = sClass.createService("TestAssociationInterceptor"); 115 testPkg.getProvides().add(serv, comp); 116 Collection c = comp.getProvidedService(); 117 if (c.size() != 0) 118 fail("Association interceptor failed (C->S)"); 119 c = serv.getProvider(); 120 if (c.size() != 0) 121 fail("Association interceptor failed (S->C)"); 122 testPkg.getProvides().refAddLink(serv, comp); 123 c = comp.getProvidedService(); 124 if (c.size() != 0) 125 fail("Association reflactive interceptor failed (C->S)"); 126 c = serv.getProvider(); 127 if (c.size() != 0) 128 fail("Association reflective interceptor failed (S->C)"); 129 comp.getProvidedService().add(serv); 130 c = comp.getProvidedService(); 131 if (c.size() != 1) 132 fail("Adding association failed (C->S)"); 133 c = serv.getProvider(); 134 if (c.size() != 1) 135 fail("Adding association failed (S->C)"); 136 137 } 138 } 139 | Popular Tags |