use of jp.ossc.nimbus.service.aop.Interceptor in project nimbus by nimbus-org.
the class ExceptionConsumeInterceptorServiceTest method test4.
public void test4() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ExceptionConsumeInterceptorService interceptor1 = new ExceptionConsumeInterceptorService();
ServiceManagerFactory.registerService("Test", "ExceptionConsumeInterceptor", interceptor1);
Interceptor interceptor2 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
throw new RuntimeException();
}
};
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor1.setExceptionClassNames(new String[] { "java.lang.IllegalArgumentException", "java.lang.UnsupportedOperationException" });
ServiceManagerFactory.findManager("Test").startAllService();
try {
new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }), new Invoker() {
public Object invoke(InvocationContext context) throws Throwable {
return "test";
}
}).invokeNext(new DefaultMethodInvocationContext());
fail();
} catch (RuntimeException e) {
assertEquals(RuntimeException.class, e.getClass());
}
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.Interceptor in project nimbus by nimbus-org.
the class ExceptionConsumeInterceptorServiceTest method test6.
public void test6() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ExceptionConsumeInterceptorService interceptor1 = new ExceptionConsumeInterceptorService();
ServiceManagerFactory.registerService("Test", "ExceptionConsumeInterceptor", interceptor1);
Interceptor interceptor2 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
throw new IllegalArgumentException();
}
};
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor1.setExceptionClassNames(new String[] { "java.lang.IllegalArgumentException", "java.lang.UnsupportedOperationException" });
interceptor1.setReturnValue("-1");
ServiceManagerFactory.findManager("Test").startAllService();
Object ret = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }), new Invoker() {
public Object invoke(InvocationContext context) throws Throwable {
return "test";
}
}).invokeNext(new DefaultMethodInvocationContext("", String.class.getMethod("indexOf", new Class[] { String.class }), new Object[] { "fuga" }));
assertEquals(new Integer(-1), ret);
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.Interceptor in project nimbus by nimbus-org.
the class ExceptionConsumeInterceptorServiceTest method test2.
public void test2() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ExceptionConsumeInterceptorService interceptor1 = new ExceptionConsumeInterceptorService();
ServiceManagerFactory.registerService("Test", "ExceptionConsumeInterceptor", interceptor1);
Interceptor interceptor2 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
throw new UnsupportedOperationException();
}
};
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor1.setExceptionClassNames(new String[] { "java.lang.IllegalArgumentException", "java.lang.UnsupportedOperationException" });
ServiceManagerFactory.findManager("Test").startAllService();
Object ret = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }), new Invoker() {
public Object invoke(InvocationContext context) throws Throwable {
return "test";
}
}).invokeNext(new DefaultMethodInvocationContext());
assertNull(ret);
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.Interceptor in project nimbus by nimbus-org.
the class ExceptionConsumeInterceptorServiceTest method test3.
public void test3() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ExceptionConsumeInterceptorService interceptor1 = new ExceptionConsumeInterceptorService();
ServiceManagerFactory.registerService("Test", "ExceptionConsumeInterceptor", interceptor1);
Interceptor interceptor2 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
throw new IllegalArgumentException();
}
};
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor1.setExceptionClassNames(new String[] { "java.lang.RuntimeException" });
ServiceManagerFactory.findManager("Test").startAllService();
Object ret = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }), new Invoker() {
public Object invoke(InvocationContext context) throws Throwable {
return "test";
}
}).invokeNext(new DefaultMethodInvocationContext());
assertNull(ret);
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.Interceptor in project nimbus by nimbus-org.
the class ExceptionWrapInterceptorServiceTest method test2.
public void test2() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ExceptionWrapInterceptorService interceptor1 = new ExceptionWrapInterceptorService();
ServiceManagerFactory.registerService("Test", "ExceptionWrapInterceptor", interceptor1);
Interceptor interceptor2 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
throw new IOException("test");
}
};
try {
ServiceManagerFactory.findManager("Test").createAllService();
Properties mapping = new Properties();
mapping.setProperty("java.lang.IllegalArgumentException", "java.lang.UnsupportedOperationException");
interceptor1.setWrapExceptionMapping(mapping);
ServiceManagerFactory.findManager("Test").startAllService();
try {
new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }), new Invoker() {
public Object invoke(InvocationContext context) throws Throwable {
return "test";
}
}).invokeNext(new DefaultMethodInvocationContext());
fail();
} catch (IOException e) {
assertEquals("test", e.getMessage());
}
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
Aggregations