1 7 package ch.ethz.prose; 8 9 import java.util.List ; 11 import java.util.Vector ; 12 13 import junit.framework.*; 14 import ch.ethz.jvmai.JVMAspectInterface; 15 import ch.ethz.prose.engine.JoinPointManager; 16 17 18 24 public 25 class ExtensionSystemTest extends TestCase { 26 27 public static class ExampleExtensionSystem{ 28 29 public static boolean appSetupVisited = false; 30 31 public static void startup() throws SystemStartupException { appSetupVisited=true;} 32 public static void teardown() throws SystemTeardownException {} 33 } 34 35 public static class ExampleExtensionManager implements AspectManager { 36 37 public ExampleExtensionManager(boolean ic, JVMAspectInterface ai) { } 38 39 public List withdrawnExtensions = new Vector (); 40 public List insertedExtensions = new Vector (); 41 42 public List getAllJoinpoints(){return null;} 43 public void insert(Aspect ext,Object tx){} 44 public void withdraw(Aspect ext,Object tx){} 45 public void commit(Object tx){} 46 public void abort(Object tx){} 47 public void insert(Aspect ext) { insertedExtensions.add(ext);} 48 public void withdraw(Aspect ext) { withdrawnExtensions.add(ext);} 49 50 public List getAllAspects() {return null;} 51 public JoinPointManager getJoinPointManager() {return null;} 52 public void teardown() { } 53 public void startup() { } 54 public List queryAspects(List aspectList, int selectFields, int groupBy) { return null; } 55 public List queryCrosscuts(List crosscutList, int selectFields, int groupBy) { return null; } 56 public List queryJoinpoints(List joinpointList, int selectFields, int groupBy) { return null; } 57 58 } 59 60 64 public ExtensionSystemTest(String name) 65 { 66 super(name); 67 } 68 69 72 protected 73 void setUp() 74 { 75 System.setProperty("ch.ethz.prose.EXManager", 76 "ch.ethz.prose.ExtensionSystemTest$ExampleExtensionManager"); 77 System.setProperty("ch.ethz.prose.ESSystem.1", 78 "ch.ethz.prose.ExtensionSystemTest$ExampleExtensionSystem"); 79 } 80 81 public void tearDown() 82 { 83 System.getProperties().remove("ch.ethz.prose.EXManager"); 84 System.getProperties().remove("ch.ethz.prose.ESSystem.1"); 85 } 86 87 91 public static 92 Test suite() 93 { 94 return new TestSuite(ExtensionSystemTest.class); 95 } 96 97 public void test1_SimpleSetup() throws Exception 100 { 101 System.getProperties().remove("ch.ethz.prose.EXManager"); 102 System.getProperties().remove("ch.ethz.prose.ESSystem.1"); 103 104 ProseSystem.startup(); 105 assertNotNull(ProseSystem.getAspectManager()); 106 assertNotNull(ProseSystem.getTestAspectManager()); 107 ProseSystem.teardown(); 108 } 109 110 public void test2_CustomSetup() throws Exception 113 { 114 try 115 { 116 System.getProperties().remove("ch.ethz.prose.ESSystem.1"); 117 118 ProseSystem.startup(); 119 assertNotNull(ProseSystem.getAspectManager()); 120 assertNotNull(ProseSystem.getTestAspectManager()); 121 assertTrue("current extension Manager have the correct type", 122 ProseSystem.getAspectManager() instanceof ExampleExtensionManager); 123 assertTrue("test extension Manager have the correct type", 124 ProseSystem.getTestAspectManager() instanceof ExampleExtensionManager); 125 ProseSystem.teardown(); 126 } 127 catch (RuntimeException e) 128 { 129 e.printStackTrace(); 130 throw e; 131 } 132 } 133 134 public void test3_FullCustomSetup() throws Exception 137 { 138 try { 139 RootComponent.startup(); 140 assertTrue(" the initialization procedure touched the flag", 141 ExampleExtensionSystem.appSetupVisited); 142 RootComponent.teardown(); 143 } 144 catch (Exception e) 145 { 146 e.printStackTrace(); 147 } 148 } 149 150 public void test4_Teardown() throws Exception 154 { 155 try 156 { 157 System.getProperties().remove("ch.ethz.prose.EXManager"); 158 System.getProperties().remove("ch.ethz.prose.ESSystem.1"); 159 160 ProseSystem.startup(); 162 assertNotNull(ProseSystem.getAspectManager()); 163 assertNotNull(ProseSystem.getTestAspectManager()); 164 165 Aspect x1 = new DefaultAspect(){}; 167 Aspect x2 = new DefaultAspect(){}; 168 169 170 ProseSystem.getAspectManager().insert(x1); 171 ProseSystem.getAspectManager().insert(x2); 172 173 ProseSystem.getTestAspectManager().insert(x1); 174 ProseSystem.getTestAspectManager().insert(x2); 175 176 AspectManager currentMgr = ProseSystem.getAspectManager(); 178 AspectManager testMgr = ProseSystem.getTestAspectManager(); 179 ProseSystem.teardown(); 180 181 assertTrue("empty extension list in currentMgr", currentMgr.getAllAspects().isEmpty()); 183 assertTrue("empty extension list in testMgr", testMgr.getAllAspects().isEmpty()); 184 } 185 catch (Exception e) 186 { 187 e.printStackTrace(); 188 throw e; 189 } 190 191 } 192 193 } 194 195 196
| Popular Tags
|