001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.app.test;
031:
032: import junit.framework.TestCase;
033:
034: import nextapp.echo2.app.Color;
035: import nextapp.echo2.app.ContentPane;
036: import nextapp.echo2.app.IllegalChildException;
037: import nextapp.echo2.app.Label;
038: import nextapp.echo2.app.SplitPane;
039: import nextapp.echo2.app.WindowPane;
040:
041: /**
042: * Unit test(s) for the <code>nextapp.echo2.app.WindowPane</code> component.
043: */
044: public class WindowPaneTest extends TestCase {
045:
046: /**
047: * Test receiving input from client.
048: */
049: public void testInput() {
050: WindowPane windowPane = new WindowPane();
051: windowPane.add(new Label("a label"));
052: windowPane.setPositionX(TestConstants.EXTENT_100_PX);
053: windowPane.setPositionY(TestConstants.EXTENT_100_PX);
054: windowPane.processInput(WindowPane.PROPERTY_POSITION_X,
055: TestConstants.EXTENT_200_PX);
056: windowPane.processInput(WindowPane.PROPERTY_POSITION_Y,
057: TestConstants.EXTENT_30_PX);
058: assertEquals(TestConstants.EXTENT_200_PX, windowPane
059: .getPositionX());
060: assertEquals(TestConstants.EXTENT_30_PX, windowPane
061: .getPositionY());
062: }
063:
064: /**
065: * Attempt to illegally add WindowPane to SplitPane, test for failure.
066: */
067: public void testInvalidParent() {
068: SplitPane splitPane = new SplitPane();
069: WindowPane windowPane = new WindowPane();
070: boolean exceptionThrown = false;
071: try {
072: splitPane.add(windowPane);
073: } catch (IllegalChildException ex) {
074: exceptionThrown = true;
075: }
076: assertTrue(exceptionThrown);
077: }
078:
079: /**
080: * Ensure WindowPane can be legally added to a ContentPane.
081: */
082: public void testValidParent() {
083: ContentPane contentPane = new ContentPane();
084: WindowPane windowPane = new WindowPane();
085: contentPane.add(windowPane);
086: }
087:
088: /**
089: * Attempt to illegally add more than one child, test for failure.
090: */
091: public void testOverload() {
092: WindowPane windowPane = new WindowPane();
093: windowPane.add(new Label("one label"));
094: boolean exceptionThrown = false;
095: try {
096: windowPane.add(new Label("one label too many"));
097: } catch (IllegalChildException ex) {
098: exceptionThrown = true;
099: }
100: assertTrue(exceptionThrown);
101: }
102:
103: /**
104: * Test primary constructor.
105: */
106: public void testPrimaryConstructor() {
107: WindowPane windowPane = new WindowPane("Hello",
108: TestConstants.EXTENT_500_PX,
109: TestConstants.EXTENT_200_PX);
110: assertEquals(TestConstants.EXTENT_500_PX, windowPane.getWidth());
111: assertEquals(TestConstants.EXTENT_200_PX, windowPane
112: .getHeight());
113: assertEquals("Hello", windowPane.getTitle());
114: }
115:
116: /**
117: * Test property accessors and mutators.
118: */
119: public void testProperties() {
120: WindowPane windowPane = new WindowPane();
121: windowPane.setBorder(TestConstants.FILL_IMAGE_BORDER);
122: assertEquals(TestConstants.FILL_IMAGE_BORDER, windowPane
123: .getBorder());
124: windowPane.setHeight(TestConstants.EXTENT_200_PX);
125: assertEquals(TestConstants.EXTENT_200_PX, windowPane
126: .getHeight());
127: windowPane.setPositionX(TestConstants.EXTENT_100_PX);
128: assertEquals(TestConstants.EXTENT_100_PX, windowPane
129: .getPositionX());
130: windowPane.setPositionY(TestConstants.EXTENT_30_PX);
131: assertEquals(TestConstants.EXTENT_30_PX, windowPane
132: .getPositionY());
133: windowPane.setTitle("Title!");
134: assertEquals("Title!", windowPane.getTitle());
135: windowPane.setTitleBackground(Color.ORANGE);
136: assertEquals(Color.ORANGE, windowPane.getTitleBackground());
137: windowPane.setTitleFont(TestConstants.MONOSPACE_12);
138: assertEquals(TestConstants.MONOSPACE_12, windowPane
139: .getTitleFont());
140: windowPane.setTitleForeground(Color.PINK);
141: assertEquals(Color.PINK, windowPane.getTitleForeground());
142: windowPane.setWidth(TestConstants.EXTENT_500_PX);
143: assertEquals(TestConstants.EXTENT_500_PX, windowPane.getWidth());
144: windowPane.setClosable(false);
145: assertFalse(windowPane.isClosable());
146: }
147: }
|