001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package jemmyI18NWizard;
043:
044: import java.io.PrintWriter;
045: import java.io.File;
046: import java.io.IOException;
047: import org.netbeans.jemmy.util.PNGEncoder;
048: import org.netbeans.test.oo.gui.jelly.JellyProperties;
049: import org.netbeans.test.oo.gui.jam.JamUtilities;
050:
051: import jemmyI18NWizard.wizardSupport.*;
052: import org.netbeans.jemmy.operators.JListOperator;
053:
054: import org.netbeans.junit.NbTestCase;
055: import org.netbeans.junit.NbTestSuite;
056: import org.netbeans.test.oo.gui.jam.Jemmy;
057:
058: /**
059: * <B>What it tests:</B>
060: * Go through Internationalization Wizard. It is the ideal shortest path.
061: * Then it checks new generated items
062: * in resource bundles, internationalized sources and log file.
063: */
064: public class BasicTest extends NbTestCase {
065:
066: public BasicTest(String testName) {
067: super (testName);
068: }
069:
070: public void setUp() {
071: // redirect error and trace messages from Jemmy
072: JellyProperties.setJemmyOutput(new PrintWriter(getLog(), true),
073: new PrintWriter(getLog(), true));
074: JellyProperties.setDefaults();
075: }
076:
077: public void test() {
078: try {
079: log("###### Opening wizard.");
080: Page0 page0 = new Page0();
081: log("###### Wizard opened.");
082: log("###### Removing selected sources.");
083: for (int i = 0; i < page0.getItemCount(); i++) {
084: page0.selectItem(i);
085: page0.removeSource();
086: }
087: assertEquals("Selected sources list must be empty.", page0
088: .getItemCount(), 0);
089: log("###### Clicking 'Add Source(s)' button.");
090: page0.addSource();
091:
092: log("###### Opening 'Select Sources' dialog.");
093: SelectSourcesDialog selSour = new SelectSourcesDialog(
094: "Select Sources");
095: log("###### 'Select Sources' dialog opened.");
096:
097: log("###### Selecting testing filesystem.");
098: assertTrue("Filesystem '" + Utilities.getFilesystemPath()
099: + "' not selected.", selSour
100: .selectFilesystem(Utilities.getFilesystemPath()));
101:
102: log("###### Selecting source files in tree.");
103: selSour.selectPath(new String[] { "jemmyI18NWizard",
104: "data", "SimpleMainClass" });
105:
106: log("###### Clicking 'OK' button.");
107: selSour.ok();
108:
109: JamUtilities.waitEventQueueEmpty(500);
110: assertEquals(
111: "Source file SimpleMainClass.java not present in list",
112: page0.getItemCount(), 1);
113: page0.selectItem(0);
114: //String selected = page0.getSelectedItem();
115: // use jelly2 here because jelly1 is not reliable
116: Object selected = new JListOperator(Jemmy.getOp(page0), 1)
117: .getSelectedValue();
118: assertNotNull("getSelectedValue() returned null.", selected);
119: assertTrue("Source file SimpleMainClass.java not selected",
120: selected.toString().endsWith(
121: "SimpleMainClass.java]"));
122:
123: log("###### Clicking 'Next >' button.");
124: page0.next();
125:
126: log("###### Opening second window of wizard.");
127: Page1 page1 = new Page1();
128: log("###### Window succesfully opened.");
129:
130: log("###### Bundle should be selected - continuing to next window.");
131: log("###### Clicking 'Next >' button.");
132: page1.next();
133:
134: log("###### Opening third window.");
135: Page2 page2 = new Page2();
136: log("###### Window succesfully opened.");
137:
138: log("###### Finishing.");
139: log("###### Clicking 'Finish' button.");
140: page2.finish();
141:
142: log("###### Test finished.");
143: log("###### Saving source file.");
144: try {
145: Utilities
146: .saveFile("jemmyI18NWizard/data/SimpleMainClass.java");
147: } catch (Exception e) {
148: log("###### Error when saving source files.");
149: fail("Error saving source file.");
150: }
151: log("###### Source file saved succesfully.");
152:
153: log("###### Saving bundle.");
154: try {
155: Utilities
156: .saveFile("jemmyI18NWizard/data/Bundle.properties");
157: } catch (Exception e) {
158: log("###### Error when saving bundle.");
159: fail("###### Error saving bundle.");
160: }
161: log("###### Bundle saved succesfully.");
162:
163: log("###### Comparing sources.");
164: String sep = File.separator;
165: String dataPath = Utilities.getFilesystemPath() + sep
166: + "jemmyI18NWizard" + sep + "data";
167: assertFile("Generated changes in SimpleMainClass differ.",
168: dataPath + sep + "SimpleMainClass.java", dataPath
169: + sep + "goldenfiles" + sep + "BasicTest"
170: + sep + "SimpleMainClass.pass",
171: getWorkDirPath() + sep + "SimpleMainClass.diff");
172:
173: log("###### Comparing bundles.");
174:
175: if (!Utilities
176: .compareBundles(
177: Utilities.getFilesystemPath()
178: + "/jemmyI18NWizard/data/Bundle.properties",
179: Utilities.getFilesystemPath()
180: + "/jemmyI18NWizard/data/goldenfiles/BasicTest/Bundle.properties")) {
181: log("###### Bundles compared succesfully.");
182: } else {
183: log("###### Error when comparing bundles.");
184: fail("Error comparing bundles.");
185: }
186:
187: } catch (Exception e) {
188: // save screenshot
189: try {
190: PNGEncoder.captureScreen(getWorkDirPath()
191: + File.separator + "screen.png");
192: } catch (IOException ioe) {
193: ioe.printStackTrace();
194: }
195: // print and log exception
196: e.printStackTrace();
197: e.printStackTrace(getLog());
198: fail(e.getMessage());
199: }
200: }
201: }
|