KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > app > test > WindowPaneTest


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.app.test;
31
32 import junit.framework.TestCase;
33
34 import nextapp.echo2.app.Color;
35 import nextapp.echo2.app.ContentPane;
36 import nextapp.echo2.app.IllegalChildException;
37 import nextapp.echo2.app.Label;
38 import nextapp.echo2.app.SplitPane;
39 import nextapp.echo2.app.WindowPane;
40
41 /**
42  * Unit test(s) for the <code>nextapp.echo2.app.WindowPane</code> component.
43  */

44 public class WindowPaneTest extends TestCase {
45     
46     /**
47      * Test receiving input from client.
48      */

49     public void testInput() {
50         WindowPane windowPane = new WindowPane();
51         windowPane.add(new Label("a label"));
52         windowPane.setPositionX(TestConstants.EXTENT_100_PX);
53         windowPane.setPositionY(TestConstants.EXTENT_100_PX);
54         windowPane.processInput(WindowPane.PROPERTY_POSITION_X, TestConstants.EXTENT_200_PX);
55         windowPane.processInput(WindowPane.PROPERTY_POSITION_Y, TestConstants.EXTENT_30_PX);
56         assertEquals(TestConstants.EXTENT_200_PX, windowPane.getPositionX());
57         assertEquals(TestConstants.EXTENT_30_PX, windowPane.getPositionY());
58     }
59     
60     /**
61      * Attempt to illegally add WindowPane to SplitPane, test for failure.
62      */

63     public void testInvalidParent() {
64         SplitPane splitPane = new SplitPane();
65         WindowPane windowPane = new WindowPane();
66         boolean exceptionThrown = false;
67         try {
68             splitPane.add(windowPane);
69         } catch (IllegalChildException ex) {
70             exceptionThrown = true;
71         }
72         assertTrue(exceptionThrown);
73     }
74     
75     /**
76      * Ensure WindowPane can be legally added to a ContentPane.
77      */

78     public void testValidParent() {
79         ContentPane contentPane = new ContentPane();
80         WindowPane windowPane = new WindowPane();
81         contentPane.add(windowPane);
82     }
83     
84     /**
85      * Attempt to illegally add more than one child, test for failure.
86      */

87     public void testOverload() {
88         WindowPane windowPane = new WindowPane();
89         windowPane.add(new Label("one label"));
90         boolean exceptionThrown = false;
91         try {
92             windowPane.add(new Label("one label too many"));
93         } catch (IllegalChildException ex) {
94             exceptionThrown = true;
95         }
96         assertTrue(exceptionThrown);
97     }
98     
99     /**
100      * Test primary constructor.
101      */

102     public void testPrimaryConstructor() {
103         WindowPane windowPane = new WindowPane("Hello", TestConstants.EXTENT_500_PX, TestConstants.EXTENT_200_PX);
104         assertEquals(TestConstants.EXTENT_500_PX, windowPane.getWidth());
105         assertEquals(TestConstants.EXTENT_200_PX, windowPane.getHeight());
106         assertEquals("Hello", windowPane.getTitle());
107     }
108     
109     /**
110      * Test property accessors and mutators.
111      */

112     public void testProperties() {
113         WindowPane windowPane = new WindowPane();
114         windowPane.setBorder(TestConstants.FILL_IMAGE_BORDER);
115         assertEquals(TestConstants.FILL_IMAGE_BORDER, windowPane.getBorder());
116         windowPane.setHeight(TestConstants.EXTENT_200_PX);
117         assertEquals(TestConstants.EXTENT_200_PX, windowPane.getHeight());
118         windowPane.setPositionX(TestConstants.EXTENT_100_PX);
119         assertEquals(TestConstants.EXTENT_100_PX, windowPane.getPositionX());
120         windowPane.setPositionY(TestConstants.EXTENT_30_PX);
121         assertEquals(TestConstants.EXTENT_30_PX, windowPane.getPositionY());
122         windowPane.setTitle("Title!");
123         assertEquals("Title!", windowPane.getTitle());
124         windowPane.setTitleBackground(Color.ORANGE);
125         assertEquals(Color.ORANGE, windowPane.getTitleBackground());
126         windowPane.setTitleFont(TestConstants.MONOSPACE_12);
127         assertEquals(TestConstants.MONOSPACE_12, windowPane.getTitleFont());
128         windowPane.setTitleForeground(Color.PINK);
129         assertEquals(Color.PINK, windowPane.getTitleForeground());
130         windowPane.setWidth(TestConstants.EXTENT_500_PX);
131         assertEquals(TestConstants.EXTENT_500_PX, windowPane.getWidth());
132         windowPane.setClosable(false);
133         assertFalse(windowPane.isClosable());
134     }
135 }
136
Popular Tags