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 java.util.Locale;
033:
034: import nextapp.echo2.app.ApplicationInstance;
035: import nextapp.echo2.app.Component;
036: import nextapp.echo2.app.LayoutDirection;
037: import junit.framework.TestCase;
038:
039: /**
040: * Unit tests for <code>nextapp.echo2.app.LayoutDirection</code>.
041: */
042: public class LayoutDirectionTest extends TestCase {
043:
044: private static final Locale ARABIC = new Locale("ar");
045: private static final Locale HEBREW = new Locale("iw");
046: private static final Locale PERSIAN = new Locale("fa");
047: private static final Locale URDU = new Locale("ur");
048:
049: private ColumnApp app;
050:
051: /**
052: * @see junit.framework.TestCase#setUp()
053: */
054: public void setUp() {
055: app = new ColumnApp();
056: ApplicationInstance.setActive(app);
057: app.doInit();
058: }
059:
060: /**
061: * @see junit.framework.TestCase#tearDown()
062: */
063: public void tearDown() {
064: ApplicationInstance.setActive(null);
065: }
066:
067: public void testApplication() {
068: app.setLocale(Locale.US);
069: assertTrue(app.getLayoutDirection().isLeftToRight());
070: app.setLocale(ARABIC);
071: assertFalse(app.getLayoutDirection().isLeftToRight());
072: app.setLocale(Locale.ENGLISH);
073: assertTrue(app.getLayoutDirection().isLeftToRight());
074: app.setLocale(URDU);
075: assertFalse(app.getLayoutDirection().isLeftToRight());
076: app.setLocale(Locale.GERMANY);
077: assertTrue(app.getLayoutDirection().isLeftToRight());
078: app.setLocale(PERSIAN);
079: assertFalse(app.getLayoutDirection().isLeftToRight());
080: app.setLocale(Locale.UK);
081: assertTrue(app.getLayoutDirection().isLeftToRight());
082: app.setLocale(HEBREW);
083: assertFalse(app.getLayoutDirection().isLeftToRight());
084: app.setLocale(Locale.ITALIAN);
085: assertTrue(app.getLayoutDirection().isLeftToRight());
086: }
087:
088: public void testComponentInheritanceFromApplication() {
089: Component component = new NullComponent();
090: assertNull(component.getRenderLayoutDirection());
091:
092: app.getColumn().add(component);
093:
094: app.setLocale(Locale.US);
095: assertTrue(component.getRenderLayoutDirection().isLeftToRight());
096:
097: app.setLocale(ARABIC);
098: assertFalse(component.getRenderLayoutDirection()
099: .isLeftToRight());
100: }
101:
102: public void testComponentInheritanceFromHierarchy() {
103: Component component = new NullComponent();
104: app.getColumn().add(component);
105:
106: app.setLocale(Locale.US);
107: assertTrue(component.getRenderLayoutDirection().isLeftToRight());
108:
109: app.getDefaultWindow().setLocale(ARABIC);
110: assertFalse(component.getRenderLayoutDirection()
111: .isLeftToRight());
112:
113: app.getContentPane().setLocale(Locale.ITALY);
114: assertTrue(component.getRenderLayoutDirection().isLeftToRight());
115:
116: app.getContentPane().setLayoutDirection(LayoutDirection.RTL);
117: assertFalse(component.getRenderLayoutDirection()
118: .isLeftToRight());
119:
120: app.getContentPane().setLayoutDirection(null);
121: assertTrue(component.getRenderLayoutDirection().isLeftToRight());
122:
123: app.getColumn().setLocale(HEBREW);
124: assertFalse(component.getRenderLayoutDirection()
125: .isLeftToRight());
126:
127: app.getColumn().setLayoutDirection(LayoutDirection.LTR);
128: assertTrue(component.getRenderLayoutDirection().isLeftToRight());
129: }
130: }
|