KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > PEMainTest


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 /*
25  * PEMainTest.java
26  *
27  * Created on October 2, 2003, 1:47 PM
28  */

29
30 package com.sun.enterprise.server;
31
32 import java.util.Locale JavaDoc;
33 import java.util.StringTokenizer JavaDoc;
34 import junit.framework.*;
35 import junit.textui.TestRunner;
36 import com.sun.enterprise.server.PEMain;
37 import com.sun.enterprise.util.SystemPropertyConstants;
38
39 /**
40  * JUnit test for PEMain.java
41  * @author Rob Ruyak
42  */

43 public class PEMainTest extends TestCase {
44     
45     public PEMainTest(String JavaDoc name) throws Exception JavaDoc
46     {
47         super(name);
48     }
49
50
51     public void testSetSystemLocale() {
52         String JavaDoc [] array = {"en_US","en_US__567_89","sp_SP","fr_FR_WIN","","FR_FR_UNIX"};
53         for(int i = 0;i < array.length;i++) {
54             System.setProperty(SystemPropertyConstants.DEFAULT_LOCALE_PROPERTY,array[i]);
55             PEMain.setSystemLocale();
56             if(array[i].equals("")) {
57                 //System.out.println("Blank string reached..Locale should not change!");
58
Assert.assertTrue(Locale.getDefault().toString().
59                         equalsIgnoreCase(array[i-1]));
60             } else {
61                 Assert.assertTrue(Locale.getDefault().toString().
62                         equalsIgnoreCase(System.getProperty(
63                                 SystemPropertyConstants.DEFAULT_LOCALE_PROPERTY)));
64             }
65             //System.out.println("Locale -> " + Locale.getDefault());
66
}
67     }
68 /*
69     public void testSplitMethod() {
70         String [] array = {"en_US","en_US_______567_89","sp_SP","fr_FR_WIN",""};
71         for(int i = 0;i < array.length;i++) {
72             String[] tokens = array[i].split("_",3);
73             switch(tokens.length) {
74                 case 1:
75                     System.out.println("Token 1: " + tokens[0]);
76                     break;
77                 case 2:
78                     System.out.println("Token 1: " + tokens[0]);
79                     System.out.println("Token 2: " + tokens[1]);
80                     break;
81                 case 3:
82                     System.out.println("Token 1: " + tokens[0]);
83                     System.out.println("Token 2: " + tokens[1]);
84                     System.out.println("Token 3: " + tokens[2]);
85                     break;
86             }
87         }
88     }
89     public void testStringTokenization() {
90         String str = "sp_SP______WIN";
91         try {
92             StringTokenizer t = new StringTokenizer(str,"_");
93             switch(t.countTokens()) {
94                 case 0:
95                     break;
96                 case 1:
97                     Locale.setDefault(new Locale(t.nextToken()));
98                     break;
99                 case 2:
100                     Locale.setDefault(new Locale(t.nextToken(),t.nextToken()));
101                     break;
102                 default:
103                     String tkn1 = null,tkn2 = null,tkn3 = null;
104                     tkn1 = t.nextToken();
105                     tkn2 = t.nextToken();
106                     int lftPos = str.indexOf(tkn2);
107                     int rgtPos = lftPos + tkn2.length();
108                     tkn3 = str.substring(rgtPos + 1,str.length());
109                     Locale.setDefault(new Locale(tkn1,tkn2,tkn3));
110                     break;
111             }
112         } catch(Exception e) {
113                 System.out.println("Caught the exception: " + e.getMessage());
114                 e.printStackTrace();
115         }
116         Assert.assertEquals(str,Locale.getDefault().toString());
117     }
118   */

119     protected void setUp()
120     {
121     }
122
123     protected void tearDown()
124     {
125     }
126
127     public static junit.framework.Test suite()
128     {
129         TestSuite suite = new TestSuite(PEMainTest.class);
130         return suite;
131     }
132
133     public static void main(String JavaDoc args[]) throws Exception JavaDoc
134     {
135         final TestRunner runner= new TestRunner();
136         final TestResult result = runner.doRun(PEMainTest.suite(), false);
137         System.exit(result.errorCount() + result.failureCount());
138     }
139     
140 }
141
Popular Tags