KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > validation > FrameTest


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.config.serverbeans.validation;
25
26 import junit.framework.*;
27 /**
28  *
29  * @author <a HREF="mailto:toby.h.ferguson@sun.com">Toby H Ferguson</a>
30  * @version $Revision: 1.3 $
31  */

32
33 public class FrameTest extends TestCase {
34     public void testToString() {
35         Frame f = Frame.newFrame();
36         assertEquals("[ []]", f.toString());
37         Frame f1 = Frame.newFrame();
38         f1.inheritFrom(f);
39         assertEquals("[ [ []]]", f1.toString());
40         f1.put("k", "v");
41         assertEquals("[k->v [ []]]", f1.toString());
42         f1.put("k2", "v2");
43         assertEquals("[k->v, k2->v2 [ []]]", f1.toString());
44         f1.put("a", "b");
45         assertEquals("[a->b, k->v, k2->v2 [ []]]", f1.toString());
46         f.put("x", "y");
47         assertEquals("[a->b, k->v, k2->v2 [x->y []]]", f1.toString());
48         
49         
50     }
51     
52     public void testEquality() {
53         Frame f = Frame.newFrame();
54         Frame f1 = Frame.newFrame();
55         assertEquals(f, f1);
56         f1.inheritFrom(f);
57         assertFalse(f.equals(f1));
58         assertFalse(f1.equals(f));
59     }
60     
61     public void testNoLoops() {
62         Frame top = Frame.newFrame();
63         Frame middle = Frame.newFrame(top);
64         try {
65             top.inheritFrom(middle);
66             fail("expected expcetion indicaing loops not allowed");
67         }
68         catch (IllegalArgumentException JavaDoc iae){
69             assertEquals("Inheriting from an ancestor is illegal - it causes loops!", iae.getMessage());
70         }
71     }
72     
73     public void testChangeInheritance(){
74         Frame top = Frame.newFrame();
75         top.put("top", "1");
76         Frame middle = Frame.newFrame();
77         assertEquals("${top}", middle.lookup("top"));
78         middle.inheritFrom(top);
79         assertEquals("1", middle.lookup("top"));
80     }
81     
82     public void testInheritance() {
83         Frame top = Frame.newFrame();
84         top.put("top", "1");
85         assertEquals("1", top.lookup("top"));
86         Frame middle = Frame.newFrame(top);
87         assertEquals("1", top.lookup("top"));
88         middle.put("top", "2");
89         assertEquals("1", top.lookup("top"));
90         assertEquals("2", middle.lookup("top"));
91         Frame bottom = Frame.newFrame(middle);
92         bottom.put("top", "3");
93         assertEquals("1", top.lookup("top"));
94         assertEquals("2", middle.lookup("top"));
95         assertEquals("3", bottom.lookup("top"));
96         
97     }
98     
99         
100     public void testNoKeyFound() {
101         Frame f = Frame.newFrame();
102         assertEquals("${key}", f.lookup("key"));
103     }
104     
105     public void testBasicPut() {
106         Frame f = Frame.newFrame();
107         f.put("x", "y");
108         assertEquals("y", f.lookup("x"));
109         f.put("java.vendor.url", "myUrl");
110         assertEquals("myUrl", f.lookup("java.vendor.url"));
111         assertEquals(System.getProperty("path.separator"), f.lookup("path.separator"));
112     }
113     
114     public void testBasicLookup() {
115         Frame f = Frame.newFrame();
116         System.setProperty("a", "b");
117         assertEquals("b", f.lookup("a"));
118         assertEquals(System.getProperty("java.vendor.url"), f.lookup("java.vendor.url"));
119         assertEquals(System.getProperty("path.separator"), f.lookup("path.separator"));
120     }
121
122     public FrameTest(String JavaDoc name){
123         super(name);
124     }
125
126     protected void setUp() {
127     }
128
129     protected void tearDown() {
130     }
131
132     private void nyi(){
133         fail("Not Yet Implemented");
134     }
135
136     public static void main(String JavaDoc args[]){
137         if (args.length == 0){
138             junit.textui.TestRunner.run(FrameTest.class);
139         } else {
140             junit.textui.TestRunner.run(makeSuite(args));
141         }
142     }
143     private static TestSuite makeSuite(String JavaDoc args[]){
144         final TestSuite ts = new TestSuite();
145         for (int i = 0; i < args.length; i++){
146             ts.addTest(new FrameTest(args[i]));
147         }
148         return ts;
149     }
150 }
151
Popular Tags