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.webcontainer.test;
031:
032: import junit.framework.TestCase;
033: import nextapp.echo2.app.Alignment;
034: import nextapp.echo2.app.Component;
035: import nextapp.echo2.app.LayoutDirection;
036: import nextapp.echo2.webcontainer.propertyrender.AlignmentRender;
037: import nextapp.echo2.webrender.output.CssStyle;
038:
039: /**
040: * Unit tests for <code>nextapp.echo2.webcontainer.propertyrender.AlignmentRender</code>
041: */
042: public class AlignmentRenderTest extends TestCase {
043:
044: private class NullComponent extends Component {
045: }
046:
047: public void testHorizontalWithComponentLTR() {
048: Alignment alignment;
049: CssStyle cssStyle = new CssStyle();
050: Component component = new NullComponent();
051: component.setLayoutDirection(LayoutDirection.LTR);
052:
053: alignment = new Alignment(Alignment.DEFAULT, Alignment.DEFAULT);
054: AlignmentRender.renderToStyle(cssStyle, alignment, component);
055: assertNull(cssStyle.getAttribute("text-align"));
056:
057: alignment = new Alignment(Alignment.TOP, Alignment.DEFAULT); // Invalid
058: AlignmentRender.renderToStyle(cssStyle, alignment, component);
059: assertNull(cssStyle.getAttribute("text-align"));
060:
061: alignment = new Alignment(Alignment.LEFT, Alignment.DEFAULT);
062: AlignmentRender.renderToStyle(cssStyle, alignment, component);
063: assertEquals("left", cssStyle.getAttribute("text-align"));
064:
065: alignment = new Alignment(Alignment.CENTER, Alignment.DEFAULT);
066: AlignmentRender.renderToStyle(cssStyle, alignment, component);
067: assertEquals("center", cssStyle.getAttribute("text-align"));
068:
069: alignment = new Alignment(Alignment.RIGHT, Alignment.DEFAULT);
070: AlignmentRender.renderToStyle(cssStyle, alignment, component);
071: assertEquals("right", cssStyle.getAttribute("text-align"));
072:
073: alignment = new Alignment(Alignment.LEADING, Alignment.DEFAULT);
074: AlignmentRender.renderToStyle(cssStyle, alignment, component);
075: assertEquals("left", cssStyle.getAttribute("text-align"));
076:
077: alignment = new Alignment(Alignment.TRAILING, Alignment.DEFAULT);
078: AlignmentRender.renderToStyle(cssStyle, alignment, component);
079: assertEquals("right", cssStyle.getAttribute("text-align"));
080: }
081:
082: public void testHorizontalWithComponentRTL() {
083: Alignment alignment;
084: CssStyle cssStyle = new CssStyle();
085: Component component = new NullComponent();
086: component.setLayoutDirection(LayoutDirection.RTL);
087:
088: alignment = new Alignment(Alignment.DEFAULT, Alignment.DEFAULT);
089: AlignmentRender.renderToStyle(cssStyle, alignment, component);
090: assertNull(cssStyle.getAttribute("text-align"));
091:
092: alignment = new Alignment(Alignment.TOP, Alignment.DEFAULT); // Invalid
093: AlignmentRender.renderToStyle(cssStyle, alignment, component);
094: assertNull(cssStyle.getAttribute("text-align"));
095:
096: alignment = new Alignment(Alignment.LEFT, Alignment.DEFAULT);
097: AlignmentRender.renderToStyle(cssStyle, alignment, component);
098: assertEquals("left", cssStyle.getAttribute("text-align"));
099:
100: alignment = new Alignment(Alignment.CENTER, Alignment.DEFAULT);
101: AlignmentRender.renderToStyle(cssStyle, alignment, component);
102: assertEquals("center", cssStyle.getAttribute("text-align"));
103:
104: alignment = new Alignment(Alignment.RIGHT, Alignment.DEFAULT);
105: AlignmentRender.renderToStyle(cssStyle, alignment, component);
106: assertEquals("right", cssStyle.getAttribute("text-align"));
107:
108: alignment = new Alignment(Alignment.TRAILING, Alignment.DEFAULT);
109: AlignmentRender.renderToStyle(cssStyle, alignment, component);
110: assertEquals("left", cssStyle.getAttribute("text-align"));
111:
112: alignment = new Alignment(Alignment.LEADING, Alignment.DEFAULT);
113: AlignmentRender.renderToStyle(cssStyle, alignment, component);
114: assertEquals("right", cssStyle.getAttribute("text-align"));
115: }
116:
117: public void testHorizontalWithoutComponent() {
118: Alignment alignment;
119: CssStyle cssStyle = new CssStyle();
120:
121: alignment = new Alignment(Alignment.DEFAULT, Alignment.DEFAULT);
122: AlignmentRender.renderToStyle(cssStyle, alignment);
123: assertNull(cssStyle.getAttribute("text-align"));
124:
125: alignment = new Alignment(Alignment.TOP, Alignment.DEFAULT); // Invalid
126: AlignmentRender.renderToStyle(cssStyle, alignment);
127: assertNull(cssStyle.getAttribute("text-align"));
128:
129: alignment = new Alignment(Alignment.LEFT, Alignment.DEFAULT);
130: AlignmentRender.renderToStyle(cssStyle, alignment);
131: assertEquals("left", cssStyle.getAttribute("text-align"));
132:
133: alignment = new Alignment(Alignment.CENTER, Alignment.DEFAULT);
134: AlignmentRender.renderToStyle(cssStyle, alignment);
135: assertEquals("center", cssStyle.getAttribute("text-align"));
136:
137: alignment = new Alignment(Alignment.RIGHT, Alignment.DEFAULT);
138: AlignmentRender.renderToStyle(cssStyle, alignment);
139: assertEquals("right", cssStyle.getAttribute("text-align"));
140:
141: alignment = new Alignment(Alignment.LEADING, Alignment.DEFAULT);
142: AlignmentRender.renderToStyle(cssStyle, alignment);
143: assertEquals("left", cssStyle.getAttribute("text-align"));
144:
145: alignment = new Alignment(Alignment.TRAILING, Alignment.DEFAULT);
146: AlignmentRender.renderToStyle(cssStyle, alignment);
147: assertEquals("right", cssStyle.getAttribute("text-align"));
148: }
149:
150: public void testVertical() {
151: Alignment alignment;
152: CssStyle cssStyle = new CssStyle();
153:
154: alignment = new Alignment(Alignment.DEFAULT, Alignment.DEFAULT);
155: AlignmentRender.renderToStyle(cssStyle, alignment);
156: assertNull(cssStyle.getAttribute("vertical-align"));
157:
158: alignment = new Alignment(Alignment.DEFAULT, Alignment.LEFT); // Invalid
159: AlignmentRender.renderToStyle(cssStyle, alignment);
160: assertNull(cssStyle.getAttribute("vertical-align"));
161:
162: alignment = new Alignment(Alignment.DEFAULT, Alignment.TOP);
163: AlignmentRender.renderToStyle(cssStyle, alignment);
164: assertEquals("top", cssStyle.getAttribute("vertical-align"));
165:
166: alignment = new Alignment(Alignment.DEFAULT, Alignment.CENTER);
167: AlignmentRender.renderToStyle(cssStyle, alignment);
168: assertEquals("middle", cssStyle.getAttribute("vertical-align"));
169:
170: alignment = new Alignment(Alignment.DEFAULT, Alignment.BOTTOM);
171: AlignmentRender.renderToStyle(cssStyle, alignment);
172: assertEquals("bottom", cssStyle.getAttribute("vertical-align"));
173: }
174: }
|