KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ldap > server > interceptor > ConfigurationTest


1 package org.apache.ldap.server.interceptor;
2
3
4 import junit.framework.Assert;
5 import org.apache.ldap.server.AbstractCoreTest;
6 import org.apache.ldap.server.invocation.Invocation;
7 import org.apache.ldap.server.jndi.EnvKeys;
8
9 import javax.naming.NamingException JavaDoc;
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13
14 /**
15  * Test case for interceptor configurations.
16  *
17  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
18  * @version $Rev: 169198 $, $Date: 2005-05-08 20:05:59 -0400 (Sun, 08 May 2005) $
19  */

20 public class ConfigurationTest extends AbstractCoreTest
21 {
22
23     private TestInterceptorChain rootChain = new TestInterceptorChain();
24
25     private TestInterceptorChain childChain = new TestInterceptorChain();
26
27     private TestInterceptor interceptorA = new TestInterceptor();
28
29     private TestInterceptor interceptorB = new TestInterceptor();
30
31
32     protected void setUp() throws Exception JavaDoc
33     {
34         rootChain.addLast( "A", interceptorA );
35
36         rootChain.addLast( "child", childChain );
37
38         childChain.addBefore( InterceptorChain.NEXT_INTERCEPTOR, "B", interceptorB );
39
40         rootChain.addLast( "default", InterceptorChain.newDefaultChain() );
41
42         extras.put( EnvKeys.INTERCEPTORS, rootChain );
43
44         extras.put( EnvKeys.INTERCEPTORS + "#root", "1" );
45
46         extras.put( EnvKeys.INTERCEPTORS + ".A", "2" );
47
48         extras.put( EnvKeys.INTERCEPTORS + ".A#A", "3" );
49
50         extras.put( EnvKeys.INTERCEPTORS + ".A#A.A", "4" );
51
52         extras.put( EnvKeys.INTERCEPTORS + ".child#child", "5" );
53
54         extras.put( EnvKeys.INTERCEPTORS + ".child.B", "6" );
55
56         extras.put( EnvKeys.INTERCEPTORS + ".child.B#B", "7" );
57
58         extras.put( EnvKeys.INTERCEPTORS + ".child.B#B.B", "8" );
59
60         super.setUp();
61     }
62
63
64     public void testRootChain() throws Exception JavaDoc
65     {
66         Map JavaDoc expected = new HashMap JavaDoc();
67
68         expected.put( "root", "1" );
69
70         expected.put( "A#A", "3" );
71
72         expected.put( "A#A.A", "4" );
73
74         expected.put( "child#child", "5" );
75
76         expected.put( "child.B#B", "7" );
77
78         expected.put( "child.B#B.B", "8" );
79
80         Assert.assertEquals( expected, rootChain.config );
81     }
82
83
84     public void testChildChain() throws Exception JavaDoc
85     {
86         Map JavaDoc expected = new HashMap JavaDoc();
87
88         expected.put( "child", "5" );
89
90         expected.put( "B#B", "7" );
91
92         expected.put( "B#B.B", "8" );
93
94         Assert.assertEquals( expected, childChain.config );
95     }
96
97
98     public void testA() throws Exception JavaDoc
99     {
100         Map JavaDoc expected = new HashMap JavaDoc();
101
102         expected.put( "A", "3" );
103
104         expected.put( "A.A", "4" );
105
106         Assert.assertEquals( expected, interceptorA.config );
107     }
108
109
110     public void testB() throws Exception JavaDoc
111     {
112         Map JavaDoc expected = new HashMap JavaDoc();
113
114         expected.put( "B", "7" );
115
116         expected.put( "B.B", "8" );
117
118         Assert.assertEquals( expected, interceptorB.config );
119     }
120
121
122     private static class TestInterceptorChain extends InterceptorChain
123     {
124         private Map JavaDoc config;
125
126
127         public synchronized void init( InterceptorContext ctx ) throws NamingException JavaDoc
128         {
129             config = ctx.getConfig();
130
131             super.init( ctx );
132         }
133
134     }
135
136     private static class TestInterceptor implements Interceptor
137     {
138         private Map JavaDoc config;
139
140
141         public void init( InterceptorContext context ) throws NamingException JavaDoc
142         {
143             config = context.getConfig();
144         }
145
146
147         public void destroy()
148         {
149         }
150
151
152         public void process( NextInterceptor nextInterceptor, Invocation invocation ) throws NamingException JavaDoc
153         {
154             nextInterceptor.process( invocation );
155         }
156     }
157
158 }
159
Popular Tags