);
FacesLifecycle.beginRequest( externalContext );
Manager.instance().setCurrentConversationId("1");
FacesLifecycle.resumeConversation(externalContext);
ConversationInterceptor ci = new ConversationInterceptor();
ci.setComponent( new Component(Foo.class, appContext) );
assert !Manager.instance().isLongRunningConversation();
String result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("foo");
}
@Override
public Object proceed() throws Exception
{
return "foo";
}
});
assert !Manager.instance().isLongRunningConversation();
assert "foo".equals(result);
Manager.instance().initializeTemporaryConversation();
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("begin");
}
@Override
public Object proceed() throws Exception
{
return "begun";
}
});
assert Manager.instance().isLongRunningConversation();
assert "begun".equals(result);
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("foo");
}
@Override
public Object proceed() throws Exception
{
return "foo";
}
});
assert Manager.instance().isLongRunningConversation();
assert "foo".equals(result);
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("end");
}
@Override
public Object proceed() throws Exception
{
return "ended";
}
});
assert !Manager.instance().isLongRunningConversation();
assert "ended".equals(result);
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("beginNull");
}
@Override
public Object proceed() throws Exception
{
return null;
}
});
assert !Manager.instance().isLongRunningConversation();
assert result==null;
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("beginVoid");
}
@Override
public Object proceed() throws Exception
{
return null;
}
});
assert Manager.instance().isLongRunningConversation();
assert result==null;
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("foo");
}
@Override
public Object proceed() throws Exception
{
return "foo";
}
});
assert Manager.instance().isLongRunningConversation();
assert "foo".equals(result);
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("endNull");
}
@Override
public Object proceed() throws Exception
{
return null;
}
});
assert Manager.instance().isLongRunningConversation();
assert result==null;
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("endVoid");
}
@Override
public Object proceed() throws Exception
{
return null;
}
});
assert !Manager.instance().isLongRunningConversation();
assert result==null;
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("beginIf");
}
@Override
public Object proceed() throws Exception
{
return "failure";
}
});
assert !Manager.instance().isLongRunningConversation();
assert "failure".equals(result);
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("beginIf");
}
@Override
public Object proceed() throws Exception
{
return "success";
}
});
assert Manager.instance().isLongRunningConversation();
assert "success".equals(result);
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("foo");
}
@Override
public Object proceed() throws Exception
{
return "foo";
}
});
assert Manager.instance().isLongRunningConversation();
assert "foo".equals(result);
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("endIf");
}
@Override
public Object proceed() throws Exception
{
return "failure";
}
});
assert Manager.instance().isLongRunningConversation();
assert "failure".equals(result);
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("endIf");
}
@Override
public Object proceed() throws Exception
{
return "success";
}
});
assert !Manager.instance().isLongRunningConversation();
assert "success".equals(result);
///////////////////////////////////////////////
// Test @End(root=true) for nested conversation
///////////////////////////////////////////////
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("begin");
}
@Override
public Object proceed() throws Exception
{
return "begun";
}
});
assert Manager.instance().isLongRunningConversation();
assert "begun".equals(result);
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("beginNested");
}
@Override
public Object proceed() throws Exception
{
return "begunNested";
}
});
assert Manager.instance().isNestedConversation();
assert "begunNested".equals(result);
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("endRoot");
}
@Override
public Object proceed() throws Exception
{
return "endedRoot";
}
});
assert !Manager.instance().isNestedConversation();
assert !Manager.instance().isLongRunningConversation();
assert "endedRoot".equals(result);
/////////////////////////////////////////////////////
// Test @End(root=true) for a non-nested conversation
/////////////////////////////////////////////////////
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("begin");
}
@Override
public Object proceed() throws Exception
{
return "begun";
}
});
assert Manager.instance().isLongRunningConversation();
assert "begun".equals(result);
result = (String) ci.aroundInvoke( new MockInvocationContext() {
@Override
public Method getMethod()
{
return InterceptorTest.getMethod("endRoot");
}