Author: jpeterka
Date: 2010-11-12 04:53:22 -0500 (Fri, 12 Nov 2010)
New Revision: 26496
Added:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/conf/
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/conf/db-multi.properties
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/conf/db-sample.properties
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/resources/drv/
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/resources/drv/hsqldb.jar
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/StopDBServer.java
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/META-INF/MANIFEST.MF
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/DBBean.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfiguration.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/PrepareDB.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/RequirementBase.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/DatabaseHelper.java
Log:
DB requirement support for internal hsqldb added
Database requirements updated
Modified: trunk/tests/plugins/org.jboss.tools.ui.bot.ext/META-INF/MANIFEST.MF
===================================================================
--- trunk/tests/plugins/org.jboss.tools.ui.bot.ext/META-INF/MANIFEST.MF 2010-11-12
09:52:06 UTC (rev 26495)
+++ trunk/tests/plugins/org.jboss.tools.ui.bot.ext/META-INF/MANIFEST.MF 2010-11-12
09:53:22 UTC (rev 26496)
@@ -27,7 +27,8 @@
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Eclipse-RegisterBuddy: org.apache.log4j
-Export-Package: org.jboss.tools.ui.bot.ext,
+Export-Package: org.hsqldb,
+ org.jboss.tools.ui.bot.ext,
org.jboss.tools.ui.bot.ext.config,
org.jboss.tools.ui.bot.ext.config.requirement,
org.jboss.tools.ui.bot.ext.entity,
@@ -40,5 +41,6 @@
org.jboss.tools.ui.bot.ext.widgets,
org.jboss.tools.ui.bot.ext.zest
Bundle-Vendor: JBoss by Red Hat
-Bundle-ClassPath: .
+Bundle-ClassPath: .,
+ resources/drv/hsqldb.jar
Import-Package: org.eclipse.gef
Added: trunk/tests/plugins/org.jboss.tools.ui.bot.ext/conf/db-multi.properties
===================================================================
--- trunk/tests/plugins/org.jboss.tools.ui.bot.ext/conf/db-multi.properties
(rev 0)
+++ trunk/tests/plugins/org.jboss.tools.ui.bot.ext/conf/db-multi.properties 2010-11-12
09:53:22 UTC (rev 26496)
@@ -0,0 +1,4 @@
+# multi-properties file sample
+# <property name - configuration name>=<config properties file>
+HSQLDB=/home/user/etc/hsql-bot.properties
+HSQLDBINT=/home/user/etc/hsql-int-bot.properties
\ No newline at end of file
Property changes on:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/conf/db-multi.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/tests/plugins/org.jboss.tools.ui.bot.ext/conf/db-sample.properties
===================================================================
--- trunk/tests/plugins/org.jboss.tools.ui.bot.ext/conf/db-sample.properties
(rev 0)
+++ trunk/tests/plugins/org.jboss.tools.ui.bot.ext/conf/db-sample.properties 2010-11-12
09:53:22 UTC (rev 26496)
@@ -0,0 +1,7 @@
+#DB Definition
+#DB=<db_type>,<version>,<driver_path>,<jdbc_string>,<username>,[<password>,<scriptpath>]
+#Supported types: hsqldb18, db2_97, mssql2005, mssql2008, mysql50, mysql51, oracle10g,
oracle11gR1, oracle11gR1RAC, oracle11gR2, oracle11gR2RAC, postgresql82, postgresql83,
postgresql84, sybase15
+#For internal: hsqldb18
+DB=hsqldb18,internal,driver,jdbc,user,,
+#For external
+DB=hsqldb18,1.8,/home/user/lib/hsqldb/lib/hsqldb.jar,jdbc:hsqldb:hsql://localhost:8001/xdb,sa,,
Property changes on:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/conf/db-sample.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/tests/plugins/org.jboss.tools.ui.bot.ext/resources/drv/hsqldb.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/resources/drv/hsqldb.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java 2010-11-12
09:52:06 UTC (rev 26495)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java 2010-11-12
09:53:22 UTC (rev 26496)
@@ -274,6 +274,7 @@
.info("All tests finished, performing cleanup requirements ");
try {
RequirementBase.createStopServer().fulfill();
+ RequirementBase.createStopDBServer().fulfill();
log.info("All cleanup requirements performed");
} catch (Exception ex) {
@@ -356,5 +357,4 @@
ExcludeCategory annotation= klass.getAnnotation(ExcludeCategory.class);
return annotation == null ? null : annotation.value();
}
-
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/DBBean.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/DBBean.java 2010-11-12
09:52:06 UTC (rev 26495)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/DBBean.java 2010-11-12
09:53:22 UTC (rev 26496)
@@ -2,6 +2,9 @@
import static org.junit.Assert.fail;
+import java.io.File;
+
+import org.eclipse.core.runtime.Platform;
import org.jboss.tools.ui.bot.ext.helper.DatabaseHelper.DBType;
/**
@@ -12,9 +15,13 @@
public class DBBean {
public String version;
public String jdbcString;
+ public String username;
+ public String password;
public String driverPath;
public String scriptPath;
public DBType dbType;
+ public String name;
+ public boolean internal = true;
public static DBBean fromString(String propValue) throws Exception{
try {
@@ -27,9 +34,33 @@
bean.version = dbParams[1];
bean.driverPath=dbParams[2];
bean.jdbcString=dbParams[3];
- bean.scriptPath=dbParams[4];
-
+ bean.username=dbParams[4];
+ // optional
+ try {
+ bean.password=dbParams[5];
+ } catch (Exception ex) {
+ bean.password = "";
+ }
+ try {
+ bean.scriptPath=dbParams[6];
+ } catch (Exception ex) {
+ bean.scriptPath= "";
+ }
+ bean.name=bean.dbType.toString() + "_" + bean.version;
+ // Internal version
+ if (bean.version.equalsIgnoreCase("internal")) {
+ bean.internal = true;
+ bean.version="1.8";
+ bean.internal = true;
+ bean.driverPath = Platform.getLocation() + File.separator + "hsqldb.jar";
+ bean.jdbcString = "jdbc:hsqldb:hsql://localhost/xdb";
+ bean.username = "sa";
+ bean.password = "";
+ } else {
+ bean.internal = false;
+ }
+
return bean;
}
catch (Exception ex) {
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfiguration.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfiguration.java 2010-11-12
09:52:06 UTC (rev 26495)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfiguration.java 2010-11-12
09:53:22 UTC (rev 26496)
@@ -85,8 +85,10 @@
if (jbpm != null)
checkDirExists(jbpm.jbpmHome);
if (db != null) {
- checkFileExists(db.driverPath);
- checkFileExists(db.scriptPath);
+ if (!db.internal)
+ checkFileExists(db.driverPath);
+ if (!db.scriptPath.isEmpty())
+ checkFileExists(db.scriptPath);
}
// special checks capturing dependency of server on java
if (java == null
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/PrepareDB.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/PrepareDB.java 2010-11-12
09:52:06 UTC (rev 26495)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/PrepareDB.java 2010-11-12
09:53:22 UTC (rev 26496)
@@ -1,5 +1,7 @@
package org.jboss.tools.ui.bot.ext.config.requirement;
+import static org.junit.Assert.fail;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
@@ -18,37 +20,70 @@
@Override
public boolean checkFulfilled() {
- return SWTTestExt.configuredState.getDB().isConfigured;
+ return SWTTestExt.configuredState.getDB().isConfigured
+ &&
SWTTestExt.configuredState.getDB().name.equals(TestConfigurator.currentConfig.getDB().name);
}
@Override
public void handle() {
TestConfiguration configuration = TestConfigurator.currentConfig;
- // Define Driver Entity
+ // For internal hsqldb
+ if (configuration.getDB().internal) {
+ try {
+ DatabaseHelper.addDriverIntoWorkspace();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ Assert.fail("DB driver not found" + e);
+ } catch (IOException e) {
+ e.printStackTrace();
+ Assert.fail("Unable to copy driver" + e);
+ }
+ DatabaseHelper.startHSQLDBServer("mydb", "xdb");
+ }
+
+ // Define Driver Entity and create driver
DriverEntity entity = new DriverEntity();
entity.setDrvPath(configuration.getDB().driverPath);
entity.setJdbcString(configuration.getDB().jdbcString);
- entity.setProfileName(configuration.getDB().dbType.toString());
- entity.setUser("sa");
- entity.setPassword("");
+ entity.setProfileName(configuration.getDB().name);
+ entity.setUser(configuration.getDB().username);
+ entity.setPassword(configuration.getDB().password);
entity.setDriverTemplateDescId(DatabaseHelper.getDriverTemplate(configuration.getDB().dbType));
try {
DatabaseHelper.createDriver(entity);
} catch (ConnectionProfileException e) {
log.error("Unable to create HSQL Driver" + e);
- Assert.fail();
+ Assert.fail("Unable to create HSQL Driver");
}
- File file = new File(configuration.getDB().scriptPath);
+ if (!configuration.getDB().scriptPath.isEmpty()) {
+ // Read script
+ StringBuilder builder = readScript(configuration.getDB().scriptPath);
+
+ // Open editor and run script
+ DatabaseHelper.openSQLEditor(configuration.getDB().dbType,
configuration.getDB().name.toString(), "Default" );
+ DatabaseHelper.runSQLScript(builder.toString());
+ }
+
+ log.info("DB Prepared");
+
+ // Update Configured State
+ SWTTestExt.configuredState.getDB().isConfigured=true;
+ SWTTestExt.configuredState.getDB().name=TestConfigurator.currentConfig.getDB().name;
+ SWTTestExt.configuredState.getDB().version=TestConfigurator.currentConfig.getDB().version;
+ }
+
+ private StringBuilder readScript(String path) {
+ File file = new File(path);
StringBuilder builder = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
} catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
+ Assert.fail("Unable to read script " + file.getAbsolutePath());
}
while(true) {
String line = null;
@@ -56,17 +91,12 @@
line = reader.readLine();
if (line == null) break;
} catch (IOException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
+ fail("Can't read script" + file.getAbsolutePath());
}
builder.append(line);
- }
- DatabaseHelper.openSQLEditor(configuration.getDB().dbType,
configuration.getDB().dbType.toString(), "Default" );
- DatabaseHelper.runSQLScript(builder.toString());
-
- if (configuration.getDB().dbType.equals("HSQLDB_1.8")) {
- // TODO
- }
+ }
+ return builder;
}
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/RequirementBase.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/RequirementBase.java 2010-11-12
09:52:06 UTC (rev 26495)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/RequirementBase.java 2010-11-12
09:53:22 UTC (rev 26496)
@@ -168,4 +168,8 @@
return req;
}
+ public static RequirementBase createStopDBServer() {
+ RequirementBase req = new StopDBServer();
+ return req;
+ }
}
Added:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/StopDBServer.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/StopDBServer.java
(rev 0)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/StopDBServer.java 2010-11-12
09:53:22 UTC (rev 26496)
@@ -0,0 +1,19 @@
+package org.jboss.tools.ui.bot.ext.config.requirement;
+
+import org.jboss.tools.ui.bot.ext.config.TestConfigurator;
+import org.jboss.tools.ui.bot.ext.helper.DatabaseHelper;
+
+public class StopDBServer extends RequirementBase {
+
+ @Override
+ public boolean checkFulfilled() {
+ if (TestConfigurator.currentConfig.getDB().internal &&
DatabaseHelper.isHSQLDBRunning())
+ return false;
+ return true;
+ }
+
+ @Override
+ public void handle() {
+ DatabaseHelper.stopHSQLDBServer();
+ }
+}
Property changes on:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/StopDBServer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/DatabaseHelper.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/DatabaseHelper.java 2010-11-12
09:52:06 UTC (rev 26495)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/DatabaseHelper.java 2010-11-12
09:53:22 UTC (rev 26496)
@@ -4,11 +4,21 @@
import static org.junit.Assert.fail;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.nio.channels.FileChannel;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
import java.util.Properties;
+import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.datatools.connectivity.ConnectionProfileConstants;
import org.eclipse.datatools.connectivity.ConnectionProfileException;
@@ -28,15 +38,19 @@
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.IViewReference;
import org.hamcrest.Matcher;
+import org.hsqldb.Server;
import org.jboss.tools.ui.bot.ext.Activator;
import org.jboss.tools.ui.bot.ext.SWTEclipseExt;
+import org.jboss.tools.ui.bot.ext.SWTUtilExt;
import org.jboss.tools.ui.bot.ext.types.DriverEntity;
import org.jboss.tools.ui.bot.ext.types.PerspectiveType;
import org.jboss.tools.ui.bot.ext.types.ViewType;
public class DatabaseHelper {
-
+
public static int SLEEP = 1000;
+ public static Logger log = Logger.getLogger(DatabaseHelper.class);
+ private static boolean hsqlRunning;
/**
* Create HSQLDB Driver
@@ -49,7 +63,7 @@
driverPath = new File(entity.getDrvPath()).getCanonicalPath(); //$NON-NLS-1$
} catch (IOException e) {
Activator.getDefault().getLog().log(new Status(IStatus.ERROR,
- Activator.PLUGIN_ID, "Can't create driver", e));
+ Activator.PLUGIN_ID, "Can't get driver' path", e));
return;
}
@@ -157,8 +171,8 @@
editor.toTextEditor().setText(script);
// Execute Script and close
- bot.editorByTitle("SQL Scrapbook 0").toTextEditor()
- .contextMenu("Execute All").click();
+ editor.toTextEditor().contextMenu("Execute All").click();
+ editor.toTextEditor().setText("");
editor.close();
bot.sleep(SLEEP);
}
@@ -172,7 +186,7 @@
public enum DBType {
hsqldb18, db2_97, mssql2005, mssql2008, mysql50, mysql51, oracle10g, oracle11gR1,
oracle11gR1RAC, oracle11gR2, oracle11gR2RAC, postgresql82, postgresql83, postgresql84,
sybase15
}
-
+
/**
* Return driver template for creating new connection
*
@@ -272,4 +286,90 @@
}
return ret;
}
+
+ /**
+ * Run HSQLDB database in server mode
+ * @param file
+ * @param dbname
+ */
+ public static void startHSQLDBServer(final String file, final String dbname) {
+ Thread hsqlThread = null;
+ log.info("Starting HSQLDB...");
+ try {
+ Class.forName("org.hsqldb.jdbcDriver");
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Runnable runable = new Runnable() {
+
+ public void run() {
+ Server.main(new String[] {"-database.0","file:" +
file,"-dbname.0",dbname });
+ }
+ };
+
+ hsqlThread = new Thread(runable);
+ hsqlThread.start();
+ hsqlRunning = true;
+ log.info("HSQLDB started");
+ }
+
+ /**
+ * Stop HSQL Database by sending SHUTDOWN command
+ */
+ public static void stopHSQLDBServer() {
+ if (!hsqlRunning) return;
+
+ try {
+ Class.forName("org.hsqldb.jdbcDriver");
+
+ Connection connection =
java.sql.DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/xdb");
+
+ Statement statement = connection.createStatement();
+ ResultSet resultset = statement.executeQuery("SHUTDOWN");
+
+ resultset.close();
+ statement.close();
+ connection.close();
+
+ hsqlRunning = false;
+ log.error("Internal hql server stopped");
+
+
+ } catch (SQLException e) {
+
+ }
+ catch (ClassNotFoundException e) {
+ log.error("Unable to stop HSQLDB " + e);
+ }
+ }
+
+ /**
+ * Returns flag refering if HSQLDB is running
+ */
+ public static boolean isHSQLDBRunning() {
+ return hsqlRunning;
+ }
+
+ /**
+ * Add HSQLDB driver into project
+ * @throws FileNotFoundException
+ * @throws IOException
+ */
+ public static void addDriverIntoWorkspace() throws FileNotFoundException, IOException {
+ File in = SWTUtilExt.getResourceFile(Activator.PLUGIN_ID,
"drv","hsqldb.jar");
+ File out = new File(Platform.getLocation() + File.separator + "hsqldb.jar");
+
+ FileChannel inChannel = null;
+ FileChannel outChannel = null;
+
+ inChannel = new FileInputStream(in).getChannel();
+ outChannel = new FileOutputStream(out).getChannel();
+
+ inChannel.transferTo(0, inChannel.size(), outChannel);
+
+ if (inChannel != null) inChannel.close();
+ if (outChannel != null) outChannel.close();
+ log.info("Driver hsqldb.jar copied");
+ }
}