Search in sources :

Example 36 with DefaultInterceptorChain

use of jp.ossc.nimbus.service.aop.DefaultInterceptorChain in project nimbus by nimbus-org.

the class MockInterceptorServiceTest method test4.

public void test4() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    MockInterceptorService interceptor = new MockInterceptorService();
    ServiceManagerFactory.registerService("Test", "MockInterceptor", interceptor);
    final Method targetMethod = String.class.getMethod("toString", (Class[]) null);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor.setMock("Mock");
        ServiceManagerFactory.findManager("Test").startAllService();
        final InterceptorChain chain = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new MethodReflectionCallInvokerService());
        assertEquals("Mock", chain.invokeNext(new DefaultMethodInvocationContext("Real", targetMethod, null)));
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Method(java.lang.reflect.Method) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) MethodReflectionCallInvokerService(jp.ossc.nimbus.service.aop.invoker.MethodReflectionCallInvokerService) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 37 with DefaultInterceptorChain

use of jp.ossc.nimbus.service.aop.DefaultInterceptorChain in project nimbus by nimbus-org.

the class MockInterceptorServiceTest method test3.

public void test3() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    MockInterceptorService interceptor = new MockInterceptorService();
    ServiceManagerFactory.registerService("Test", "MockInterceptor", interceptor);
    final Method targetMethod = String.class.getMethod("toString", (Class[]) null);
    ServiceManagerFactory.registerService("Test", "Mock", "Mock");
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor.setMockServiceName(new ServiceName("Test", "Mock"));
        ServiceManagerFactory.findManager("Test").startAllService();
        final InterceptorChain chain = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new MethodReflectionCallInvokerService());
        assertEquals("Mock", chain.invokeNext(new DefaultMethodInvocationContext("Real", targetMethod, null)));
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) ServiceName(jp.ossc.nimbus.core.ServiceName) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Method(java.lang.reflect.Method) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) MethodReflectionCallInvokerService(jp.ossc.nimbus.service.aop.invoker.MethodReflectionCallInvokerService) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 38 with DefaultInterceptorChain

use of jp.ossc.nimbus.service.aop.DefaultInterceptorChain in project nimbus by nimbus-org.

the class NullReturnInterceptorServiceTest method test1.

public void test1() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    NullReturnInterceptorService interceptor = new NullReturnInterceptorService();
    ServiceManagerFactory.registerService("Test", "NullReturnInterceptor", interceptor);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        ServiceManagerFactory.findManager("Test").startAllService();
        final InterceptorChain chain = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {

            public Object invoke(InvocationContext context) throws Throwable {
                return "test";
            }
        });
        assertNull(chain.invokeNext(new DefaultInvocationContext(null)));
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) DefaultInvocationContext(jp.ossc.nimbus.service.aop.DefaultInvocationContext) Invoker(jp.ossc.nimbus.service.aop.Invoker) DefaultInvocationContext(jp.ossc.nimbus.service.aop.DefaultInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 39 with DefaultInterceptorChain

use of jp.ossc.nimbus.service.aop.DefaultInterceptorChain in project nimbus by nimbus-org.

the class ContextImportInterceptorServiceTest method test2.

public void test2() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    DefaultContextService contextService = new DefaultContextService();
    ServiceManagerFactory.registerService("Test", "Context", contextService);
    Interceptor interceptor1 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            Map importContext = new HashMap();
            importContext.put("A", "100");
            importContext.put("B", "200");
            context.setAttribute("Context", importContext);
            return chain.invokeNext(context);
        }
    };
    ContextImportInterceptorService interceptor2 = new ContextImportInterceptorService();
    ServiceManagerFactory.registerService("Test", "ContextImportInterceptor", interceptor2);
    Interceptor interceptor3 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            Context ctx = (Context) ServiceManagerFactory.getServiceObject("Test", "Context");
            assertEquals(2, ctx.size());
            assertEquals("100", ctx.get("A"));
            assertEquals("200", ctx.get("B"));
            return chain.invokeNext(context);
        }
    };
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor2.setContext(contextService);
        interceptor2.setAttributeName("Context");
        interceptor2.setContextKeys(new String[] { "A", "B" });
        ServiceManagerFactory.findManager("Test").startAllService();
        new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2, interceptor3 }), null).invokeNext(new DefaultInvocationContext());
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInvocationContext(jp.ossc.nimbus.service.aop.DefaultInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) Context(jp.ossc.nimbus.service.context.Context) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) DefaultInvocationContext(jp.ossc.nimbus.service.aop.DefaultInvocationContext) HashMap(java.util.HashMap) DefaultContextService(jp.ossc.nimbus.service.context.DefaultContextService) DefaultInvocationContext(jp.ossc.nimbus.service.aop.DefaultInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) HashMap(java.util.HashMap) Map(java.util.Map) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 40 with DefaultInterceptorChain

use of jp.ossc.nimbus.service.aop.DefaultInterceptorChain in project nimbus by nimbus-org.

the class ContextImportInterceptorServiceTest method test1.

public void test1() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    ServiceManagerFactory.registerService("Test", "Context", new DefaultContextService());
    Interceptor interceptor1 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            Map importContext = new HashMap();
            importContext.put("A", "100");
            importContext.put("B", "200");
            context.setAttribute(ContextImportInterceptorService.DEFAULT_ATTRIBUTE_NAME, importContext);
            return chain.invokeNext(context);
        }
    };
    ContextImportInterceptorService interceptor2 = new ContextImportInterceptorService();
    ServiceManagerFactory.registerService("Test", "ContextImportInterceptor", interceptor2);
    Interceptor interceptor3 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            Context ctx = (Context) ServiceManagerFactory.getServiceObject("Test", "Context");
            assertEquals(2, ctx.size());
            assertEquals("100", ctx.get("A"));
            assertEquals("200", ctx.get("B"));
            return chain.invokeNext(context);
        }
    };
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor2.setContextServiceName(new ServiceName("Test", "Context"));
        ServiceManagerFactory.findManager("Test").startAllService();
        new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2, interceptor3 }), null).invokeNext(new DefaultInvocationContext());
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInvocationContext(jp.ossc.nimbus.service.aop.DefaultInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) Context(jp.ossc.nimbus.service.context.Context) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) DefaultInvocationContext(jp.ossc.nimbus.service.aop.DefaultInvocationContext) HashMap(java.util.HashMap) ServiceName(jp.ossc.nimbus.core.ServiceName) DefaultContextService(jp.ossc.nimbus.service.context.DefaultContextService) DefaultInvocationContext(jp.ossc.nimbus.service.aop.DefaultInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) HashMap(java.util.HashMap) Map(java.util.Map) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Aggregations

DefaultInterceptorChain (jp.ossc.nimbus.service.aop.DefaultInterceptorChain)47 DefaultInterceptorChainList (jp.ossc.nimbus.service.aop.DefaultInterceptorChainList)45 InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)43 DefaultMethodInvocationContext (jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext)40 Interceptor (jp.ossc.nimbus.service.aop.Interceptor)34 Invoker (jp.ossc.nimbus.service.aop.Invoker)33 InterceptorChain (jp.ossc.nimbus.service.aop.InterceptorChain)28 HashMap (java.util.HashMap)20 Map (java.util.Map)10 Context (jp.ossc.nimbus.service.context.Context)9 Properties (java.util.Properties)6 Random (java.util.Random)6 AttributeMetaData (jp.ossc.nimbus.core.AttributeMetaData)6 ServiceName (jp.ossc.nimbus.core.ServiceName)6 MethodInvocationContext (jp.ossc.nimbus.service.aop.MethodInvocationContext)6 Method (java.lang.reflect.Method)5 ServiceMetaData (jp.ossc.nimbus.core.ServiceMetaData)5 DefaultInvocationContext (jp.ossc.nimbus.service.aop.DefaultInvocationContext)5 DefaultContextService (jp.ossc.nimbus.service.context.DefaultContextService)5 MethodReflectionCallInvokerService (jp.ossc.nimbus.service.aop.invoker.MethodReflectionCallInvokerService)4