1 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 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); 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); 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); 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); 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 |