final Bar bar = new Bar();
final Foo foo = new Foo();
Contexts.getSessionContext().set("otherFoo", foo);
BijectionInterceptor bi = new BijectionInterceptor();
bi.setComponent( new Component(Bar.class, appContext) );
String result = (String) bi.aroundInvoke( new MockInvocationContext() {
@Override
public Object getTarget()
{
return bar;
}
@Override
public Object proceed() throws Exception
{
assert bar.otherFoo==foo;
assert bar.foo!=null;
return bar.foo();
}
});
assert "foo".equals(result);
assert Contexts.getEventContext().get("otherString").equals("outAgain");
assert Contexts.getConversationContext().get("string").equals("out");
assert Contexts.getSessionContext().isSet("foo");
assert bar.foo==null;
assert bar.otherFoo==null;
final Method method;
try
{
method = Bar.class.getMethod("foo");
}
catch (Exception e)
{
throw new RuntimeException(e);
}
bi.aroundInvoke( new MockInvocationContext() {
@Override
public Object getTarget()
{
return bar;
}
@Override
public Object proceed() throws Exception
{
assert bar.otherFoo==foo;
assert bar.foo!=null;
return bar.foo();
}
@Override
public Method getMethod()
{
return method;
}
});
assert bar.foo==null;
assert bar.otherFoo==null;
try
{
Contexts.getSessionContext().remove("otherFoo");
bi.aroundInvoke( new MockInvocationContext() {
@Override
public Object getTarget()
{
return bar;
}
@Override
public Object proceed() throws Exception
{
assert false;
return null;
}
@Override
public Method getMethod()
{
return method;
}
});
assert false;
}
catch (Exception e)
{
assert e instanceof RequiredException;
}
final Method method2;
try
{
method2 = BrokenAction.class.getMethod("go");
}
catch (Exception e)
{
throw new RuntimeException(e);
}
final BrokenAction brokenAction = new BrokenAction();
BijectionInterceptor biba = new BijectionInterceptor();
biba.setComponent( new Component(BrokenAction.class, appContext) );
try
{
biba.aroundInvoke( new MockInvocationContext() {
@Override
public Object getTarget() {
return brokenAction;
}
@Override
public Object proceed() throws Exception {
assert false;
return null;
}
@Override
public Method getMethod()
{
return method2;
}
} );
assert false;
}
catch (Exception e)
{
assert e instanceof RequiredException;
}
final Method method3;
try
{
method3 = Action.class.getMethod("go");
}
catch (Exception e)
{
throw new RuntimeException(e);
}
final Action action = new Action();
BijectionInterceptor bia = new BijectionInterceptor();
bia.setComponent( new Component(Action.class, appContext) );
result = (String) bia.aroundInvoke( new MockInvocationContext() {
@Override
public Object getTarget() {
return action;
}