alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package jemmyI18NWizard;

import java.io.PrintWriter;
import java.io.File;
import java.io.IOException;
import org.netbeans.jemmy.util.PNGEncoder;
import org.netbeans.test.oo.gui.jelly.JellyProperties;
import org.netbeans.test.oo.gui.jam.JamUtilities;

import jemmyI18NWizard.wizardSupport.*;
import org.netbeans.jemmy.operators.JListOperator;

import org.netbeans.junit.NbTestCase;
import org.netbeans.junit.NbTestSuite;
import org.netbeans.test.oo.gui.jam.Jemmy;


/**
 * What it tests:
 * Go through Internationalization Wizard. It is the ideal shortest path.
 * Then it checks new generated items
 * in resource bundles, internationalized sources and log file.
 */
public class BasicTest extends NbTestCase {
    
    
    public BasicTest(String testName) {
        super(testName);
    }
    
    
    public static void main(String[] args) {
        junit.textui.TestRunner.run(new NbTestSuite(BasicTest.class));
    }
    
    public void setUp() {
        // redirect error and trace messages from Jemmy
        JellyProperties.setJemmyOutput(new PrintWriter(getLog(), true), new PrintWriter(getLog(), true));
        JellyProperties.setDefaults();
    }
    
    public void test() {
        try {
            log("###### Opening wizard.");
            Page0 page0 = new Page0();
            log("###### Wizard opened.");
            log("###### Removing selected sources.");
            for(int i=0; i' button.");
            page0.next();
            
            log("###### Opening second window of wizard.");
            Page1 page1 = new Page1();
            log("###### Window succesfully opened.");
            
            log("###### Bundle should be selected - continuing to next window.");
            log("###### Clicking 'Next >' button.");
            page1.next();
            
            log("###### Opening third window.");
            Page2 page2 = new Page2();
            log("###### Window succesfully opened.");
            
            log("###### Finishing.");
            log("###### Clicking 'Finish' button.");
            page2.finish();
            
            log("###### Test finished.");
            log("###### Saving source file.");
            try {
                Utilities.saveFile("jemmyI18NWizard/data/SimpleMainClass.java");
            } catch(Exception e) {
                log("###### Error when saving source files.");
                fail("Error saving source file.");
            }
            log("###### Source file saved succesfully.");
            
            log("###### Saving bundle.");
            try {
                Utilities.saveFile("jemmyI18NWizard/data/Bundle.properties");
            } catch(Exception e) {
                log("###### Error when saving bundle.");
                fail("###### Error saving bundle.");
            }
            log("###### Bundle saved succesfully.");
            
            log("###### Comparing sources.");
            String sep = File.separator;
            String dataPath = Utilities.getFilesystemPath()+sep+"jemmyI18NWizard"+sep+"data";
            assertFile("Generated changes in SimpleMainClass differ.", dataPath+sep+"SimpleMainClass.java", dataPath+sep+"goldenfiles"+sep+"BasicTest"+sep+"SimpleMainClass.pass", getWorkDirPath()+sep+"SimpleMainClass.diff");
            
            log("###### Comparing bundles.");
            
            if(!Utilities.compareBundles(Utilities.getFilesystemPath()+"/jemmyI18NWizard/data/Bundle.properties"
            , Utilities.getFilesystemPath()+"/jemmyI18NWizard/data/goldenfiles/BasicTest/Bundle.properties"))  {
                log("###### Bundles compared succesfully.");
            } else {
                log("###### Error when comparing bundles.");
                fail("Error comparing bundles.");
            }
            
        } catch (Exception e) {
            // save screenshot
            try {
                PNGEncoder.captureScreen(getWorkDirPath()+File.separator+"screen.png");
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
            // print and log exception
            e.printStackTrace();
            e.printStackTrace(getLog());
            fail(e.getMessage());
        }
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.