KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > framework > LocalStringsManagerTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.cli.framework;
25
26 import java.util.Properties JavaDoc;
27 import java.util.Vector JavaDoc;
28 import java.util.ResourceBundle JavaDoc;
29
30 import junit.framework.*;
31 /**
32  *
33  * @author <a HREF="mailto:toby.h.ferguson@sun.com">Toby H Ferguson</a>
34  * @version $Revision: 1.4 $
35  */

36
37 public class LocalStringsManagerTest extends TestCase {
38     public void testGettingAnAbsentKey(){
39         final LocalStringsManager lsm = new LocalStringsManager("com.sun.enterprise.cli.framework", "P1");
40         assertEquals("Key not found (absent)", lsm.getString("absent"));
41     }
42     
43     public void testReplacementException() throws Exception JavaDoc {
44         final LocalStringsManager lsm = new LocalStringsManager("com.sun.enterprise.cli.framework", "P1");
45         try {
46             assertEquals("15% of 1,000 makes 150", lsm.getString("bad_format", new Object JavaDoc[0]));
47             fail("Expected CommandValidationException indicating that the formatting was incorrect");
48         }
49         catch (CommandValidationException cve){
50             assertEquals("java.lang.IllegalArgumentException: unknown format type at ", cve.getMessage());
51         }
52     }
53
54     private Properties JavaDoc makeProperty(String JavaDoc f){
55         final Properties JavaDoc p = new Properties JavaDoc();
56         p.setProperty("base-package", "com.sun.enterprise.cli.framework");
57         p.setProperty("property-file-name", f);
58         return p;
59     }
60     
61     public void testInitializationFromProperties(){
62         final Vector JavaDoc v = new Vector JavaDoc();
63         v.add(makeProperty("P1"));
64         v.add(makeProperty("P2"));
65         final LocalStringsManager lsm = new LocalStringsManager(v);
66         assertEquals("P1.a", lsm.getString("a"));
67         
68         ResourceBundle JavaDoc rb1 =
69                 ResourceBundle.getBundle("com.sun.enterprise.cli.framework" +
70                                          "." + "P1");
71         ResourceBundle JavaDoc rb2 =
72                 ResourceBundle.getBundle("com.sun.enterprise.cli.framework" +
73                                          "." + "P2"); final Vector JavaDoc v2 = new Vector JavaDoc();
74         v2.add(rb1);
75         v2.add(rb2);
76         assertEquals("Comparing Resource Properties", v2, lsm.getResourceBundles());
77     }
78
79         
80     public void testReplacement() throws Exception JavaDoc {
81         final Object JavaDoc[] arguments = {
82             new Double JavaDoc(.15),
83             new Integer JavaDoc(1000),
84             new Integer JavaDoc(150)
85         };
86         final LocalStringsManager lsm = new LocalStringsManager("com.sun.enterprise.cli.framework", "P1");
87         assertEquals("15% of 1,000 makes 150", lsm.getString("good_format", arguments));
88     }
89
90
91     public void testSimpleUse(){
92         final LocalStringsManager lsm = new LocalStringsManager("com.sun.enterprise.cli.framework", "P1");
93         assertEquals("P1.a", lsm.getString("a"));
94     }
95
96     public void testWithLocale()
97     {
98         final Vector JavaDoc v = new Vector JavaDoc();
99         v.add("com.sun.enterprise.cli.framework.P1");
100         final LocalStringsManager lsm = new LocalStringsManager(v, java.util.Locale.US);
101         assertEquals("P1.a", lsm.getString("a"));
102     }
103
104
105     public void testSimpleCreation() {
106         final LocalStringsManager lsm = new LocalStringsManager("com.sun.enterprise.cli.framework", "P1");
107         assertEquals("P1", lsm.getPropertiesFile());
108         assertEquals("com.sun.enterprise.cli.framework", lsm.getPackageName());
109     }
110
111     public LocalStringsManagerTest(String JavaDoc name){
112         super(name);
113     }
114
115     protected void setUp() {
116     }
117
118
119     protected void tearDown() {
120     }
121
122     private void nyi(){
123         fail("Not Yet Implemented");
124     }
125
126     public static void main(String JavaDoc args[]){
127         if (args.length == 0){
128             junit.textui.TestRunner.run(LocalStringsManagerTest.class);
129         } else {
130             junit.textui.TestRunner.run(makeSuite(args));
131         }
132     }
133     private static TestSuite makeSuite(String JavaDoc args[]){
134         final TestSuite ts = new TestSuite();
135         for (int i = 0; i < args.length; i++){
136             ts.addTest(new LocalStringsManagerTest(args[i]));
137         }
138         return ts;
139     }
140 }
141
Popular Tags