1 7 package ch.ethz.prose.filter; 8 9 import java.lang.reflect.Method ; 11 import java.util.Collection ; 12 import java.util.Vector ; 13 14 import junit.framework.*; 15 import ch.ethz.jvmai.MethodEntryJoinPoint; 16 import ch.ethz.prose.ProseSystem; 17 import ch.ethz.prose.engine.JoinPointManager; 18 import ch.ethz.prose.engine.MethodEntryRequest; 19 20 26 public 27 class DeclarationSTest extends TestCase { 28 29 static class FooBar 34 {static void fooBar(){}} 35 static public class NiceFooBar 36 { public void niceFooBar(){}} 37 static class BadFooBar 38 {void badFooBar(){}} 39 static public class ASimpleMethodBody 40 {public synchronized void aSimpleMethodBody(){}} 41 static final class ASimpleBody 42 { synchronized final void aSimpleBody(){}} 43 static class ASeccondBody extends Vector  44 { void aSeccondBody(){} } 45 46 47 MethodEntryRequest fooBarRequest; 49 MethodEntryRequest niceFooBarRequest; 50 MethodEntryRequest badFooBarRequest; 51 MethodEntryRequest aSimpleMethodBodyRequest; 52 MethodEntryRequest aSimpleBodyRequest; 53 MethodEntryRequest aSeccondBodyRequest; 54 55 57 58 62 public DeclarationSTest(String name) 63 { 64 super(name); 65 } 66 67 70 protected 71 void setUp() throws Exception  72 { 73 ProseSystem.startup(); 74 75 JoinPointManager jpm= ProseSystem.getAspectManager().getJoinPointManager(); 76 77 Method fooBarMethod = FooBar.class.getDeclaredMethod("fooBar",new Class []{}); 78 Method niceFooBarMethod = NiceFooBar.class.getDeclaredMethod("niceFooBar",new Class []{}); 79 Method badFooBarMethod = BadFooBar.class.getDeclaredMethod("badFooBar",new Class []{}); 80 Method aSimpleMethodBodyMethod = ASimpleMethodBody.class.getDeclaredMethod("aSimpleMethodBody",new Class []{}); 81 Method aSimpleBodyMethod = ASimpleBody.class.getDeclaredMethod("aSimpleBody",new Class []{}); 82 Method aSeccondBodyMethod = ASeccondBody.class.getDeclaredMethod("aSeccondBody",new Class []{}); 83 84 fooBarRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,fooBarMethod ); 85 niceFooBarRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,niceFooBarMethod ); 86 badFooBarRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,badFooBarMethod ); 87 aSimpleMethodBodyRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,aSimpleMethodBodyMethod); 88 aSimpleBodyRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,aSimpleBodyMethod ); 89 aSeccondBodyRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,aSeccondBodyMethod ); 90 91 } 92 93 94 protected 95 void tearDown() 96 { 97 try 98 { ProseSystem.teardown(); } 99 catch (Exception e) 100 { Assert.fail("ProseSystem.teardown() failed"); } 101 } 102 103 104 public void testExecutionSNamed() 105 { 106 PointCutter simpleClasses = (Within.type(".*ASimple.*")); 107 assertTrue("1",simpleClasses.isSpecialRequest(aSimpleBodyRequest)); 108 assertTrue("2",!simpleClasses.isSpecialRequest(fooBarRequest)); 109 PointCutter bodyClasses = (Within.type(".*Body.*")); 110 assertTrue("3",bodyClasses.isSpecialRequest(aSimpleMethodBodyRequest)); 111 assertTrue("4",!bodyClasses.isSpecialRequest(fooBarRequest)); 112 PointCutter simpleBodySpec = (simpleClasses).AND(bodyClasses); 113 assertTrue("5",simpleBodySpec.isSpecialRequest(aSimpleBodyRequest)); 114 assertTrue("6",!simpleBodySpec.isSpecialRequest(aSeccondBodyRequest)); 115 assertTrue("7",simpleBodySpec.isSpecialRequest(aSimpleMethodBodyRequest)); 116 } 117 118 public void testExecutionSUSER_AND_SYSTEM() 119 { 120 assertTrue(Within.userCode().isSpecialRequest(aSimpleBodyRequest)); 121 } 122 123 public void testExecutionSExtending() 124 { 125 PointCutter collectionClasses = Within.subType(Collection .class); 126 assertTrue(collectionClasses.isSpecialRequest(aSeccondBodyRequest)); 127 assertTrue(!collectionClasses.isSpecialRequest(aSimpleBodyRequest)); 128 } 129 130 public void testExecutionSameType() throws Throwable  131 { 132 PointCutter myCollectionClasses = Within.type(ASeccondBody.class); 133 } 134 135 public void testExecutionSinpackage() 136 { 137 PointCutter inthisPackageClasses = Within.packageTypes("ch.ethz.prose.*"); 138 assertTrue(inthisPackageClasses.isSpecialRequest(aSeccondBodyRequest)); 139 PointCutter inJavaLangClasses = Within.packageTypes("java.lang.*"); 140 assertTrue(!inJavaLangClasses.isSpecialRequest(aSeccondBodyRequest)); 141 } 142 143 147 public static 148 Test suite() 149 { 150 return new TestSuite(DeclarationSTest.class); 151 } 152 153 } 154 155 156 | Popular Tags |