Author: jpeterka
Date: 2010-11-10 13:56:20 -0500 (Wed, 10 Nov 2010)
New Revision: 26425
Added:
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/requirement/PrepareDB.java
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/Annotations.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ConfiguredState.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/TestConfigurator.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:
Initial support implementation for Database requirements
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/Annotations.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/Annotations.java 2010-11-10
18:45:12 UTC (rev 26424)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/Annotations.java 2010-11-10
18:56:20 UTC (rev 26425)
@@ -54,6 +54,12 @@
* setting this to false will disable this feature
* @return
*/
+ /**
+ * optionally require Database
+ * @return
+ */
+ DB db() default @DB (required = false);
+
boolean clearWorkspace() default true;
/**
* by default all projects are undeployed from pre-configured server & deleted
before test runs
@@ -172,6 +178,24 @@
String operator() default "=";
}
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface DB {
+ /**
+ * true if DB is required ()
+ * @return
+ */
+ boolean required() default true;
+ /**
+ * version of database (use * for al)
+ * @return
+ */
+ String version() default "*";
+ /**
+ * defines operator for version version, possible values (=,<,>=<=,>=,!=)
default =
+ * @return
+ */
+ String operator() default "=";
+ }
public enum ServerState {
/**
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ConfiguredState.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ConfiguredState.java 2010-11-10
18:45:12 UTC (rev 26424)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ConfiguredState.java 2010-11-10
18:56:20 UTC (rev 26425)
@@ -18,6 +18,7 @@
private Seam seam = new Seam();
private ESB esb = new ESB();
private JBPM jbpm = new JBPM();
+ private DB db = new DB();
private boolean viewsPrepared = false;
@@ -72,6 +73,13 @@
return jbpm;
}
+ /**
+ * gets configured database
+ */
+ public DB getDB() {
+ return db;
+ }
+
public class Server {
/**
* is server runtime & server added?
@@ -148,4 +156,20 @@
*/
public String name = null;
}
+
+
+ public class DB {
+ /**
+ * version of DB
+ */
+ public String version = null;
+ /**
+ * is configured?
+ */
+ public boolean isConfigured = false;
+ /**
+ * name of added runtime
+ */
+ public String name = null;
+ }
}
Added:
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
(rev 0)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/DBBean.java 2010-11-10
18:56:20 UTC (rev 26425)
@@ -0,0 +1,87 @@
+package org.jboss.tools.ui.bot.ext.config;
+
+import static org.junit.Assert.fail;
+
+import org.jboss.tools.ui.bot.ext.helper.DatabaseHelper.DBType;
+
+/**
+ * DB Bean class representing property string data
+ * @author jpeterka
+ *
+ */
+public class DBBean {
+ public String version;
+ public String jdbcString;
+ public String driverPath;
+ public String scriptPath;
+ public DBType dbType;
+
+ public static DBBean fromString(String propValue) throws Exception{
+ try {
+ if (propValue==null) {
+ return null;
+ }
+ String[] dbParams = propValue.split(",");
+ DBBean bean = new DBBean();
+ bean.dbType=getDBType(dbParams[0]);
+ bean.version = dbParams[1];
+ bean.driverPath=dbParams[2];
+ bean.jdbcString=dbParams[3];
+ bean.scriptPath=dbParams[4];
+
+
+ return bean;
+ }
+ catch (Exception ex) {
+ throw new Exception("Cannot parse DB property line",ex);
+ }
+ }
+ @Override
+ public String toString() {
+ return String.format("DB runtime version=%s, jdbc_string=%s, driver_path=%s
",
+ this.version, this.jdbcString, this.driverPath);
+ }
+
+ /**
+ * A common method for all enums since they can't have another base class
+ * @param <T> Enum type
+ * @param c enum type. All enums must be all caps.
+ * @param string case insensitive
+ * @return corresponding enum, or null
+ */
+ public static <T extends Enum<T>> T getEnumFromString(Class<T> c,
String string)
+ {
+ if( c != null && string != null )
+ {
+ try
+ {
+ return Enum.valueOf(c, string.trim());
+ //return Enum.valueOf(c, string.trim().toUpperCase());
+ }
+ catch(IllegalArgumentException ex)
+ {
+ }
+ }
+ return null;
+ }
+ /**
+ * Validate given db type, fix lower/upper case if needed
+ */
+ private static DBType getDBType(String type) {
+ // list of supported database types (except hsql)
+ String[] valid =
{"hsqldb18","db2_97","mssql2005","mssql2008","mysql50","mysql51","oracle10g",
+ "oracle11gR1","oracle11gR1RAC","oracle11gR2","oracle11gR2RAC","postgressql82","postgresql83",
+ "postgresql84","sybase15"};
+
+ for (String v : valid) {
+ if (v.equalsIgnoreCase(type)) {
+ return getEnumFromString(DBType.class, v);
+ }
+ }
+
+ fail("Database type is not valid");
+ throw new IllegalArgumentException("Can't get DB type");
+ }
+
+
+}
\ No newline at end of file
Property changes on:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/DBBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-10
18:45:12 UTC (rev 26424)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfiguration.java 2010-11-10
18:56:20 UTC (rev 26425)
@@ -29,6 +29,7 @@
private ESBBean esb;
private JavaBean java;
private JBPMBean jbpm;
+ private DBBean db;
public TestConfiguration(String propName, String propFile) throws Exception {
this.propName = propName;
@@ -58,6 +59,7 @@
printConfig(Keys.ESB, esb);
jbpm = JBPMBean.fromString(getProperty(Keys.JBPM));
printConfig(Keys.JBPM, jbpm);
+ db = DBBean.fromString(getProperty(Keys.DB));
checkConfig();
}
@@ -80,6 +82,12 @@
checkDirExists(server.runtimeHome);
if (esb != null)
checkDirExists(esb.esbHome);
+ if (jbpm != null)
+ checkDirExists(jbpm.jbpmHome);
+ if (db != null) {
+ checkFileExists(db.driverPath);
+ checkFileExists(db.scriptPath);
+ }
// special checks capturing dependency of server on java
if (java == null
&& server != null
@@ -111,6 +119,12 @@
+ "' does not exist or is not directory");
}
}
+
+ private static void checkFileExists(String path) throws FileNotFoundException {
+ if (!new File(path).exists() || !new File(path).isFile()) {
+ throw new FileNotFoundException("File " + path + " not exist or is not
file");
+ }
+ }
public ESBBean getEsb() {
return esb;
@@ -139,4 +153,8 @@
public JBPMBean getJBPM() {
return jbpm;
}
+
+ public DBBean getDB() {
+ return db;
+ }
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java 2010-11-10
18:45:12 UTC (rev 26424)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java 2010-11-10
18:56:20 UTC (rev 26425)
@@ -10,6 +10,7 @@
import java.util.Properties;
import org.apache.log4j.Logger;
+import org.jboss.tools.ui.bot.ext.config.Annotations.DB;
import org.jboss.tools.ui.bot.ext.config.Annotations.ESB;
import org.jboss.tools.ui.bot.ext.config.Annotations.JBPM;
import org.jboss.tools.ui.bot.ext.config.Annotations.SWTBotTestRequires;
@@ -28,6 +29,7 @@
public static final String JAVA = "JAVA";
public static final String ESB = "ESB";
public static final String JBPM = "JBPM";
+ public static final String DB = "DB";
}
public class Values {
@@ -193,6 +195,16 @@
}
return RequirementBase.createAddJBPM();
}
+
+ private static RequirementBase getDBRequirement(DB d) {
+ if (!d.required() || currentConfig.getDB() == null) {
+ return null;
+ }
+ if (!matches(currentConfig.getDB().version, d.operator(), d.version())) {
+ return null;
+ }
+ return RequirementBase.prepareDB();
+ }
/**
* returns list of requirements if given class (Test) can run, all this is
@@ -238,6 +250,13 @@
}
reqs.add(req);
}
+ if (requies.db().required()) {
+ RequirementBase req = getDBRequirement(requies.db());
+ if (req == null) {
+ return null;
+ }
+ reqs.add(req);
+ }
if (!"".equals(requies.perspective())) {
reqs.add(RequirementBase.createSwitchPerspective(requies
Added:
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
(rev 0)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/PrepareDB.java 2010-11-10
18:56:20 UTC (rev 26425)
@@ -0,0 +1,72 @@
+package org.jboss.tools.ui.bot.ext.config.requirement;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.eclipse.datatools.connectivity.ConnectionProfileException;
+import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.ui.bot.ext.config.TestConfiguration;
+import org.jboss.tools.ui.bot.ext.config.TestConfigurator;
+import org.jboss.tools.ui.bot.ext.helper.DatabaseHelper;
+import org.jboss.tools.ui.bot.ext.types.DriverEntity;
+import org.junit.Assert;
+
+public class PrepareDB extends RequirementBase {
+
+ @Override
+ public boolean checkFulfilled() {
+ return SWTTestExt.configuredState.getDB().isConfigured;
+ }
+
+ @Override
+ public void handle() {
+ TestConfiguration configuration = TestConfigurator.currentConfig;
+
+ // Define Driver Entity
+ 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.setDriverTemplateDescId(DatabaseHelper.getDriverTemplate(configuration.getDB().dbType));
+
+ try {
+ DatabaseHelper.createDriver(entity);
+ } catch (ConnectionProfileException e) {
+ log.error("Unable to create HSQL Driver" + e);
+ Assert.fail();
+ }
+
+ File file = new File(configuration.getDB().scriptPath);
+ StringBuilder builder = new StringBuilder();
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new FileReader(file));
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ while(true) {
+ String line = null;
+ try {
+ line = reader.readLine();
+ if (line == null) break;
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ 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
+ }
+ }
+
+}
Property changes on:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/PrepareDB.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-10
18:45:12 UTC (rev 26424)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/RequirementBase.java 2010-11-10
18:56:20 UTC (rev 26425)
@@ -162,7 +162,10 @@
RequirementBase req = new RemoveServer();
return req;
}
-
-
+ public static RequirementBase prepareDB () {
+ RequirementBase req = new PrepareDB();
+ return req;
+ }
+
}
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-10
18:45:12 UTC (rev 26424)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/DatabaseHelper.java 2010-11-10
18:56:20 UTC (rev 26425)
@@ -1,5 +1,8 @@
package org.jboss.tools.ui.bot.ext.helper;
+import static org.eclipse.swtbot.eclipse.finder.matchers.WithPartName.withPartName;
+import static org.junit.Assert.fail;
+
import java.io.File;
import java.io.IOException;
import java.util.Properties;
@@ -18,12 +21,23 @@
import org.eclipse.datatools.connectivity.drivers.IPropertySet;
import org.eclipse.datatools.connectivity.drivers.PropertySetImpl;
import org.eclipse.datatools.connectivity.drivers.models.TemplateDescriptor;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.ui.IViewReference;
+import org.hamcrest.Matcher;
import org.jboss.tools.ui.bot.ext.Activator;
+import org.jboss.tools.ui.bot.ext.SWTEclipseExt;
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;
+
/**
* Create HSQLDB Driver
* @throws ConnectionProfileException
@@ -93,5 +107,169 @@
public static void createDriver(DriverEntity entity) throws ConnectionProfileException
{
createDriver(entity,"DefaultDS");
}
-
+ /**
+ *
+ */
+ public static void openSQLEditor(DBType type, String profile, String db) {
+ SWTEclipseExt eclipse = new SWTEclipseExt();
+ SWTWorkbenchBot bot = eclipse.getBot();
+
+ eclipse.openPerspective(PerspectiveType.DB_DEVELOPMENT);
+ eclipse.showView(ViewType.DATA_SOURCE_EXPLORER);
+
+ bot.saveAllEditors();
+ bot.closeAllEditors();
+
+ bot.sleep(SLEEP);
+
+ Matcher<IViewReference> matcher = withPartName("Data Source
Explorer");
+ SWTBotView view = bot.view(matcher);
+
+ bot.sleep(SLEEP);
+ SWTBotTree tree = view.bot().tree();
+
+ // Open SQL Scrapbook
+ SWTBotTreeItem item = tree.expandNode("Database Connections")
+ .expandNode(profile);
+ item.contextMenu("Connect").click();
+ item.contextMenu("Open SQL Scrapbook").click();
+
+ // Set SQL Scrapbook
+ SWTBotEditor editor = bot.editorByTitle("SQL Scrapbook 0");
+ editor.setFocus();
+ bot.comboBoxWithLabelInGroup("Type:", "Connection profile")
+ .setSelection(getTypeCombo(type));
+ bot.comboBoxWithLabelInGroup("Name:", "Connection profile")
+ .setSelection(profile);
+ bot.comboBoxWithLabelInGroup("Database:", "Connection profile")
+ .setSelection(db);
+ }
+
+ /**
+ *
+ * @param script
+ */
+ public static void runSQLScript(String script) {
+ SWTEclipseExt eclipse = new SWTEclipseExt();
+ SWTWorkbenchBot bot = eclipse.getBot();
+
+ SWTBotEditor editor = bot.editorByTitle("SQL Scrapbook 0");
+ editor.toTextEditor().setText(script);
+
+ // Execute Script and close
+ bot.editorByTitle("SQL Scrapbook 0").toTextEditor()
+ .contextMenu("Execute All").click();
+ editor.close();
+ bot.sleep(SLEEP);
+ }
+
+ /**
+ * Database type enum
+ *
+ * @author jpeterka
+ *
+ */
+ 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
+ *
+ * @param type
+ * @return
+ */
+ public static String getDriverTemplate(DBType type) {
+ String ret = "";
+ switch (type) {
+ case hsqldb18:
+ ret = "org.eclipse.datatools.enablement.hsqldb.1_8.driver";
+ break;
+ case db2_97:
+ ret = "org.eclipse.datatools.enablement.ibm.db2.luw.driverTemplate";
+ break;
+ case mssql2005:
+ ret =
"org.eclipse.datatools.enablement.msft.sqlserver.2005.driverTemplate";
+ break;
+ case mssql2008:
+ ret =
"org.eclipse.datatools.enablement.msft.sqlserver.2008.driverTemplate";
+ break;
+ case mysql50:
+ ret = "org.eclipse.datatools.enablement.mysql.5_0.driverTemplate";
+ break;
+ case mysql51:
+ ret = "org.eclipse.datatools.enablement.mysql.5_1.driverTemplate";
+ break;
+ case oracle10g:
+ ret = "org.eclipse.datatools.enablement.oracle.10.driverTemplate";
+ break;
+ case oracle11gR1: // Intentionally empty
+ case oracle11gR1RAC: // Intentionally empty
+ case oracle11gR2: // Intentionally empty
+ case oracle11gR2RAC:
+ ret = "org.eclipse.datatools.enablement.oracle.11.driverTemplate";
+ break;
+ case postgresql82: // Intentionally empty
+ case postgresql83: // Intentionally empty
+ case postgresql84: // Intentionally empty
+ case sybase15:
+ ret =
"org.eclipse.datatools.connectivity.db.sybase.ase.genericDriverTemplate_15";
+ break;
+ default:
+ fail("Unknown db type");
+ break;
+ }
+ return ret;
+ }
+
+ /**
+ * Resolves db type for eclipse usage in SQL editor
+ *
+ * @param type
+ * @return
+ */
+ public static String getTypeCombo(DBType type) {
+ String ret = "";
+ switch (type) {
+ case hsqldb18:
+ ret = "HSQLDB_1.8";
+ break;
+ case db2_97:
+ ret = "DB2 UDB_V9.1";
+ break;
+ case mssql2005:
+ ret = "SQL Server_2005";
+ break;
+ case mssql2008:
+ ret = "SQL Server_2008";
+ break;
+ case mysql50:
+ ret = "MySQL_5.0";
+ break;
+ case mysql51:
+ ret = "MySQL_5.1";
+ break;
+ case oracle10g:
+ ret = "Oracle_10";
+ break;
+ case oracle11gR1: // Intentionally empty
+ case oracle11gR1RAC: // Intentionally empty
+ case oracle11gR2: // Intentionally empty
+ case oracle11gR2RAC:
+ ret = "Oracle_11";
+ break;
+ case postgresql82: // Intentionally empty
+ case postgresql83: // Intentionally empty
+ case postgresql84:
+ ret = "postgres_8.x";
+ break;
+ case sybase15:
+ ret = "Sybase_ASE_15.x";
+ break;
+ default:
+ fail("Unknown db type");
+ break;
+ }
+ return ret;
+ }
}