| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.commons.tracing; |
| 34 | | | |
| 35 | | | |
| 36 | | | import org.objectweb.asm.Opcodes; |
| 37 | | | |
| 38 | | | import junit.framework.TestCase; |
| 39 | | | |
| 40 | 100 | (1) | public class AspectPatternTest extends TestCase |
| 41 | | | { |
| 42 | | | |
| 43 | | (2)(3) | public void testAspectPattern() |
| 44 | | | { |
| 45 | 100 | (4) | AspectPattern pat |
| 46 | | | = new AspectPattern("int foo.*.Bar.method()"); |
| 47 | 100 | | assertEquals("No modifier!", pat.getModifiers(), 0); |
| 48 | 100 | (5) | assertEquals("method\\(\\)I", pat.getMethodRegex()); |
| 49 | 100 | (6) | assertTrue(pat.matches(0, |
| 50 | | (7) | "foo/test/Bar", "method()I")); |
| 51 | 100 | (8) | assertFalse(pat.matches(0, |
| 52 | | | "foo/test/Bar", "method(I)I")); |
| 53 | 100 | | } |
| 54 | | | |
| 55 | | (9)(10) | public void testAspectPattern2() |
| 56 | | | { |
| 57 | 100 | (11) | AspectPattern pat |
| 58 | | | = new AspectPattern("int *.method(*)"); |
| 59 | 100 | | assertEquals("No modifier!", pat.getModifiers(), 0); |
| 60 | 100 | (12)(13) | assertEquals("method\\(\\[*([VZCBSIFJD]|L[^;]+;)\\)I", pat.getMethodRegex()); |
| 61 | 100 | (14) | assertEquals("[^/]*", pat.getClassRegex()); |
| 62 | 100 | (15) | assertTrue(pat.matches(0, |
| 63 | | (16) | "Foo", "method(I)I")); |
| 64 | 100 | (17) | assertTrue(pat.matches(0, |
| 65 | | | "Foo", "method([I)I")); |
| 66 | 100 | (18) | assertTrue(pat.matches(0, |
| 67 | | | "Foo", "method(Ljava/lang/String;)I")); |
| 68 | 100 | (19) | assertFalse(pat.matches(0, |
| 69 | | | "Foo", "method()I")); |
| 70 | 100 | (20) | assertFalse(pat.matches(0, |
| 71 | | | "pkg/Foo", "method(I)I")); |
| 72 | 100 | (21) | assertFalse(pat.matches(0, |
| 73 | | (22) | "pkg/Foo", "method(II)I")); |
| 74 | 100 | (23) | assertFalse(pat.matches(0, |
| 75 | | | "Foo", "method()I")); |
| 76 | 100 | (24) | assertFalse(pat.matches(0, |
| 77 | | | "Foo", "method(I)V")); |
| 78 | 100 | | } |
| 79 | | | |
| 80 | | (25)(26) | public void testAspectPattern3() |
| 81 | | | { |
| 82 | 100 | (27) | AspectPattern pat |
| 83 | | | = new AspectPattern("int foo.*.*.method(*,int)"); |
| 84 | 100 | | assertEquals("No modifier!", pat.getModifiers(), 0); |
| 85 | | (28) | |
| 86 | | | |
| 87 | 100 | (29) | assertTrue(pat.matches(0, |
| 88 | | (30) | "foo/foo/Foo", "method(JI)I")); |
| 89 | 100 | (31) | assertTrue(pat.matches(0, |
| 90 | | | "foo/test/Bar", "method(Ljava/lang/String;I)I")); |
| 91 | 100 | (32) | assertTrue(pat.matches(0, |
| 92 | | | "foo/test/Bar", "method(II)I")); |
| 93 | 100 | (33) | assertFalse(pat.matches(0, |
| 94 | | | "foo/Bar", "method(II)I")); |
| 95 | 100 | (34) | assertFalse(pat.matches(0, |
| 96 | | | "foo/test/Bar", "method(IJ)I")); |
| 97 | 100 | (35) | assertFalse(pat.matches(0, |
| 98 | | | "foo/test/Bar", "method(II)V")); |
| 99 | 100 | (36) | assertFalse(pat.matches(0, |
| 100 | | | "test/test/Bar", "method(II)I")); |
| 101 | 100 | | } |
| 102 | | | |
| 103 | | (37)(38) | public void testAspectPattern4() |
| 104 | | | { |
| 105 | 100 | (39) | AspectPattern pat |
| 106 | | | = new AspectPattern("public * org.jcoderz..*.*(..)"); |
| 107 | 100 | | assertTrue("Pattern should match class!" + pat, |
| 108 | | | pat.matchClass("org/jcoderz/tracing/Test")); |
| 109 | 100 | | assertTrue("Pattern should match method!" + pat, |
| 110 | | | pat.matchMethod("method(JI)I")); |
| 111 | 100 | | assertTrue("Pattern should match!" + pat, pat.matches(1, |
| 112 | | | "org/jcoderz/tracing/Test", "method(JI)I")); |
| 113 | 100 | | } |
| 114 | | | |
| 115 | | (40)(41) | public void testAspectPattern5() |
| 116 | | | { |
| 117 | 100 | (42) | AspectPattern pat |
| 118 | | | = new AspectPattern("public * org.jcoderz.tracing.logging.test.*.*(..)"); |
| 119 | 100 | | assertTrue("Pattern should match class!" + pat, |
| 120 | | | pat.matchClass("org/jcoderz/tracing/logging/test/Test")); |
| 121 | 100 | | assertTrue("Pattern should match method!" + pat, |
| 122 | | | pat.matchMethod("method(JI)I")); |
| 123 | 100 | | assertTrue("Pattern should match!" + pat, pat.matches(1, |
| 124 | | | "org/jcoderz/tracing/logging/test/Test", "method(JI)I")); |
| 125 | 100 | | } |
| 126 | | | |
| 127 | | (43)(44) | public void testAspectPattern6() |
| 128 | | | { |
| 129 | 100 | (45) | AspectPattern pat |
| 130 | | | = new AspectPattern("* *.set*(..)"); |
| 131 | 100 | | assertTrue("Pattern should match class!" + pat, |
| 132 | | | pat.matchClass("Test")); |
| 133 | 100 | | assertTrue("Pattern should match method!" + pat, |
| 134 | | | pat.matchMethod("setMethod(JI)I")); |
| 135 | 100 | | assertFalse("Pattern should not match class!" + pat, |
| 136 | | | pat.matchClass("com/Test")); |
| 137 | 100 | | } |
| 138 | | | |
| 139 | | (46)(47) | public void testAspectPattern7() |
| 140 | | | { |
| 141 | 100 | (48) | AspectPattern pat |
| 142 | | | = new AspectPattern("public void Account.set*(*)"); |
| 143 | 100 | (49) | assertTrue("Pattern should match class! " + pat, |
| 144 | | | pat.matchClass("Account")); |
| 145 | 100 | (50) | assertTrue("Pattern should match method! " + pat, |
| 146 | | | pat.matchMethod("setMethod(I)V")); |
| 147 | 100 | | assertTrue("Pattern should match method! " + pat, |
| 148 | | | pat.matchAccess(Opcodes.ACC_PUBLIC)); |
| 149 | 100 | | assertFalse("Pattern should not access level! " + pat, |
| 150 | | | pat.matchAccess(Opcodes.ACC_PRIVATE)); |
| 151 | 100 | | assertFalse("Pattern should not match method! " + pat, |
| 152 | | | pat.matchMethod("getMethod(I)V")); |
| 153 | 100 | | assertFalse("Pattern should not match class! " + pat, |
| 154 | | | pat.matchClass("com.Account")); |
| 155 | 100 | | } |
| 156 | | | |
| 157 | | (51)(52) | public void testAspectPattern8() |
| 158 | | | { |
| 159 | 100 | (53) | AspectPattern pat |
| 160 | | | = new AspectPattern("public static void ...main(String[])"); |
| 161 | 100 | | assertTrue("Pattern should match class! " + pat, |
| 162 | | | pat.matchClass("Account")); |
| 163 | 100 | | assertTrue("Pattern should match class! " + pat, |
| 164 | | | pat.matchClass("com/Account")); |
| 165 | 100 | | assertTrue("Pattern should match method! " + pat, |
| 166 | | | pat.matchMethod("main([Ljava/lang/String;)V")); |
| 167 | 100 | | assertTrue("Pattern should match access level! " + pat, |
| 168 | | | pat.matchAccess(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC)); |
| 169 | 100 | | assertFalse("Pattern should not match access level! " + pat, |
| 170 | | | pat.matchAccess(Opcodes.ACC_STATIC)); |
| 171 | 100 | | assertFalse("Pattern should not access level! " + pat, |
| 172 | | | pat.matchAccess(Opcodes.ACC_PRIVATE)); |
| 173 | 100 | | assertFalse("Pattern should not match method! " + pat, |
| 174 | | | pat.matchMethod("getMethod(I)V")); |
| 175 | 100 | | } |
| 176 | | | |
| 177 | | (54)(55) | public void testAspectPattern9() |
| 178 | | | { |
| 179 | 100 | (56) | AspectPattern pat |
| 180 | | (57) | = new AspectPattern("public static * org.jcoderz.tracing.db.DaoUtil.*(..)"); |
| 181 | 100 | | assertTrue("Pattern should match class! " + pat, |
| 182 | | | pat.matchClass("org/jcoderz/tracing/db/DaoUtil")); |
| 183 | 100 | | assertTrue("Pattern should match method! " + pat + " '" |
| 184 | | | + pat.getMethodPattern() + "'", |
| 185 | | | pat.matchMethod("create(Ljava/lang/Object;)Ljava/lang/Object;")); |
| 186 | 100 | | assertTrue("Pattern should match access level! " + pat, |
| 187 | | | pat.matchAccess(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC)); |
| 188 | 100 | | assertFalse("Pattern should not match access level! " + pat, |
| 189 | | | pat.matchAccess(Opcodes.ACC_STATIC)); |
| 190 | 100 | | assertFalse("Pattern should not access level! " + pat, |
| 191 | | | pat.matchAccess(Opcodes.ACC_PRIVATE)); |
| 192 | 100 | | } |
| 193 | | | } |