KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > webcontainer > test > AlignmentRenderTest


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.webcontainer.test;
31
32 import junit.framework.TestCase;
33 import nextapp.echo2.app.Alignment;
34 import nextapp.echo2.app.Component;
35 import nextapp.echo2.app.LayoutDirection;
36 import nextapp.echo2.webcontainer.propertyrender.AlignmentRender;
37 import nextapp.echo2.webrender.output.CssStyle;
38
39 /**
40  * Unit tests for <code>nextapp.echo2.webcontainer.propertyrender.AlignmentRender</code>
41  */

42 public class AlignmentRenderTest extends TestCase {
43     
44     private class NullComponent extends Component { }
45     
46     public void testHorizontalWithComponentLTR() {
47         Alignment alignment;
48         CssStyle cssStyle = new CssStyle();
49         Component component = new NullComponent();
50         component.setLayoutDirection(LayoutDirection.LTR);
51         
52         alignment = new Alignment(Alignment.DEFAULT, Alignment.DEFAULT);
53         AlignmentRender.renderToStyle(cssStyle, alignment, component);
54         assertNull(cssStyle.getAttribute("text-align"));
55         
56         alignment = new Alignment(Alignment.TOP, Alignment.DEFAULT); // Invalid
57
AlignmentRender.renderToStyle(cssStyle, alignment, component);
58         assertNull(cssStyle.getAttribute("text-align"));
59         
60         alignment = new Alignment(Alignment.LEFT, Alignment.DEFAULT);
61         AlignmentRender.renderToStyle(cssStyle, alignment, component);
62         assertEquals("left", cssStyle.getAttribute("text-align"));
63         
64         alignment = new Alignment(Alignment.CENTER, Alignment.DEFAULT);
65         AlignmentRender.renderToStyle(cssStyle, alignment, component);
66         assertEquals("center", cssStyle.getAttribute("text-align"));
67         
68         alignment = new Alignment(Alignment.RIGHT, Alignment.DEFAULT);
69         AlignmentRender.renderToStyle(cssStyle, alignment, component);
70         assertEquals("right", cssStyle.getAttribute("text-align"));
71
72         alignment = new Alignment(Alignment.LEADING, Alignment.DEFAULT);
73         AlignmentRender.renderToStyle(cssStyle, alignment, component);
74         assertEquals("left", cssStyle.getAttribute("text-align"));
75         
76         alignment = new Alignment(Alignment.TRAILING, Alignment.DEFAULT);
77         AlignmentRender.renderToStyle(cssStyle, alignment, component);
78         assertEquals("right", cssStyle.getAttribute("text-align"));
79     }
80     
81     public void testHorizontalWithComponentRTL() {
82         Alignment alignment;
83         CssStyle cssStyle = new CssStyle();
84         Component component = new NullComponent();
85         component.setLayoutDirection(LayoutDirection.RTL);
86         
87         alignment = new Alignment(Alignment.DEFAULT, Alignment.DEFAULT);
88         AlignmentRender.renderToStyle(cssStyle, alignment, component);
89         assertNull(cssStyle.getAttribute("text-align"));
90         
91         alignment = new Alignment(Alignment.TOP, Alignment.DEFAULT); // Invalid
92
AlignmentRender.renderToStyle(cssStyle, alignment, component);
93         assertNull(cssStyle.getAttribute("text-align"));
94         
95         alignment = new Alignment(Alignment.LEFT, Alignment.DEFAULT);
96         AlignmentRender.renderToStyle(cssStyle, alignment, component);
97         assertEquals("left", cssStyle.getAttribute("text-align"));
98         
99         alignment = new Alignment(Alignment.CENTER, Alignment.DEFAULT);
100         AlignmentRender.renderToStyle(cssStyle, alignment, component);
101         assertEquals("center", cssStyle.getAttribute("text-align"));
102         
103         alignment = new Alignment(Alignment.RIGHT, Alignment.DEFAULT);
104         AlignmentRender.renderToStyle(cssStyle, alignment, component);
105         assertEquals("right", cssStyle.getAttribute("text-align"));
106         
107         alignment = new Alignment(Alignment.TRAILING, Alignment.DEFAULT);
108         AlignmentRender.renderToStyle(cssStyle, alignment, component);
109         assertEquals("left", cssStyle.getAttribute("text-align"));
110
111         alignment = new Alignment(Alignment.LEADING, Alignment.DEFAULT);
112         AlignmentRender.renderToStyle(cssStyle, alignment, component);
113         assertEquals("right", cssStyle.getAttribute("text-align"));
114     }
115     
116     public void testHorizontalWithoutComponent() {
117         Alignment alignment;
118         CssStyle cssStyle = new CssStyle();
119         
120         alignment = new Alignment(Alignment.DEFAULT, Alignment.DEFAULT);
121         AlignmentRender.renderToStyle(cssStyle, alignment);
122         assertNull(cssStyle.getAttribute("text-align"));
123         
124         alignment = new Alignment(Alignment.TOP, Alignment.DEFAULT); // Invalid
125
AlignmentRender.renderToStyle(cssStyle, alignment);
126         assertNull(cssStyle.getAttribute("text-align"));
127         
128         alignment = new Alignment(Alignment.LEFT, Alignment.DEFAULT);
129         AlignmentRender.renderToStyle(cssStyle, alignment);
130         assertEquals("left", cssStyle.getAttribute("text-align"));
131         
132         alignment = new Alignment(Alignment.CENTER, Alignment.DEFAULT);
133         AlignmentRender.renderToStyle(cssStyle, alignment);
134         assertEquals("center", cssStyle.getAttribute("text-align"));
135         
136         alignment = new Alignment(Alignment.RIGHT, Alignment.DEFAULT);
137         AlignmentRender.renderToStyle(cssStyle, alignment);
138         assertEquals("right", cssStyle.getAttribute("text-align"));
139
140         alignment = new Alignment(Alignment.LEADING, Alignment.DEFAULT);
141         AlignmentRender.renderToStyle(cssStyle, alignment);
142         assertEquals("left", cssStyle.getAttribute("text-align"));
143         
144         alignment = new Alignment(Alignment.TRAILING, Alignment.DEFAULT);
145         AlignmentRender.renderToStyle(cssStyle, alignment);
146         assertEquals("right", cssStyle.getAttribute("text-align"));
147     }
148     
149     public void testVertical() {
150         Alignment alignment;
151         CssStyle cssStyle = new CssStyle();
152         
153         alignment = new Alignment(Alignment.DEFAULT, Alignment.DEFAULT);
154         AlignmentRender.renderToStyle(cssStyle, alignment);
155         assertNull(cssStyle.getAttribute("vertical-align"));
156         
157         alignment = new Alignment(Alignment.DEFAULT, Alignment.LEFT); // Invalid
158
AlignmentRender.renderToStyle(cssStyle, alignment);
159         assertNull(cssStyle.getAttribute("vertical-align"));
160         
161         alignment = new Alignment(Alignment.DEFAULT, Alignment.TOP);
162         AlignmentRender.renderToStyle(cssStyle, alignment);
163         assertEquals("top", cssStyle.getAttribute("vertical-align"));
164         
165         alignment = new Alignment(Alignment.DEFAULT, Alignment.CENTER);
166         AlignmentRender.renderToStyle(cssStyle, alignment);
167         assertEquals("middle", cssStyle.getAttribute("vertical-align"));
168         
169         alignment = new Alignment(Alignment.DEFAULT, Alignment.BOTTOM);
170         AlignmentRender.renderToStyle(cssStyle, alignment);
171         assertEquals("bottom", cssStyle.getAttribute("vertical-align"));
172     }
173 }
174
Popular Tags