1 7 package ch.ethz.prose.filter; 8 9 import java.lang.reflect.Method ; 11 import java.lang.reflect.Modifier ; 12 13 import junit.framework.*; 14 import ch.ethz.jvmai.MethodEntryJoinPoint; 15 import ch.ethz.prose.ProseSystem; 16 import ch.ethz.prose.engine.JoinPointManager; 17 import ch.ethz.prose.engine.MethodEntryRequest; 18 19 25 public 26 class MethodSTest extends TestCase { 27 28 static void fooBar(){} 33 public void niceFooBar(){} 34 protected void badFooBar(){} 35 public synchronized void aSimpleMethodBody(){} 36 synchronized final void aSimpleBody(){} 37 void aSeccondBody(){} 38 39 40 MethodEntryRequest fooBarRequest; 42 MethodEntryRequest niceFooBarRequest; 43 MethodEntryRequest badFooBarRequest; 44 MethodEntryRequest aSimpleMethodBodyRequest; 45 MethodEntryRequest aSimpleBodyRequest; 46 MethodEntryRequest aSeccondBodyRequest; 47 48 50 51 55 public MethodSTest(String name) 56 { 57 super(name); 58 } 59 60 63 protected 64 void setUp() throws Exception 65 { 66 ProseSystem.startup(); 67 68 JoinPointManager jpm = ProseSystem.getAspectManager().getJoinPointManager(); 69 70 Method fooBarMethod = getClass().getDeclaredMethod("fooBar" ,new Class []{}); 71 Method niceFooBarMethod = getClass().getDeclaredMethod("niceFooBar" ,new Class []{}); 72 Method badFooBarMethod = getClass().getDeclaredMethod("badFooBar" ,new Class []{}); 73 Method aSimpleMethodBodyMethod = getClass().getDeclaredMethod("aSimpleMethodBody",new Class []{}); 74 Method aSimpleBodyMethod = getClass().getDeclaredMethod("aSimpleBody" ,new Class []{}); 75 Method aSeccondBodyMethod = getClass().getDeclaredMethod("aSeccondBody" ,new Class []{}); 76 77 fooBarRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,fooBarMethod ); 78 niceFooBarRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,niceFooBarMethod ); 79 badFooBarRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,badFooBarMethod ); 80 aSimpleMethodBodyRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,aSimpleMethodBodyMethod); 81 aSimpleBodyRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,aSimpleBodyMethod ); 82 aSeccondBodyRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,aSeccondBodyMethod ); 83 } 84 85 protected 86 void tearDown() 87 { 88 try 89 { ProseSystem.teardown(); } 90 catch (Exception e) 91 { Assert.fail("ProseSystem.teardown() failed"); } 92 } 93 94 95 public void testMethodsNamed() 96 { 97 PointCutter simpleMethods = (Within.method("aSimple.*")); 98 assertTrue(simpleMethods.isSpecialRequest(aSimpleBodyRequest)); 99 assertTrue(!simpleMethods.isSpecialRequest(fooBarRequest)); 100 PointCutter bodyMethods = (Within.method(".*Body.*")); 101 assertTrue(bodyMethods.isSpecialRequest(aSimpleMethodBodyRequest)); 102 assertTrue(!bodyMethods.isSpecialRequest(fooBarRequest)); 103 PointFilter simpleBodySpec = (simpleMethods).AND(bodyMethods); 104 assertTrue(simpleBodySpec.isSpecialRequest(aSimpleBodyRequest)); 105 assertTrue(!simpleBodySpec.isSpecialRequest(aSeccondBodyRequest)); 106 assertTrue(simpleBodySpec.isSpecialRequest(aSimpleMethodBodyRequest)); 107 } 108 109 public void testMethodDefined() 110 { 111 PointCutter synchMethos = (Within.method(Modifier.SYNCHRONIZED)); 112 assertTrue("a simple Body is synchronized", synchMethos.isSpecialRequest(aSimpleBodyRequest)); 113 assertTrue("a seccond body is not synchronized",!synchMethos.isSpecialRequest(aSeccondBodyRequest)); 114 115 PointFilter protOrPubMethods = 116 (Within.method(Modifier.PROTECTED)) .OR 117 (Within.method(Modifier.PUBLIC)); 118 assertTrue("niceFooBar is pro or pub", protOrPubMethods.isSpecialRequest(niceFooBarRequest)); 119 assertTrue("niceFooBar is pro or pub", protOrPubMethods.isSpecialRequest(badFooBarRequest)); 120 assertTrue("niceFooBar is pro or pub", protOrPubMethods.isSpecialRequest(aSimpleMethodBodyRequest)); 121 } 122 123 public void testMethodBefore() 124 { 125 PointCutter beforeM = Executions.before(); 126 assertTrue("all requests are ok",beforeM.isSpecialRequest(aSeccondBodyRequest)); 127 } 128 129 133 public static 134 Test suite() 135 { 136 return new TestSuite(MethodSTest.class); 137 } 138 } 139 140 141 | Popular Tags |