public void tearDown() throws Exception { interceptor.destroy(); interceptor = null; ac = null; session = null; mai = null; }
public void testSetParameterAndAttributeNames() throws Exception { // given prepare("world", Locale.CHINA); interceptor.setAttributeName("hello"); interceptor.setParameterName("world"); // when interceptor.intercept(mai); // then assertFalse( mai.getInvocationContext().getParameters().contains("world")); // should have been removed assertNotNull(session.get("hello")); // should be stored here assertEquals(Locale.CHINA, session.get("hello")); }
public void testActionContextLocaleIsPreservedWhenNotOverridden() throws Exception { final Locale locale1 = Locale.TRADITIONAL_CHINESE; mai.getInvocationContext().setLocale(locale1); interceptor.intercept(mai); Locale locale = (Locale) session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE); assertNull(locale); // should not be stored here locale = mai.getInvocationContext().getLocale(); assertEquals(locale1, locale); }
public void testDenmarkLocaleRequestOnly() throws Exception { prepare(I18nInterceptor.DEFAULT_REQUESTONLY_PARAMETER, "da_DK"); interceptor.intercept(mai); assertFalse( mai.getInvocationContext() .getParameters() .get(I18nInterceptor.DEFAULT_PARAMETER) .isDefined()); // should have been removed Locale denmark = new Locale("da", "DK"); assertNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here assertEquals(denmark, mai.getInvocationContext().getLocale()); // should create a locale object }
public void testRealLocalesInParams() throws Exception { Locale[] locales = new Locale[] {Locale.CANADA_FRENCH}; assertTrue(locales.getClass().isArray()); prepare(I18nInterceptor.DEFAULT_PARAMETER, locales); interceptor.intercept(mai); assertFalse( mai.getInvocationContext() .getParameters() .get(I18nInterceptor.DEFAULT_PARAMETER) .isDefined()); // should have been removed assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here assertEquals(Locale.CANADA_FRENCH, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); }
public void testRealLocaleObjectInParams() throws Exception { prepare(I18nInterceptor.DEFAULT_PARAMETER, Locale.CANADA_FRENCH); interceptor.intercept(mai); assertFalse( mai.getInvocationContext() .getParameters() .get(I18nInterceptor.DEFAULT_PARAMETER) .isDefined()); // should have been removed assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here assertEquals( Locale.CANADA_FRENCH, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should create a locale object }
public void testWithVariant() throws Exception { prepare(I18nInterceptor.DEFAULT_PARAMETER, "ja_JP_JP"); interceptor.intercept(mai); assertFalse( mai.getInvocationContext() .getParameters() .get(I18nInterceptor.DEFAULT_PARAMETER) .isDefined()); // should have been removed Locale variant = new Locale("ja", "JP", "JP"); Locale locale = (Locale) session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE); assertNotNull(locale); // should be stored here assertEquals(variant, locale); assertEquals("JP", locale.getVariant()); }
public void testCountryOnlyLocale() throws Exception { prepare(I18nInterceptor.DEFAULT_PARAMETER, "NL"); interceptor.intercept(mai); assertFalse( mai.getInvocationContext() .getParameters() .get(I18nInterceptor.DEFAULT_PARAMETER) .isDefined()); // should have been removed Locale denmark = new Locale("NL"); assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here assertEquals( denmark, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should create a locale object }
public void testDefaultLocale() throws Exception { prepare( I18nInterceptor.DEFAULT_PARAMETER, "_"); // bad locale that would get us default locale instead interceptor.intercept(mai); assertFalse( mai.getInvocationContext() .getParameters() .get(I18nInterceptor.DEFAULT_PARAMETER) .isDefined()); // should have been removed assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here assertEquals( Locale.getDefault(), session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should create a locale object }
public void testCookieCreation() throws Exception { prepare(I18nInterceptor.DEFAULT_COOKIE_PARAMETER, "da_DK"); final Cookie cookie = new Cookie(I18nInterceptor.DEFAULT_COOKIE_ATTRIBUTE, "da_DK"); HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class); response.addCookie(CookieMatcher.eqCookie(cookie)); EasyMock.replay(response); ac.put(StrutsStatics.HTTP_RESPONSE, response); interceptor.intercept(mai); EasyMock.verify(response); Locale denmark = new Locale("da", "DK"); assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here assertEquals( denmark, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should create a locale object }
public void setUp() throws Exception { interceptor = new I18nInterceptor(); interceptor.init(); session = new HashMap(); Map<String, Object> ctx = new HashMap<String, Object>(); ctx.put(ActionContext.PARAMETERS, HttpParameters.createEmpty().build()); ctx.put(ActionContext.SESSION, session); ac = new ActionContext(ctx); ServletActionContext.setContext(ac); ServletActionContext.setRequest(new MockHttpServletRequest()); Action action = new Action() { public String execute() throws Exception { return SUCCESS; } }; mai = new MockActionInvocation(); ((MockActionInvocation) mai).setAction(action); ((MockActionInvocation) mai).setInvocationContext(ac); }
public void testNoSession() throws Exception { ac.setSession(null); interceptor.intercept(mai); }
public void testEmptyParamAndSession() throws Exception { interceptor.intercept(mai); }