// Get the initial environment and expression contexts from the page
// context.
final TestEnvironmentContext initialEnvContext =
(TestEnvironmentContext) pageContext.getEnvironmentContext();
final ExpressionContext initialExprContext =
initialEnvContext.getExpressionContext();
// Retrieve the initial MarinerRequestContext.
final MarinerRequestContext initialRequestContext =
pageContext.getRequestContext();
assertSame("Expression context should be copied to first nested " +
"context",
initialRequestContext.getEnvironmentContext().
getExpressionContext(),
initialExprContext);
// Initially, the expression context is associated with the page
// context's request context.
assertSame("MRC class property should be the same for the page " +
"context's request context",
initialExprContext.getProperty(MarinerRequestContext.class),
initialRequestContext);
// Create the first nested context.
MarinerRequestContext nestedContext1 =
initialRequestContext.createNestedContext();
// Test that the initial expression context has been copied to the
// first nested context.
assertSame("Expression context should be copied to first nested " +
"context",
nestedContext1.getEnvironmentContext().getExpressionContext(),
initialExprContext);
// The expression context is now associated with the
// MarinerServletRequestContext.
assertSame("MRC class property should be the same on first nested " +
"context",
initialExprContext.getProperty(MarinerRequestContext.class),
nestedContext1);
// Create the second nested context.
MarinerRequestContext nestedContext2 =
nestedContext1.createNestedContext();
// Test that the initial expression context has been copied to the
// second nested context.
assertSame("Expression context should be copied to second nested " +
"context",
nestedContext2.getEnvironmentContext().getExpressionContext(),
initialExprContext);
// The expression context is now associated with the second nested
// context.
assertSame("MRC class property should be the same on second nested " +
"context",
initialExprContext.getProperty(MarinerRequestContext.class),
nestedContext2);
// Clean up the context's resources; in particular the expression
// context should be "reset".
nestedContext2.release();
// After releasing, the expression context should now be re-associated
// with the first nested context.
assertSame("MRC class property should be the same on first nested " +
"context after second nested context release",
initialExprContext.getProperty(MarinerRequestContext.class),
nestedContext1);
// Clean up the context's resources; in particular the expression
// context should be "reset".
nestedContext1.release();
// After releasing, the expression context should now be re-associated
// with the internal request context.
assertSame("MRC class property should be the same on " +
"MarinerServletRequestContext after first nested release",
initialExprContext.getProperty(MarinerRequestContext.class),
initialRequestContext);
}