modules/enterprise/gui/installer-war/src/test/java/org/rhq/enterprise/installer/DBInstallatonTest.java
| 91 +++-------
1 file changed, 36 insertions(+), 55 deletions(-)
New commits:
commit 7812b862b15013d8c4720d4290681f3383a6811b
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Dec 19 14:26:25 2011 -0500
The old version of this file requires on a static name and location for
the db to be installed/upgraded in the tests. This version uses the
defined test db.
diff --git
a/modules/enterprise/gui/installer-war/src/test/java/org/rhq/enterprise/installer/DBInstallatonTest.java
b/modules/enterprise/gui/installer-war/src/test/java/org/rhq/enterprise/installer/DBInstallatonTest.java
index 12f4ac6..3bff054 100644
---
a/modules/enterprise/gui/installer-war/src/test/java/org/rhq/enterprise/installer/DBInstallatonTest.java
+++
b/modules/enterprise/gui/installer-war/src/test/java/org/rhq/enterprise/installer/DBInstallatonTest.java
@@ -23,16 +23,13 @@
package org.rhq.enterprise.installer;
-import org.rhq.core.db.DbUtil;
+import org.rhq.core.db.reset.DBReset;
import org.rhq.core.db.setup.DBSetup;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.File;
-import java.net.URI;
import java.net.URL;
-import java.sql.Connection;
-import java.sql.Statement;
import java.util.Properties;
/**
@@ -43,13 +40,20 @@ import java.util.Properties;
*
* @author John Sanda
*/
-public class DBInstallatonTest {
+public class DBInstallationTest {
- final String TEST_DB = "installer_test_db";
- final String USERNAME = "rhqadmin";
- final String PASSWORD = "rhqadmin";
+ private final String LOG_DIRECTORY = System.getProperty("java.io.tmpdir",
"rhq/installer-test");
+ private final String DB_NAME =
System.getProperty("rhq.db.installation.test.db-name",
"rhq_installer_test_db");
+ private final String USERNAME = System.getProperty("rhq.test.ds.user-name",
"rhqadmin");
+ private final String PASSWORD = System.getProperty("rhq.test.ds.password",
"rhqadmin");
+ private final String SERVER = System.getProperty("rhq.test.ds.server-name",
"127.0.0.1");
+ private final String DB_URL =
System.getProperty("rhq.db.installation.test.connection-url",
+ "jdbc:postgresql://" + SERVER + ":5432/" + DB_NAME);
+ private final String ADMIN_USERNAME =
System.getProperty("rhq.db.admin.username", "postgres");
+ private final String ADMIN_PASSWORD =
System.getProperty("rhq.db.admin.password", "postgres");
+ private static final String DB_TYPE_MAPPING =
System.getProperty("rhq.test.ds.type-mapping", "PostgreSQL");
- ServerInformation installer = new ServerInformation();
+ private ServerInformation installer;
@BeforeMethod
public void prepareForInstallation() throws Exception {
@@ -57,7 +61,7 @@ public class DBInstallatonTest {
recreateTestDatabase();
installer = new ServerInformation();
- installer.setLogDirectory(getLogDirectory());
+ installer.setLogDirectory(new File(LOG_DIRECTORY));
}
@Test
@@ -84,50 +88,38 @@ public class DBInstallatonTest {
installer.upgradeExistingDatabaseSchema(getInstallProperties());
}
- void initLogDirectory() {
- File logDir = getLogDirectory();
+ @Test
+ public void overwriteJON240Schema() throws Exception {
+ installSchemaAndData("2.4.0");
+ installer.createNewDatabaseSchema(getInstallProperties());
+ }
+
+ @Test
+ public void upgradeJON240Schema() throws Exception {
+ installSchemaAndData("2.4.0");
+ installer.upgradeExistingDatabaseSchema(getInstallProperties());
+ }
+
+ private void initLogDirectory() {
+ File logDir = new File(LOG_DIRECTORY);
if (logDir.exists()) {
logDir.delete();
}
logDir.mkdirs();
}
- void recreateTestDatabase() throws Exception {
- Connection connection = null;
- Statement dropDB = null;
- Statement createDB = null;
-
- try {
- String dbUrl = "jdbc:postgresql://127.0.0.1:5432/postgres";
-
- connection = DbUtil.getConnection(dbUrl, "postgres",
"postgres");
- dropDB = connection.createStatement();
- createDB = connection.createStatement();
-
- dropDB.execute("drop database if exists " + TEST_DB);
- createDB.execute("create database " + TEST_DB + " with owner
" + USERNAME);
- } finally {
- if (dropDB != null) {
- dropDB.close();
- }
- if (createDB != null) {
- createDB.close();
- }
- if (connection != null) {
- connection.close();
- }
- }
+ private void recreateTestDatabase() throws Exception {
+ DBReset dbReset = new DBReset();
+ dbReset.performDBReset(DB_TYPE_MAPPING, DB_URL, DB_NAME, USERNAME,
ADMIN_USERNAME, ADMIN_PASSWORD);
}
- void installSchemaAndData(String jonVersion) throws Exception {
- String testDbUrl = getTestDbUrl();
-
- DBSetup dbsetup = new DBSetup(testDbUrl, USERNAME, PASSWORD);
+ private void installSchemaAndData(String jonVersion) throws Exception {
+ DBSetup dbsetup = new DBSetup(DB_URL, USERNAME, PASSWORD);
dbsetup.setup(getSchemaFile(jonVersion).getAbsolutePath());
dbsetup.setup(getDataFile(jonVersion).getAbsolutePath());
}
- File getSchemaFile(String version) throws Exception {
+ private File getSchemaFile(String version) throws Exception {
URL url = getClass().getResource("db-schema-combined-" + version +
".xml");
if (url == null) {
@@ -137,7 +129,7 @@ public class DBInstallatonTest {
return new File(url.toURI().getPath());
}
- File getDataFile(String version) throws Exception {
+ private File getDataFile(String version) throws Exception {
URL url = getClass().getResource("db-data-combined-" + version +
".xml");
if (url == null) {
@@ -147,23 +139,12 @@ public class DBInstallatonTest {
return new File(url.toURI().getPath());
}
- File getLogDirectory() {
- return new File(System.getProperty("java.io.tmpdir",
"rhq/installer-test"));
- }
-
private Properties getInstallProperties() {
Properties dbProperties = new Properties();
- dbProperties.put(ServerProperties.PROP_DATABASE_CONNECTION_URL, getTestDbUrl());
+ dbProperties.put(ServerProperties.PROP_DATABASE_CONNECTION_URL, DB_URL);
dbProperties.put(ServerProperties.PROP_DATABASE_USERNAME, USERNAME);
dbProperties.put(ServerProperties.PROP_DATABASE_PASSWORD, PASSWORD);
dbProperties.put(ServerProperties.PROP_EMAIL_FROM_ADDRESS,
"rhqadmin(a)localhost.com");
return dbProperties;
}
-
- private String getTestDbUrl() {
- return "jdbc:postgresql://127.0.0.1:5432/" + TEST_DB;
- }
-
-
-
}
Show replies by date