Esempio n. 1
0
 public void tearDown() throws Exception {
   interceptor.destroy();
   interceptor = null;
   ac = null;
   session = null;
   mai = null;
 }
Esempio n. 2
0
  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"));
  }
Esempio n. 3
0
  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);
  }
Esempio n. 4
0
  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
  }
Esempio n. 5
0
  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));
  }
Esempio n. 6
0
  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
  }
Esempio n. 7
0
  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());
  }
Esempio n. 8
0
  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
  }
Esempio n. 9
0
  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
  }
Esempio n. 10
0
  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
  }
Esempio n. 11
0
  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);
  }
Esempio n. 12
0
 public void testNoSession() throws Exception {
   ac.setSession(null);
   interceptor.intercept(mai);
 }
Esempio n. 13
0
 public void testEmptyParamAndSession() throws Exception {
   interceptor.intercept(mai);
 }