KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
27 import java.util.Locale JavaDoc;
28 import junit.framework.TestCase;
29 import junit.framework.TestSuite;
30 import java.util.NoSuchElementException JavaDoc;
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 CLIManFileFinderTest extends TestCase {
38   public void testEndOfIterator() {
39       CLIManFileFinder c = new CLIManFileFinder();
40       Locale JavaDoc l = new Locale JavaDoc("en", "UK", "v1");
41       Iterator JavaDoc it = c.getPossibleLocations("command", l);
42       for (int i = 0; i < 71; i++){
43         it.next();
44       }
45       assertEquals("help/command.9m", (String JavaDoc) it.next());
46       assertTrue(!it.hasNext());
47       try {
48         it.next();
49         fail("Expected NoSuchElementException indicating we'd read beyond the end of the interator");
50       }
51       catch (NoSuchElementException JavaDoc nse){
52       }
53         
54   }
55     
56   public void testEndOfThirdSearch() {
57       CLIManFileFinder c = new CLIManFileFinder();
58       Locale JavaDoc l = new Locale JavaDoc("en", "UK", "v1");
59       Iterator JavaDoc it = c.getPossibleLocations("command", l);
60       for (int i = 0; i < 53; i++){
61         it.next();
62       }
63       assertEquals("help/en/command.9m", (String JavaDoc) it.next());
64       assertEquals("help/command.1", (String JavaDoc) it.next());
65   }
66   public void testEndOfSecondSearch() {
67       CLIManFileFinder c = new CLIManFileFinder();
68       Locale JavaDoc l = new Locale JavaDoc("en", "UK", "v1");
69       Iterator JavaDoc it = c.getPossibleLocations("command", l);
70       for (int i = 0; i < 35; i++){
71         it.next();
72       }
73       assertEquals("help/en/UK/command.9m", (String JavaDoc) it.next());
74       assertEquals("help/en/command.1", (String JavaDoc) it.next());
75   }
76   public void testEndOfFirstSearch() {
77       CLIManFileFinder c = new CLIManFileFinder();
78       Locale JavaDoc l = new Locale JavaDoc("en", "UK", "v1");
79       Iterator JavaDoc it = c.getPossibleLocations("command", l);
80       for (int i = 0; i < 17; i++){
81         it.next();
82       }
83       assertEquals("help/en/UK/v1/command.9m", (String JavaDoc) it.next());
84       assertEquals("help/en/UK/command.1", (String JavaDoc) it.next());
85   }
86   
87   public void testLocations() {
88       CLIManFileFinder c = new CLIManFileFinder();
89       Locale JavaDoc l = new Locale JavaDoc("en", "UK", "v1");
90       Iterator JavaDoc it = c.getPossibleLocations("command", l);
91       assertEquals("help/en/UK/v1/command.1", (String JavaDoc) it.next());
92       assertEquals("help/en/UK/v1/command.1m",(String JavaDoc) it.next());
93       assertEquals("help/en/UK/v1/command.2", (String JavaDoc) it.next());
94       for (int i = 0; i < 5; i++){
95         it.next();
96       }
97       assertEquals("help/en/UK/v1/command.5", (String JavaDoc) it.next());
98   }
99   
100         
101   public void testNoLanguage() {
102       CLIManFileFinder c = new CLIManFileFinder();
103       Locale JavaDoc l = new Locale JavaDoc("", "UK", "v1");
104       assertEquals(1,c.getLocaleLocations(l).length);
105       assertEquals("", c.getLocaleLocations(l)[0]);
106     }
107     
108   public void testNoCountry() {
109       CLIManFileFinder c = new CLIManFileFinder();
110       Locale JavaDoc l = new Locale JavaDoc("en", "", "v1");
111       assertEquals(2,c.getLocaleLocations(l).length);
112       assertEquals("/en", c.getLocaleLocations(l)[0]);
113       assertEquals("", c.getLocaleLocations(l)[1]);
114     }
115
116   public void testEmptyVariant(){
117     CLIManFileFinder c = new CLIManFileFinder();
118     Locale JavaDoc l = new Locale JavaDoc("en", "uk", "");
119     assertEquals(3,c.getLocaleLocations(l).length);
120     assertEquals("/en/UK", c.getLocaleLocations(l)[0]);
121     assertEquals("/en", c.getLocaleLocations(l)[1]);
122       assertEquals("", c.getLocaleLocations(l)[2]);
123   }
124   public void testNoVariant(){
125     CLIManFileFinder c = new CLIManFileFinder();
126     Locale JavaDoc l = new Locale JavaDoc("en", "uk");
127     assertEquals(3,c.getLocaleLocations(l).length);
128     assertEquals("/en/UK", c.getLocaleLocations(l)[0]);
129     assertEquals("/en", c.getLocaleLocations(l)[1]);
130       assertEquals("", c.getLocaleLocations(l)[2]);
131   }
132   
133   public void testSimpleLocation() {
134     CLIManFileFinder c = new CLIManFileFinder();
135     Locale JavaDoc l = new Locale JavaDoc("en", "uk", "v1");
136     assertEquals(4,c.getLocaleLocations(l).length);
137     assertEquals("/en/UK/v1", c.getLocaleLocations(l)[0]);
138     assertEquals("/en/UK", c.getLocaleLocations(l)[1]);
139     assertEquals("/en", c.getLocaleLocations(l)[2]);
140     assertEquals("", c.getLocaleLocations(l)[3]);
141     
142   }
143
144   public CLIManFileFinderTest(String JavaDoc name){
145     super(name);
146   }
147
148   protected void setUp() {
149   }
150
151   protected void tearDown() {
152   }
153
154   private void nyi(){
155     fail("Not Yet Implemented");
156   }
157
158   public static void main(String JavaDoc args[]){
159     if (args.length == 0){
160       junit.textui.TestRunner.run(CLIManFileFinderTest.class);
161     } else {
162       junit.textui.TestRunner.run(makeSuite(args));
163     }
164   }
165   private static TestSuite makeSuite(String JavaDoc args[]){
166     final TestSuite ts = new TestSuite();
167     for (int i = 0; i < args.length; i++){
168       ts.addTest(new CLIManFileFinderTest(args[i]));
169     }
170     return ts;
171   }
172 }
173
Popular Tags