    1   /* Copyright 2004, 2005 Acegi Technology Pty Limited
    2    *
    3    * Licensed under the Apache License, Version 2.0 (the "License");
    4    * you may not use this file except in compliance with the License.
    5    * You may obtain a copy of the License at
    6    *
    7    *     http://www.apache.org/licenses/LICENSE-2.0
    8    *
    9    * Unless required by applicable law or agreed to in writing, software
    10   * distributed under the License is distributed on an "AS IS" BASIS,
    11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12   * See the License for the specific language governing permissions and
    13   * limitations under the License.
    14   */
    15
    16  package org.acegisecurity;
    17
    18  import junit.framework.TestCase;
    19
    20  import org.springframework.context.i18n.LocaleContextHolder;
    21  import org.springframework.context.support.MessageSourceAccessor;
    22
    23  import java.util.Locale;
    24
    25
    26  /***
    27   * Tests {@link org.acegisecurity.AcegiMessageSource}.
    28   */
    29  public class AcegiMessageSourceTests extends TestCase {
    30      //~ Constructors ===========================================================
    31
    32      public AcegiMessageSourceTests() {
    33          super();
    34      }
    35
    36      public AcegiMessageSourceTests(String arg0) {
    37          super(arg0);
    38      }
    39
    40      //~ Methods ================================================================
    41
    42      public static void main(String[] args) {
    43          junit.textui.TestRunner.run(AcegiMessageSourceTests.class);
    44      }
    45
    46      public void testOperation() {
    47          AcegiMessageSource msgs = new AcegiMessageSource();
    48          assertEquals("Proxy tickets are rejected",
    49              msgs.getMessage("RejectProxyTickets.reject", null, Locale.ENGLISH));
    50      }
    51
    52      public void testReplacableLookup() {
    53          // Change Locale to English
    54          Locale before = LocaleContextHolder.getLocale();
    55          LocaleContextHolder.setLocale(Locale.ENGLISH);
    56
    57          // Cause a message to be generated
    58          MessageSourceAccessor messages = AcegiMessageSource.getAccessor();
    59          assertEquals("Missing mandatory digest value; received header FOOBAR",
    60              messages.getMessage("DigestProcessingFilter.missingMandatory",
    61                  new Object[] {"FOOBAR"}, "ERROR - FAILED TO LOOKUP"));
    62
    63          // Revert to original Locale
    64          LocaleContextHolder.setLocale(before);
    65      }
    66  }