1   /* Copyright 2004, 2005, 2006 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", msgs.getMessage("RejectProxyTickets.reject", null, Locale.ENGLISH));
49      }
50  
51      public void testReplacableLookup() {
52          // Change Locale to English
53          Locale before = LocaleContextHolder.getLocale();
54          LocaleContextHolder.setLocale(Locale.ENGLISH);
55  
56          // Cause a message to be generated
57          MessageSourceAccessor messages = AcegiMessageSource.getAccessor();
58          assertEquals("Missing mandatory digest value; received header FOOBAR",
59              messages.getMessage("DigestProcessingFilter.missingMandatory", new Object[] {"FOOBAR"},
60                  "ERROR - FAILED TO LOOKUP"));
61  
62          // Revert to original Locale
63          LocaleContextHolder.setLocale(before);
64      }
65  }