KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tirsen > nanning > xml > AspectSystemParserTest


1 package com.tirsen.nanning.xml;
2
3 import com.tirsen.nanning.*;
4 import com.tirsen.nanning.config.*;
5 import junit.framework.TestCase;
6
7 import java.io.IOException JavaDoc;
8
9 public class AspectSystemParserTest extends TestCase {
10     private AspectSystemParser aspectSystemParser;
11
12     protected void setUp() throws Exception JavaDoc {
13         super.setUp();
14
15         aspectSystemParser = new AspectSystemParser();
16     }
17
18     public static class TestAspect implements Aspect {
19         public void introduce(AspectInstance aspectInstance) {
20         }
21
22         public void advise(AspectInstance aspectInstance) {
23         }
24     }
25
26     public static class TestInterceptor implements MethodInterceptor {
27         public Object JavaDoc invoke(Invocation invocation) throws Throwable JavaDoc {
28             return null;
29         }
30     }
31
32     public void testParseAspect() throws IOException JavaDoc {
33         String JavaDoc xml = "<aspect-system><aspect class='" + TestAspect.class.getName() + "' /></aspect-system>";
34         AspectSystem aspectSystem = aspectSystemParser.parse(xml);
35
36         assertEquals(1, aspectSystem.getAspects().size());
37         assertTrue(aspectSystem.getAspects().get(0) instanceof TestAspect);
38     }
39
40     public void testParseInterceptor() throws IOException JavaDoc {
41         String JavaDoc xml = "<aspect-system><interceptor class=\"" + TestInterceptor.class.getName() + "\" /></aspect-system>";
42         AspectSystem aspectSystem = aspectSystemParser.parse(xml);
43
44         assertEquals(1, aspectSystem.getAspects().size());
45         assertTrue(aspectSystem.getAspects().get(0) instanceof InterceptorAspect);
46
47         InterceptorAspect interceptorAspect = (InterceptorAspect) aspectSystem.getAspects().get(0);
48         assertEquals(TestInterceptor.class, interceptorAspect.getInterceptorClass());
49         assertEquals(InterceptorAspect.PER_METHOD, interceptorAspect.getStateManagement());
50     }
51
52     public void testParsePointcut() throws IOException JavaDoc {
53         String JavaDoc xml = "<aspect-system><interceptor class='" + TestInterceptor.class.getName() + "'>" +
54                 "<pointcut attribute='attribute'></pointcut>" +
55                 "</interceptor></aspect-system>";
56         AspectSystem aspectSystem = aspectSystemParser.parse(xml);
57         InterceptorAspect interceptorAspect = (InterceptorAspect) aspectSystem.getAspects().get(0);
58         assertTrue(interceptorAspect.getPointcut() instanceof AttributePointcut);
59         AttributePointcut attributePointcut = (AttributePointcut) interceptorAspect.getPointcut();
60         assertEquals("attribute", attributePointcut.getAttribute());
61     }
62
63     public void testParseClass() throws IOException JavaDoc {
64         String JavaDoc xml = "<aspect-system><class name='" + Interface.class.getName() + "' /></aspect-system>";
65         AspectSystem aspectSystem = aspectSystemParser.parse(xml);
66         ClassAspect classAspect = (ClassAspect) aspectSystem.getAspects().get(0);
67         assertEquals(Interface.class, classAspect.getClassIdentifier());
68     }
69
70     public void testParseClassWithLocalAspect() throws IOException JavaDoc {
71         String JavaDoc xml = "<aspect-system><class name='" + Interface.class.getName() + "'>" +
72                 "<aspect class='" + TestAspect.class.getName() + "' /></class></aspect-system>";
73         AspectSystem aspectSystem = aspectSystemParser.parse(xml);
74         ClassAspect classAspect = (ClassAspect) aspectSystem.getAspects().get(0);
75         assertEquals(Interface.class, classAspect.getClassIdentifier());
76         assertEquals(1, classAspect.getAspects().size());
77         assertTrue(classAspect.getAspects().get(0) instanceof TestAspect);
78     }
79
80     public void testParseMixin() throws IOException JavaDoc {
81         String JavaDoc xml = "<aspect-system><mixin interface='" + Interface.class.getName() + "' " +
82                 "target='" + Target.class.getName() + "' /></aspect-system>";
83         AspectSystem aspectSystem = aspectSystemParser.parse(xml);
84         assertEquals(1, aspectSystem.getAspects().size());
85         Introductor introductor = (Introductor) aspectSystem.getAspects().get(0);
86         assertEquals(Interface.class, introductor.getInterfaceClass());
87         assertEquals(Target.class, introductor.getTargetClass());
88     }
89
90
91     public void testParseAspectSystem() throws IOException JavaDoc {
92         String JavaDoc xml = "<aspect-system />";
93
94         aspectSystemParser = new AspectSystemParser();
95         assertTrue(aspectSystemParser.parse(xml) instanceof AspectSystem);
96     }
97 }
98
Popular Tags