1 15 package org.apache.hivemind.impl; 16 17 import hivemind.test.FrameworkTestCase; 18 19 import java.util.List ; 20 import java.util.Locale ; 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 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 final List 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 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 |