KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > impl > TestInterceptors


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.impl;
16
17 import hivemind.test.FrameworkTestCase;
18
19 import java.util.List JavaDoc;
20 import java.util.Locale JavaDoc;
21
22 import org.apache.hivemind.Location;
23 import org.apache.hivemind.definition.ModuleDefinition;
24 import org.apache.hivemind.definition.InterceptorDefinition;
25 import org.apache.hivemind.definition.Visibility;
26 import org.apache.hivemind.definition.impl.OrderedInterceptorDefinitionImpl;
27 import org.apache.hivemind.definition.impl.ServicePointDefinitionImpl;
28 import org.apache.hivemind.internal.Module;
29
30 /**
31  * Test for interceptors.
32  *
33  * @author Howard M. Lewis Ship
34  * @since 1.1
35  */

36 public class TestInterceptors extends FrameworkTestCase
37 {
38     private Module newModule()
39     {
40         ModuleImpl result = new ModuleImpl();
41
42         result.setClassResolver(getClassResolver());
43         result.setPackageName("");
44         result.setRegistry(new RegistryInfrastructureImpl(new StrictErrorHandler(), Locale
45                 .getDefault()));
46         return result;
47     }
48
49     private ServicePointImpl newServicePoint(ModuleDefinition moduleDefinition, Location l, Module module)
50     {
51         ServicePointDefinitionImpl definition = new ServicePointDefinitionImpl(moduleDefinition, "zip.zap", l, Visibility.PUBLIC, "foo.bar.Baz");
52         ServicePointImpl sp = new ServicePointImpl(module, definition);
53         return sp;
54     }
55    
56     public void testDefaultInterceptorOrdering()
57     {
58         Location l = newLocation();
59         Module module = newModule();
60
61         replayControls();
62
63         ModuleDefinition moduleDef = createModuleDefinition("module");
64         ServicePointImpl sp = newServicePoint(moduleDef, l, module);
65         
66         InterceptorDefinition interceptor1 = new OrderedInterceptorDefinitionImpl(moduleDef, "Interceptor1", null, null,
67                 null, null);
68         sp.getServicePointDefinition().addInterceptor(interceptor1);
69         InterceptorDefinition interceptor2 = new OrderedInterceptorDefinitionImpl(moduleDef, "Interceptor2", null, null,
70                 null, null);
71         sp.getServicePointDefinition().addInterceptor(interceptor2);
72 // sp.getServicePointDefinition()setExtensionPointId("ExtensionPointId");
73
final List JavaDoc ordered = sp.getOrderedInterceptorContributions();
74         assertNotNull(ordered);
75         assertEquals(2, ordered.size());
76         assertEquals(interceptor1, ordered.get(0));
77         assertEquals(interceptor2, ordered.get(1));
78         verifyControls();
79     }
80
81     public void testCustomInterceptorOrdering()
82     {
83         Location l = newLocation();
84         Module module = newModule();
85
86         replayControls();
87
88         ModuleDefinition moduleDef = createModuleDefinition("module");
89         ServicePointImpl sp = newServicePoint(moduleDef, l, module);
90         
91         InterceptorDefinition interceptor1 = new OrderedInterceptorDefinitionImpl(moduleDef, "Interceptor1", null, null,
92                 null, null);
93         sp.getServicePointDefinition().addInterceptor(interceptor1);
94         InterceptorDefinition interceptor2 = new OrderedInterceptorDefinitionImpl(moduleDef, "Interceptor2", null, null,
95                 null, "Interceptor1");
96         sp.getServicePointDefinition().addInterceptor(interceptor2);
97         final List JavaDoc ordered = sp.getOrderedInterceptorContributions();
98         assertNotNull(ordered);
99         assertEquals(2, ordered.size());
100         assertEquals(interceptor2, ordered.get(0));
101         assertEquals(interceptor1, ordered.get(1));
102         verifyControls();
103     }
104 }
Popular Tags