public void testStoreLocale() throws Exception {
// Test different locations for storing locale
Parameters parameters = new Parameters();
Map result;
Session session;
Cookie cookie;
// 1. Don't store
result = act("locale2", null, parameters);
assertNotNull("Action should always succeed", result);
assertNull("Test for request attribute", getRequest().getAttribute("locale"));
assertNull("Test for session", getRequest().getSession(false));
assertTrue("Test for cookie", getResponse().getCookies().isEmpty());
// 2. Store, but don't create session
result = act("locale4", null, parameters);
assertNotNull("Action should always succeed", result);
assertEquals("Test for request attribute", "no_NO_B", getRequest().getAttribute("locale"));
assertNull("Test for session", getRequest().getSession(false));
assertEquals("Test for cookie", 1, getResponse().getCookies().size());
cookie = (Cookie) getResponse().getCookies().toArray()[0];
assertEquals("Check cookie name", "locale", cookie.getName());
assertEquals("Check cookie value", "no_NO_B", cookie.getValue());
// 3. Store, creating session
getRequest().reset();
getRequest().clearSession();
getResponse().reset();
result = act("locale5", null, parameters);
assertNotNull("Action should always succeed", result);
assertEquals("Test for request attribute", "en_GB_SCOUSE", getRequest().getAttribute("locale"));
session = getRequest().getSession(false);
assertNotNull("Test for session", session);
assertEquals("Test session attribute", "en_GB_SCOUSE", session.getAttribute("locale"));
assertEquals("Test for cookie", 1, getResponse().getCookies().size());
cookie = (Cookie) getResponse().getCookies().toArray()[0];
assertEquals("Check cookie name", "locale", cookie.getName());
assertEquals("Check cookie value", "en_GB_SCOUSE", cookie.getValue());
// 4. Store, with existing session
getRequest().reset();
getRequest().clearSession();
getResponse().reset();
session = getRequest().getSession(true);
result = act("locale4", null, parameters);
assertNotNull("Action should always succeed", result);
assertEquals("Test for request attribute", "no_NO_B", getRequest().getAttribute("locale"));
session = getRequest().getSession(false);
assertNotNull("Test for session", session);
assertEquals("Test session attribute", "no_NO_B", session.getAttribute("locale"));
assertEquals("Test for cookie", 1, getResponse().getCookies().size());
cookie = (Cookie) getResponse().getCookies().toArray()[0];
assertEquals("Check cookie name", "locale", cookie.getName());
assertEquals("Check cookie value", "no_NO_B", cookie.getValue());
}