servletContext.addInitParameter("org.apache.myfaces.NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION", "2");
servletContext.addInitParameter(StateManager.SERIALIZE_SERVER_STATE_PARAM_NAME, "true");
// Initialization
setupRequest();
StateCache stateCache = new ServerSideStateCacheImpl();
tearDownRequest();
Object savedToken;
Object firstSavedToken;
try
{
setupRequest();
facesContext.getViewRoot().setViewId("view1.xhtml");
savedToken = stateCache.saveSerializedView(facesContext, 1);
firstSavedToken = savedToken;
}
finally
{
tearDownRequest();
}
try
{
setupRequest();
Object value = stateCache.restoreSerializedView(facesContext, "view1.xhtml", savedToken);
Assert.assertEquals(1, value);
facesContext.getViewRoot().setViewId("view2.xhtml");
savedToken = stateCache.saveSerializedView(facesContext, 2);
}
finally
{
tearDownRequest();
}
try
{
setupRequest();
Object value = stateCache.restoreSerializedView(facesContext, "view2.xhtml", savedToken);
Assert.assertEquals(2, value);
facesContext.getViewRoot().setViewId("view2.xhtml");
savedToken = stateCache.saveSerializedView(facesContext, 3);
}
finally
{
tearDownRequest();
}
try
{
setupRequest();
Object value = stateCache.restoreSerializedView(facesContext, "view1.xhtml", firstSavedToken);
// Since org.apache.myfaces.NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION is 2, the first one was already discarded
Assert.assertNull(value);
}
finally