KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tirsen > nanning > AspectRepositoryTest


1 /*
2  * Nanning Aspects
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package com.tirsen.nanning;
8
9 import com.tirsen.nanning.definition.*;
10 import junit.framework.TestCase;
11
12 /**
13  * TODO document AspectRepositoryTest
14  *
15  * <!-- $Id: AspectRepositoryTest.java,v 1.10 2003/05/11 13:40:52 tirsen Exp $ -->
16  *
17  * @author $Author: tirsen $
18  * @version $Revision: 1.10 $
19  */

20 public class AspectRepositoryTest extends TestCase {
21     public void testEmpty() {
22         AspectFactory aspectRepository = new AspectRepository();
23
24         try {
25             aspectRepository.newInstance(Intf.class);
26             ///CLOVER:OFF
27
fail("could instantiate aspect before it was configured");
28             ///CLOVER:ON
29
} catch (IllegalArgumentException JavaDoc shouldHappen) {
30         }
31     }
32
33     public void testConfig() throws InstantiationException JavaDoc, IllegalAccessException JavaDoc {
34         AspectRepository aspectRepository = new AspectRepository();
35
36         // the braces are here to isolate the lexical spaces to ensure that the lexical space is in the repository
37
{
38             InterceptorDefinition interceptorDefinition = new InterceptorDefinition(MockInterceptor.class);
39             aspectRepository.defineInterceptor(interceptorDefinition);
40
41             assertSame(interceptorDefinition, aspectRepository.getInterceptor(MockInterceptor.class));
42         }
43
44         {
45             InterceptorDefinition interceptorDefinition = new InterceptorDefinition(NullInterceptor.class);
46             aspectRepository.defineInterceptor(interceptorDefinition);
47
48             assertSame(interceptorDefinition, aspectRepository.getInterceptor(NullInterceptor.class));
49         }
50
51         {
52             AspectDefinition aspectDefinition = new AspectDefinition();
53             aspectDefinition.setInterface(TestMixin.class);
54             aspectDefinition.addInterceptor(aspectRepository.getInterceptor(MockInterceptor.class));
55             aspectDefinition.addInterceptor(aspectRepository.getInterceptor(NullInterceptor.class));
56             aspectDefinition.setTarget(TestMixinImpl.class);
57             aspectRepository.defineAspect(aspectDefinition);
58
59             assertSame(aspectDefinition, aspectRepository.getAspect(TestMixin.class));
60         }
61
62         {
63             AspectClass aspectClass = new AspectClass();
64             aspectClass.setInterface(Intf.class);
65             aspectClass.addInterceptor(aspectRepository.getInterceptor(MockInterceptor.class));
66             aspectClass.addInterceptor(aspectRepository.getInterceptor(NullInterceptor.class));
67             aspectClass.setTarget(IntfImpl.class);
68             aspectClass.addAspect(aspectRepository.getAspect(TestMixin.class));
69             aspectRepository.defineClass(aspectClass);
70
71             assertSame(aspectClass, aspectRepository.getClass(Intf.class));
72         }
73
74         Intf intf = (Intf) aspectRepository.newInstance(Intf.class);
75         intf.call();
76     }
77
78     public void testConfigure() throws NoSuchMethodException JavaDoc, ConfigureException {
79         AspectRepository aspectRepository = new AspectRepository();
80         java.net.URL JavaDoc resource = AspectRepositoryTest.class.getResource("aspect-repository-test.xml");
81         aspectRepository.configure(resource);
82
83         // AspectRepository aspectRepository = AspectRepository.getInstance();
84
Object JavaDoc bigMomma = aspectRepository.newInstance(Intf.class);
85         AspectClassTest.verifySideAspect(bigMomma);
86     }
87 }
88
Popular Tags