KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jemmyI18NWizard > BasicTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package jemmyI18NWizard;
21
22 import java.io.PrintWriter JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.IOException JavaDoc;
25 import org.netbeans.jemmy.util.PNGEncoder;
26 import org.netbeans.test.oo.gui.jelly.JellyProperties;
27 import org.netbeans.test.oo.gui.jam.JamUtilities;
28
29 import jemmyI18NWizard.wizardSupport.*;
30 import org.netbeans.jemmy.operators.JListOperator;
31
32 import org.netbeans.junit.NbTestCase;
33 import org.netbeans.junit.NbTestSuite;
34 import org.netbeans.test.oo.gui.jam.Jemmy;
35
36
37 /**
38  * <B>What it tests:</B>
39  * Go through Internationalization Wizard. It is the ideal shortest path.
40  * Then it checks new generated items
41  * in resource bundles, internationalized sources and log file.
42  */

43 public class BasicTest extends NbTestCase {
44     
45     
46     public BasicTest(String JavaDoc testName) {
47         super(testName);
48     }
49     
50     
51     public void setUp() {
52         // redirect error and trace messages from Jemmy
53
JellyProperties.setJemmyOutput(new PrintWriter JavaDoc(getLog(), true), new PrintWriter JavaDoc(getLog(), true));
54         JellyProperties.setDefaults();
55     }
56     
57     public void test() {
58         try {
59             log("###### Opening wizard.");
60             Page0 page0 = new Page0();
61             log("###### Wizard opened.");
62             log("###### Removing selected sources.");
63             for(int i=0; i<page0.getItemCount(); i++) {
64                 page0.selectItem(i);
65                 page0.removeSource();
66             }
67             assertEquals("Selected sources list must be empty.", page0.getItemCount(), 0);
68             log("###### Clicking 'Add Source(s)' button.");
69             page0.addSource();
70
71             log("###### Opening 'Select Sources' dialog.");
72             SelectSourcesDialog selSour = new SelectSourcesDialog("Select Sources");
73             log("###### 'Select Sources' dialog opened.");
74             
75             log("###### Selecting testing filesystem.");
76             assertTrue("Filesystem '" + Utilities.getFilesystemPath() +"' not selected.", selSour.selectFilesystem(Utilities.getFilesystemPath()));
77             
78             log("###### Selecting source files in tree.");
79             selSour.selectPath(new String JavaDoc[] {"jemmyI18NWizard", "data", "SimpleMainClass"});
80             
81             log("###### Clicking 'OK' button.");
82             selSour.ok();
83             
84             JamUtilities.waitEventQueueEmpty(500);
85             assertEquals("Source file SimpleMainClass.java not present in list", page0.getItemCount(), 1);
86             page0.selectItem(0);
87             //String selected = page0.getSelectedItem();
88
// use jelly2 here because jelly1 is not reliable
89
Object JavaDoc selected = new JListOperator(Jemmy.getOp(page0), 1).getSelectedValue();
90             assertNotNull("getSelectedValue() returned null.", selected);
91             assertTrue("Source file SimpleMainClass.java not selected", selected.toString().endsWith("SimpleMainClass.java]"));
92             
93             log("###### Clicking 'Next >' button.");
94             page0.next();
95             
96             log("###### Opening second window of wizard.");
97             Page1 page1 = new Page1();
98             log("###### Window succesfully opened.");
99             
100             log("###### Bundle should be selected - continuing to next window.");
101             log("###### Clicking 'Next >' button.");
102             page1.next();
103             
104             log("###### Opening third window.");
105             Page2 page2 = new Page2();
106             log("###### Window succesfully opened.");
107             
108             log("###### Finishing.");
109             log("###### Clicking 'Finish' button.");
110             page2.finish();
111             
112             log("###### Test finished.");
113             log("###### Saving source file.");
114             try {
115                 Utilities.saveFile("jemmyI18NWizard/data/SimpleMainClass.java");
116             } catch(Exception JavaDoc e) {
117                 log("###### Error when saving source files.");
118                 fail("Error saving source file.");
119             }
120             log("###### Source file saved succesfully.");
121             
122             log("###### Saving bundle.");
123             try {
124                 Utilities.saveFile("jemmyI18NWizard/data/Bundle.properties");
125             } catch(Exception JavaDoc e) {
126                 log("###### Error when saving bundle.");
127                 fail("###### Error saving bundle.");
128             }
129             log("###### Bundle saved succesfully.");
130             
131             log("###### Comparing sources.");
132             String JavaDoc sep = File.separator;
133             String JavaDoc dataPath = Utilities.getFilesystemPath()+sep+"jemmyI18NWizard"+sep+"data";
134             assertFile("Generated changes in SimpleMainClass differ.", dataPath+sep+"SimpleMainClass.java", dataPath+sep+"goldenfiles"+sep+"BasicTest"+sep+"SimpleMainClass.pass", getWorkDirPath()+sep+"SimpleMainClass.diff");
135             
136             log("###### Comparing bundles.");
137             
138             if(!Utilities.compareBundles(Utilities.getFilesystemPath()+"/jemmyI18NWizard/data/Bundle.properties"
139             , Utilities.getFilesystemPath()+"/jemmyI18NWizard/data/goldenfiles/BasicTest/Bundle.properties")) {
140                 log("###### Bundles compared succesfully.");
141             } else {
142                 log("###### Error when comparing bundles.");
143                 fail("Error comparing bundles.");
144             }
145             
146         } catch (Exception JavaDoc e) {
147             // save screenshot
148
try {
149                 PNGEncoder.captureScreen(getWorkDirPath()+File.separator+"screen.png");
150             } catch (IOException JavaDoc ioe) {
151                 ioe.printStackTrace();
152             }
153             // print and log exception
154
e.printStackTrace();
155             e.printStackTrace(getLog());
156             fail(e.getMessage());
157         }
158     }
159 }
160
Popular Tags