Search in sources :

Example 6 with AttributeMetaData

use of jp.ossc.nimbus.core.AttributeMetaData in project nimbus by nimbus-org.

the class MethodMappingInterceptorServiceTest method test4.

public void test4() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    ServiceMetaData serviceData = new ServiceMetaData();
    serviceData.setCode(MethodMappingInterceptorService.class.getName());
    serviceData.setName("MethodMappingInterceptor");
    AttributeMetaData attr = new AttributeMetaData(serviceData);
    attr.setName("TargetMethodReturnMapping");
    attr.setValue("java.util.HashMap#get(java.lang.Object)=A\n" + "java.util.HashMap#put(java.lang.Object, java.lang.Object)=B");
    serviceData.addAttribute(attr);
    attr = new AttributeMetaData(serviceData);
    attr.setName("ContextServiceName");
    attr.setValue("#Context");
    serviceData.addAttribute(attr);
    ServiceManagerFactory.registerService("Test", serviceData);
    Interceptor interceptor1 = (Interceptor) ServiceManagerFactory.getServiceObject("Test", "MethodMappingInterceptor");
    Context context = new DefaultContextService();
    ServiceManagerFactory.registerService("Test", "Context", context);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        ServiceManagerFactory.findManager("Test").startAllService();
        context.put("A", new Integer(100));
        context.put("B", new Integer(200));
        assertEquals(new Integer(100), new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("get", new Class[] { Object.class }), null)));
        assertEquals(new Integer(200), new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("put", new Class[] { Object.class, Object.class }), null)));
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) Context(jp.ossc.nimbus.service.context.Context) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) AttributeMetaData(jp.ossc.nimbus.core.AttributeMetaData) HashMap(java.util.HashMap) DefaultContextService(jp.ossc.nimbus.service.context.DefaultContextService) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 7 with AttributeMetaData

use of jp.ossc.nimbus.core.AttributeMetaData in project nimbus by nimbus-org.

the class MethodMappingInterceptorServiceTest method test1.

public void test1() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    ServiceMetaData serviceData = new ServiceMetaData();
    serviceData.setCode(MethodMappingInterceptorService.class.getName());
    serviceData.setName("MethodMappingInterceptor");
    AttributeMetaData attr = new AttributeMetaData(serviceData);
    attr.setName("TargetMethodMapping");
    attr.setValue("java.util.HashMap#get(java.lang.Object)=#Interceptor2\n" + "java.util.HashMap#put(java.lang.Object, java.lang.Object)=#Interceptor3");
    serviceData.addAttribute(attr);
    ServiceManagerFactory.registerService("Test", serviceData);
    Interceptor interceptor1 = (Interceptor) ServiceManagerFactory.getServiceObject("Test", "MethodMappingInterceptor");
    Interceptor interceptor2 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            return this;
        }
    };
    ServiceManagerFactory.registerService("Test", "Interceptor2", interceptor2);
    Interceptor interceptor3 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            return this;
        }
    };
    ServiceManagerFactory.registerService("Test", "Interceptor3", interceptor3);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        ServiceManagerFactory.findManager("Test").startAllService();
        assertEquals(interceptor2, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("get", new Class[] { Object.class }), null)));
        assertEquals(interceptor3, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("put", new Class[] { Object.class, Object.class }), 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) AttributeMetaData(jp.ossc.nimbus.core.AttributeMetaData) HashMap(java.util.HashMap) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Aggregations

AttributeMetaData (jp.ossc.nimbus.core.AttributeMetaData)7 HashMap (java.util.HashMap)6 DefaultInterceptorChain (jp.ossc.nimbus.service.aop.DefaultInterceptorChain)6 DefaultInterceptorChainList (jp.ossc.nimbus.service.aop.DefaultInterceptorChainList)6 DefaultMethodInvocationContext (jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext)6 InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)6 ServiceMetaData (jp.ossc.nimbus.core.ServiceMetaData)5 Interceptor (jp.ossc.nimbus.service.aop.Interceptor)5 InterceptorChain (jp.ossc.nimbus.service.aop.InterceptorChain)4 Context (jp.ossc.nimbus.service.context.Context)3 Map (java.util.Map)2 Invoker (jp.ossc.nimbus.service.aop.Invoker)2 MethodInvocationContext (jp.ossc.nimbus.service.aop.MethodInvocationContext)2 ArrayList (java.util.ArrayList)1 DefaultContextService (jp.ossc.nimbus.service.context.DefaultContextService)1 ThreadContextService (jp.ossc.nimbus.service.context.ThreadContextService)1 ThreadManagedJournalService (jp.ossc.nimbus.service.journal.ThreadManagedJournalService)1 MethodCallJournalData (jp.ossc.nimbus.service.journal.editor.MethodCallJournalData)1 MethodReturnJournalData (jp.ossc.nimbus.service.journal.editor.MethodReturnJournalData)1 MutableObjectJournalEditorService (jp.ossc.nimbus.service.journal.editor.MutableObjectJournalEditorService)1