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: import nextapp.echo2.app.Color;
034: import nextapp.echo2.app.Extent;
035: import nextapp.echo2.app.IllegalChildException;
036: import nextapp.echo2.app.Label;
037: import nextapp.echo2.app.SplitPane;
038:
039: /**
040: * Unit test(s) for the <code>nextapp.echo2.app.SplitPane</code> component.
041: */
042: public class SplitPaneTest extends TestCase {
043:
044: /**
045: * Test empty constructor and verify default state.
046: */
047: public void testEmptyConstructor() {
048: SplitPane splitPane = new SplitPane();
049: assertNull(splitPane.getSeparatorPosition());
050: assertFalse(splitPane.isResizable());
051: }
052:
053: /**
054: * Test receiving input from client.
055: */
056: public void testInput() {
057: SplitPane splitPane = new SplitPane();
058: splitPane.add(new Label("one label"));
059: splitPane.add(new Label("one more label"));
060: splitPane.setSeparatorPosition(new Extent(80));
061: splitPane.processInput(SplitPane.PROPERTY_SEPARATOR_POSITION,
062: new Extent(212));
063: assertEquals(new Extent(212), splitPane.getSeparatorPosition());
064: }
065:
066: /**
067: * Attempt to illegally add more than two children, tests for failure.
068: */
069: public void testOverload() {
070: SplitPane splitPane = new SplitPane();
071: splitPane.add(new Label("one label"));
072: splitPane.add(new Label("one more label"));
073: boolean exceptionThrown = false;
074: try {
075: splitPane.add(new Label("one label too many"));
076: } catch (IllegalChildException ex) {
077: exceptionThrown = true;
078: }
079: assertTrue(exceptionThrown);
080: }
081:
082: /**
083: * Test primary constructor.
084: */
085: public void testPrimaryConstructor() {
086: SplitPane splitPane;
087: splitPane = new SplitPane(SplitPane.ORIENTATION_VERTICAL,
088: TestConstants.EXTENT_200_PX);
089: assertEquals(SplitPane.ORIENTATION_VERTICAL, splitPane
090: .getOrientation());
091: assertEquals(TestConstants.EXTENT_200_PX, splitPane
092: .getSeparatorPosition());
093:
094: splitPane = new SplitPane(SplitPane.ORIENTATION_HORIZONTAL,
095: TestConstants.EXTENT_500_PX);
096: assertEquals(SplitPane.ORIENTATION_HORIZONTAL, splitPane
097: .getOrientation());
098: assertEquals(TestConstants.EXTENT_500_PX, splitPane
099: .getSeparatorPosition());
100: }
101:
102: /**
103: * Test property accessors and mutators.
104: */
105: public void testProperties() {
106: SplitPane splitPane = new SplitPane();
107: splitPane.setOrientation(SplitPane.ORIENTATION_VERTICAL);
108: assertEquals(SplitPane.ORIENTATION_VERTICAL, splitPane
109: .getOrientation());
110: splitPane.setSeparatorPosition(TestConstants.EXTENT_200_PX);
111: assertEquals(TestConstants.EXTENT_200_PX, splitPane
112: .getSeparatorPosition());
113: splitPane.setSeparatorHeight(TestConstants.EXTENT_30_PX);
114: assertEquals(TestConstants.EXTENT_30_PX, splitPane
115: .getSeparatorHeight());
116: splitPane.setSeparatorWidth(TestConstants.EXTENT_100_PX);
117: assertEquals(TestConstants.EXTENT_100_PX, splitPane
118: .getSeparatorWidth());
119: splitPane.setSeparatorColor(Color.RED);
120: assertEquals(Color.RED, splitPane.getSeparatorColor());
121: splitPane.setResizable(true);
122: assertEquals(true, splitPane.isResizable());
123: splitPane
124: .setSeparatorHorizontalImage(TestConstants.BACKGROUND_IMAGE);
125: assertEquals(TestConstants.BACKGROUND_IMAGE, splitPane
126: .getSeparatorHorizontalImage());
127: splitPane
128: .setSeparatorVerticalImage(TestConstants.BACKGROUND_IMAGE);
129: splitPane.setSeparatorHorizontalImage(null);
130: assertEquals(TestConstants.BACKGROUND_IMAGE, splitPane
131: .getSeparatorVerticalImage());
132: }
133: }
|