|
What this is
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 org.netbeans.test.db; import java.util.Random; import junit.textui.TestRunner; import org.netbeans.jellytools.modules.db.AddJDBCDriverOperator; import org.netbeans.jellytools.modules.db.ConfirmObjectDeletionOperator; import org.netbeans.jellytools.modules.db.DBJellyTestCase; import org.netbeans.jellytools.modules.db.nodes.DriverNode; import org.netbeans.jellytools.modules.db.nodes.DriversNode; import org.netbeans.jemmy.JemmyProperties; import org.netbeans.junit.NbTestSuite; /** * This test tests add/remove database driver * * @author Patrik Knakal * @version 1.0 */ public class DBExplorerDriverTest extends DBJellyTestCase { /* * This static initializer is necessary for setting up driver name operating with. * There is not possible to use it within setUp() method, because this method is * called for each testcase ant there is necessary to have unique name for all tests. */ static { DB_DRIVER_NAME = new String(System.getProperty("db.drivername") + (new Random()).nextInt() ); //NOI18N } /** * Necessary constructor. */ public DBExplorerDriverTest(String name) { super(name); } /** */ public static NbTestSuite suite() { //NbTestSuite suite = new NbTestSuite(class); NbTestSuite suite = new NbTestSuite(); suite.addTest(new DBExplorerDriverTest("testAddDriver")); //NOI18N suite.addTest(new DBExplorerDriverTest("testDeleteDriver")); //NOI18N return suite; } /** * This method adds a new driver node to drivers pool. Firstly checks existence * of the driver node. If the node wasn't added then throws an exception. */ public void testAddDriver() { try { DriversNode driversNode = DriversNode.getInstance(); debug("DriversNode created"); //NOI18N //should never happen if (driversNode.containsChild(DB_DRIVER_NAME) ) { throw new Exception("Driver with specified name already exists: " + DB_DRIVER_NAME ); //NOI18N } driversNode.addDriver(); debug("Add Driver action called"); //NOI18N AddJDBCDriverOperator addDriverOperator = new AddJDBCDriverOperator(); debug("AddJDBCDriverOperator created"); //NOI18N addDriverOperator.typeName(DB_DRIVER_NAME); debug("Driver name typed"); //NOI18N addDriverOperator.typeDriver(DB_DRIVER_CLASS); debug("Driver class typed"); //NOI18N addDriverOperator.typeDatabaseURLPrefix(DB_URL_PREFIX); debug("Driver URL prefix typed"); //NOI18N addDriverOperator.oK(); debug("OK button pressed"); //NOI18N if (!driversNode.containsChild(DB_DRIVER_NAME) ) { //NOI18N throw new Exception("Driver wasn't added"); //NOI18N } } catch (Exception exc) { System.out.println("Exception in 'testAddDriver' method:\n\t"); //NOI18N exc.printStackTrace(); fail(exc); } } /** * Delete specified driver node. If the node doesn't exist then throws an exception. * If the node wasn't deleted (or exists more then once) throws an exception. */ public void testDeleteDriver() { try { DriversNode driversNode = DriversNode.getInstance(); debug("DriversNode created"); //NOI18N //if the specified node doesn't exist there is nothing to delete if (!driversNode.containsChild(DB_DRIVER_NAME) ) { throw new Exception("Specified driver node doesn't exist. Expected driver name: '" + DB_DRIVER_NAME + "'"); //NOI18N } DriverNode driverNode = driversNode.getDriver(DB_DRIVER_NAME); debug("DriverNode created"); //NOI18N driverNode.delete(); debug("'Delete' action called"); //NOI18N ConfirmObjectDeletionOperator deleteOperator = new ConfirmObjectDeletionOperator(); debug("ConfirmObjectDeletionOperator created"); //NOI18N deleteOperator.yes(); debug("Yes button pressed"); //NOI18N //if the specified node exists, it wasn't deleted correctly or the node was added more then once if (driversNode.containsChild(DB_DRIVER_NAME) ) { throw new Exception("Driver wasn't deleted or exists nore then once."); //NOI18N } } catch (Exception exc) { System.out.println("Exception in 'testDelete' method:\n\t"); //NOI18N exc.printStackTrace(); fail(exc); } } /** * Use for execution inside IDE */ public static void main(java.lang.String[] args) throws Exception { DEBUG = true; System.setProperty("xmltest.dbgTimeouts", "true"); JemmyProperties.getCurrentTimeouts().loadDebugTimeouts(); TestRunner.run(suite()); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.