java/code/src/com/redhat/rhn/common/hibernate/test/TestFactoryWrapperTest.java | 70
++++++----
java/code/src/com/redhat/rhn/common/translation/test/ExceptionsWrapperTest.java | 47
+++++-
java/code/src/com/redhat/rhn/taskomatic/task/test/KickstartCleanupTest.java | 3
3 files changed, 88 insertions(+), 32 deletions(-)
New commits:
commit 528259d7bcd4d7a90dfa2fbbd3dd55b6d097d588
Author: Jan Dobes <jdobes(a)redhat.com>
Date: Thu May 23 10:07:00 2013 +0200
junit tests postgresql fixes
diff --git
a/java/code/src/com/redhat/rhn/common/hibernate/test/TestFactoryWrapperTest.java
b/java/code/src/com/redhat/rhn/common/hibernate/test/TestFactoryWrapperTest.java
index 6b7ab85..9f761bf 100644
--- a/java/code/src/com/redhat/rhn/common/hibernate/test/TestFactoryWrapperTest.java
+++ b/java/code/src/com/redhat/rhn/common/hibernate/test/TestFactoryWrapperTest.java
@@ -14,6 +14,7 @@
*/
package com.redhat.rhn.common.hibernate.test;
+import com.redhat.rhn.common.conf.ConfigDefaults;
import com.redhat.rhn.common.db.datasource.ModeFactory;
import com.redhat.rhn.common.db.datasource.SelectMode;
import com.redhat.rhn.common.hibernate.HibernateFactory;
@@ -140,7 +141,7 @@ public class TestFactoryWrapperTest extends RhnBaseTestCase {
public void testLotsOfTransactions() throws Exception {
for (int i = 0; i < 20; i++) {
- SelectMode m = ModeFactory.getMode("test_queries",
"date_dto_test");
+ SelectMode m = ModeFactory.getMode("test_queries",
"get_debug_log");
m.execute(new HashMap());
HibernateFactory.commitTransaction();
HibernateFactory.closeSession();
@@ -178,29 +179,54 @@ public class TestFactoryWrapperTest extends RhnBaseTestCase {
catch (SQLException e) {
// let's clean up anything that MAY have been left
// over
- forceQuery(c, "drop sequence persist_sequence");
forceQuery(c, "drop table persist_test");
+ forceQuery(c, "drop sequence persist_sequence");
+
// Couldn't select 1, so the table didn't exist, create it
- stmt.execute("create sequence persist_sequence");
- stmt.execute("create table persist_test " +
- "( " +
- " foobar VarChar2(32)," +
- " test_column VarChar2(5)," +
- " pin number, " +
- " hidden VarChar(32), " +
- " id number" +
- " constraint persist_test_pk primary key," +
- " created date" +
- ")");
-
- stmt.execute("insert into persist_test (foobar, id) " +
- "values ('Blarg', persist_sequence.nextval)");
- stmt.execute("insert into persist_test (foobar, id) " +
- "values ('duplicate', persist_sequence.nextval)");
- stmt.execute("insert into persist_test (foobar, id) " +
- "values ('duplicate', persist_sequence.nextval)");
- stmt.execute("insert into persist_test (foobar, hidden, id) " +
- "values ('duplicate', 'xxxxx',
persist_sequence.nextval)");
+ if (ConfigDefaults.get().isOracle()) {
+ stmt.execute("create sequence persist_sequence");
+ stmt.execute("create table persist_test " +
+ "( " +
+ " foobar VarChar2(32)," +
+ " test_column VarChar2(5)," +
+ " pin number, " +
+ " hidden VarChar(32), " +
+ " id number" +
+ " constraint persist_test_pk primary key," +
+ " created timestamp with local time zone" +
+ ")");
+ stmt.execute("insert into persist_test (foobar, id) " +
+ "values ('Blarg', persist_sequence.nextval");
+ stmt.execute("insert into persist_test (foobar, id) " +
+ "values ('duplicate',
persist_sequence.nextval)");
+ stmt.execute("insert into persist_test (foobar, id) " +
+ "values ('duplicate',
persist_sequence.nextval)");
+ stmt.execute("insert into persist_test (foobar, hidden, id) "
+
+ "values ('duplicate', 'xxxxx',
persist_sequence.nextval)");
+
+ }
+ else {
+ c.rollback();
+ stmt.execute("create sequence persist_sequence");
+ stmt.execute("create table persist_test " +
+ "( " +
+ " foobar VarChar(32)," +
+ " test_column VarChar(5)," +
+ " pin numeric, " +
+ " hidden VarChar(32), " +
+ " id numeric" +
+ " constraint persist_test_pk primary key," +
+ " created timestamp with time zone" +
+ ")");
+ stmt.execute("insert into persist_test (foobar, id) " +
+ "values ('Blarg',
nextval('persist_sequence'))");
+ stmt.execute("insert into persist_test (foobar, id) " +
+ "values ('duplicate',
nextval('persist_sequence'))");
+ stmt.execute("insert into persist_test (foobar, id) " +
+ "values ('duplicate',
nextval('persist_sequence'))");
+ stmt.execute("insert into persist_test (foobar, hidden, id) "
+
+ "values ('duplicate', 'xxxxx',
nextval('persist_sequence'))");
+ }
c.commit();
}
diff --git
a/java/code/src/com/redhat/rhn/common/translation/test/ExceptionsWrapperTest.java
b/java/code/src/com/redhat/rhn/common/translation/test/ExceptionsWrapperTest.java
index 5f84121..3975734 100644
--- a/java/code/src/com/redhat/rhn/common/translation/test/ExceptionsWrapperTest.java
+++ b/java/code/src/com/redhat/rhn/common/translation/test/ExceptionsWrapperTest.java
@@ -14,6 +14,7 @@
*/
package com.redhat.rhn.common.translation.test;
+import com.redhat.rhn.common.conf.ConfigDefaults;
import com.redhat.rhn.common.db.ConstraintViolationException;
import com.redhat.rhn.common.db.WrappedSQLException;
import com.redhat.rhn.common.hibernate.HibernateFactory;
@@ -46,9 +47,6 @@ public class ExceptionsWrapperTest extends TestCase {
super(name);
}
- /**
- * These tests assume that the DB is oracle
- */
public void testConstraintViolation() throws Exception {
Session session = null;
Statement stmt = null;
@@ -60,6 +58,9 @@ public class ExceptionsWrapperTest extends TestCase {
"values ('tooBigAString', 1)");
}
catch (SQLException e) {
+ if (!ConfigDefaults.get().isOracle()) {
+ session.connection().rollback();
+ }
try {
throw SqlExceptionTranslator.sqlException(e);
}
@@ -68,6 +69,10 @@ public class ExceptionsWrapperTest extends TestCase {
assertEquals(c.getConstraintType(),
ExceptionConstants.VALUE_TOO_LARGE);
}
+ // PostgreSQL
+ catch (WrappedSQLException c) {
+ assertTrue(c.getMessage().toLowerCase().contains("value too
long"));
+ }
}
finally {
HibernateHelper.cleanupDB(stmt);
@@ -87,6 +92,9 @@ public class ExceptionsWrapperTest extends TestCase {
"values ('ano', 1)");
}
catch (SQLException e) {
+ if (!ConfigDefaults.get().isOracle()) {
+ session.connection().rollback();
+ }
try {
throw SqlExceptionTranslator.sqlException(e);
}
@@ -95,6 +103,10 @@ public class ExceptionsWrapperTest extends TestCase {
assertEquals(c.getConstraintType(),
ExceptionConstants.VALUE_TOO_LARGE);
}
+ // PostgreSQL
+ catch (WrappedSQLException c) {
+ assertTrue(c.getMessage().toLowerCase().contains("duplicate
key"));
+ }
}
finally {
HibernateHelper.cleanupDB(stmt);
@@ -114,6 +126,9 @@ public class ExceptionsWrapperTest extends TestCase {
"values ('ano', 1)");
}
catch (SQLException e) {
+ if (!ConfigDefaults.get().isOracle()) {
+ session.connection().rollback();
+ }
try {
throw SqlExceptionTranslator.sqlException(e);
}
@@ -141,6 +156,9 @@ public class ExceptionsWrapperTest extends TestCase {
"values ('ano', 1)");
}
catch (SQLException e) {
+ if (!ConfigDefaults.get().isOracle()) {
+ session.connection().rollback();
+ }
try {
throw SqlExceptionTranslator.sqlException(e);
}
@@ -185,12 +203,23 @@ public class ExceptionsWrapperTest extends TestCase {
}
catch (SQLException e) {
// Couldn't select 1, so the table didn't exist, create it
- stmt.execute("create table exceptions_test " +
- "( " +
- " small_column VarChar2(5)," +
- " id number" +
- " constraint exceptions_test_pk primary key" +
- ")");
+ if (ConfigDefaults.get().isOracle()) {
+ stmt.execute("create table exceptions_test " +
+ "( " +
+ " small_column VarChar2(5)," +
+ " id number" +
+ " constraint exceptions_test_pk primary key" +
+ ")");
+ }
+ else {
+ session.connection().rollback();
+ stmt.execute("create table exceptions_test " +
+ "( " +
+ " small_column VarChar(5)," +
+ " id numeric" +
+ " constraint exceptions_test_pk primary key" +
+ ")");
+ }
session.connection().commit();
}
diff --git a/java/code/src/com/redhat/rhn/taskomatic/task/test/KickstartCleanupTest.java
b/java/code/src/com/redhat/rhn/taskomatic/task/test/KickstartCleanupTest.java
index b6007b6..fd0652e 100644
--- a/java/code/src/com/redhat/rhn/taskomatic/task/test/KickstartCleanupTest.java
+++ b/java/code/src/com/redhat/rhn/taskomatic/task/test/KickstartCleanupTest.java
@@ -90,8 +90,9 @@ public class KickstartCleanupTest extends RhnBaseTestCase {
KickstartSession ksession, int days) throws Exception {
Connection cn = session.connection();
StringBuffer sql = new StringBuffer();
- sql.append("update rhnkickstartsession set last_action = sysdate - ");
+ sql.append("update rhnkickstartsession set last_action = current_timestamp -
interval '");
sql.append(String.valueOf(days));
+ sql.append("' day");
sql.append(" where id = ").append(ksession.getId());
Statement stmt = null;
try {