1 7 package ch.ethz.prose.query; 8 9 import junit.framework.*; 11 12 import ch.ethz.prose.DefaultAspect; 13 import ch.ethz.prose.ProseSystem; 14 import ch.ethz.prose.crosscut.Crosscut; 15 import ch.ethz.prose.crosscut.MethodCut; 16 import ch.ethz.prose.filter.PointCutter; 17 import ch.ethz.prose.filter.Within; 18 19 20 21 27 public 28 class QueryManagerTest extends TestCase { 29 30 34 public QueryManagerTest(String name) 35 { 36 super(name); 37 } 38 39 public static class QMCrosscut extends MethodCut 40 { 41 public void METHOD_ARGS(QueryManagerTest tst, int i) 42 {} 43 44 protected PointCutter pointCutter() 45 { 46 return Within.method("salut"); 47 } 48 }; 49 50 public static class QMAspect1 extends DefaultAspect 51 { 52 public Crosscut c1 = new QMCrosscut(); 53 public Crosscut c2 = new QMCrosscut(); 54 public Crosscut c3 = new QMCrosscut(); 55 } 56 57 public static class QMAspect2 extends DefaultAspect 58 { 59 public Crosscut c1 = new QMCrosscut(); 60 } 61 62 QMAspect1 a1 = null; 63 QMAspect2 a2 = null; 64 QueryManager qMgr = null; 65 68 protected 69 void setUp() throws Exception 70 { 71 ProseSystem.startup(); 72 a1 = new QMAspect1(); 73 a2 = new QMAspect2(); 74 qMgr = new QueryManager(ProseSystem.getAspectManager()); 75 } 76 77 protected void tearDown() throws Exception 78 { 79 ProseSystem.teardown(); 80 } 81 82 86 public static 87 Test suite() 88 { 89 return new TestSuite(QueryManagerTest.class); 90 } 91 92 93 public void testReconstructAspect() throws Exception 94 { 95 ProseSystem.getAspectManager().insert(a1); 96 ProseSystem.getAspectManager().insert(a2); 97 98 AspectSurrogate as1 = new AspectSurrogate(a1); 99 100 assertSame("a1 == as1.reconstruct",a1,qMgr.reconstructAspect(as1)); 101 assertEquals("a1 EQUALS as1.reconstruct",a1,qMgr.reconstructAspect(as1)); 102 103 ProseSystem.getAspectManager().withdraw(a1); 104 assertNull("a1.reconstruct = null",qMgr.reconstructAspect(as1)); 105 } 106 107 public void testReconstructCrosscut() throws Exception 108 { 109 ProseSystem.getAspectManager().insert(a1); 110 111 AspectSurrogate as1 = new AspectSurrogate(a1); 112 CrosscutSurrogate cs2 = new CrosscutSurrogate(as1,a1.c2); 113 114 assertSame("a1.c2 == cs3.reconstruct",a1.c2,qMgr.reconstructCrosscut(cs2)); 115 ProseSystem.getAspectManager().withdraw(a1); 116 117 assertNull("a1.c2.reconstruct = null",qMgr.reconstructCrosscut(cs2)); 118 } 119 } 120 121 122 | Popular Tags |