Merge pull request #2 from yasserzamani/sessionless

test no session but with locale parameter
This commit is contained in:
Lukasz Lenart
2018-01-31 11:27:59 +01:00
committed by GitHub
2 changed files with 22 additions and 2 deletions
@@ -281,7 +281,6 @@ public class I18nInterceptor extends AbstractInterceptor {
@Override
public Locale store(ActionInvocation invocation, Locale locale) {
LOG.debug("Do not create session if it doesn't exist");
HttpSession session = ServletActionContext.getRequest().getSession(false);
if (session != null) {
@@ -289,6 +288,8 @@ public class I18nInterceptor extends AbstractInterceptor {
synchronized (sessionId.intern()) {
invocation.getInvocationContext().getSession().put(attributeName, locale);
}
} else {
LOG.debug("session creation avoided as it doesn't exist already");
}
return locale;
@@ -52,7 +52,7 @@ public class I18nInterceptorTest extends TestCase {
interceptor.intercept(mai);
}
public void testNoSession() throws Exception {
public void testNoSessionNoLocale() throws Exception {
request.setSession(null);
try {
interceptor.intercept(mai);
@@ -60,6 +60,25 @@ public class I18nInterceptorTest extends TestCase {
} catch (Exception ignore) {
fail("Shouldn't throw any exception!");
}
assertFalse(mai.getInvocationContext().getParameters().get(I18nInterceptor.DEFAULT_PARAMETER).isDefined()); // should have been removed
assertNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should not be stored here
}
public void testNoSessionButLocale() throws Exception {
prepare(I18nInterceptor.DEFAULT_PARAMETER, "da_DK"); //prevents shouldStore to being false
request.setSession(null);
try {
interceptor.intercept(mai);
assertTrue(true);
} catch (Exception ignore) {
fail("Shouldn't throw any exception!");
}
assertFalse(mai.getInvocationContext().getParameters().get(I18nInterceptor.DEFAULT_PARAMETER).isDefined()); // should have been removed
assertNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should not be stored here
}
public void testDefaultLocale() throws Exception {