01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * 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: * Tests {@link org.acegisecurity.AcegiMessageSource}.
27: */
28: public class AcegiMessageSourceTests extends TestCase {
29: //~ Constructors ===================================================================================================
30:
31: public AcegiMessageSourceTests() {
32: super ();
33: }
34:
35: public AcegiMessageSourceTests(String arg0) {
36: super (arg0);
37: }
38:
39: //~ Methods ========================================================================================================
40:
41: public static void main(String[] args) {
42: junit.textui.TestRunner.run(AcegiMessageSourceTests.class);
43: }
44:
45: public void testOperation() {
46: AcegiMessageSource msgs = new AcegiMessageSource();
47: assertEquals("Proxy tickets are rejected", msgs.getMessage(
48: "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
58: .getAccessor();
59: assertEquals(
60: "Missing mandatory digest value; received header FOOBAR",
61: messages.getMessage(
62: "DigestProcessingFilter.missingMandatory",
63: new Object[] { "FOOBAR" },
64: "ERROR - FAILED TO LOOKUP"));
65:
66: // Revert to original Locale
67: LocaleContextHolder.setLocale(before);
68: }
69: }
|