use of jp.ossc.nimbus.service.aop.Invoker 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");
}
}
use of jp.ossc.nimbus.service.aop.Invoker in project nimbus by nimbus-org.
the class ExceptionConsumeInterceptorServiceTest method test5.
public void test5() 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("hoge");
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(new Properties(), Properties.class.getMethod("getProperty", new Class[] { String.class }), new Object[] { "fuga" }));
assertEquals("hoge", ret);
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.Invoker in project nimbus by nimbus-org.
the class ExceptionConsumeInterceptorServiceTest method test1.
public void test1() 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.setLoggerMessageCode("WARN");
interceptor1.setLoggerMessageArgs(new String[] { "例外が発生しました。握り潰します。" });
interceptor1.setLoggingException(true);
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.Invoker in project nimbus by nimbus-org.
the class ExceptionThrowInterceptorServiceTest method test3.
public void test3() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ExceptionThrowInterceptorService interceptor = new ExceptionThrowInterceptorService();
ServiceManagerFactory.registerService("Test", "ExceptionThrowInterceptor", interceptor);
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor.setExceptionClassName("java.lang.IllegalArgumentException");
interceptor.setMessageKey("NIMBUS000");
ServiceManagerFactory.findManager("Test").startAllService();
try {
new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {
public Object invoke(InvocationContext context) throws Throwable {
return "test";
}
}).invokeNext(new DefaultMethodInvocationContext());
fail();
} catch (IllegalArgumentException e) {
assertEquals(ServiceManagerFactory.getMessageRecordFactory().findMessage("NIMBUS000"), e.getMessage());
}
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.Invoker in project nimbus by nimbus-org.
the class ExceptionThrowInterceptorServiceTest method test1.
public void test1() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ExceptionThrowInterceptorService interceptor = new ExceptionThrowInterceptorService();
ServiceManagerFactory.registerService("Test", "ExceptionThrowInterceptor", interceptor);
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor.setExceptionClassName("java.lang.IllegalArgumentException");
ServiceManagerFactory.findManager("Test").startAllService();
try {
new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {
public Object invoke(InvocationContext context) throws Throwable {
return "test";
}
}).invokeNext(new DefaultMethodInvocationContext());
fail();
} catch (IllegalArgumentException e) {
assertNull(e.getMessage());
}
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
Aggregations