mirror of
https://github.com/apache/openjpa.git
synced 2025-02-23 10:57:48 +00:00
testcase cleanup. Remove System.err.printlns
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@736066 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0452a7c4ab
commit
fd42fb9d9e
@ -417,19 +417,11 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
|
||||
String[] schemas =
|
||||
{ "SCHEMA1", "SCHEMA2", "SCHEMA3", "SCHEMA3G", "SCHEMA4G" };
|
||||
for (String schema : schemas) {
|
||||
try {
|
||||
em.getTransaction().begin();
|
||||
Query q = em.createNativeQuery("create schema " + schema);
|
||||
q.executeUpdate();
|
||||
em.getTransaction().commit();
|
||||
} catch (PersistenceException e) {
|
||||
System.err.println("Exception caught while creating schema "
|
||||
+ schema + ". Schema already exists? Message: "
|
||||
+ e.getMessage());
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
em.getTransaction().begin();
|
||||
Query q = em.createNativeQuery("create schema " + schema);
|
||||
q.executeUpdate();
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
closeEMF(emf);
|
||||
}
|
||||
|
||||
} // end of TestMultipleSchemaNames
|
||||
|
@ -40,11 +40,23 @@ import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||
@AllowFailure(true)
|
||||
public class TestSequenceGenerator extends SingleEMFTestCase {
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
public void setUp()
|
||||
throws Exception {
|
||||
setUp(NativeSequenceEntity.class,
|
||||
NativeORMSequenceEntity.class,
|
||||
CLEAR_TABLES);
|
||||
|
||||
// disable testcase for dictionaries which do not have a native sequence
|
||||
// query.
|
||||
try {
|
||||
enabled =
|
||||
((JDBCConfiguration) emf.getConfiguration())
|
||||
.getDBDictionaryInstance().nextSequenceQuery == null;
|
||||
} catch (Throwable t) {
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,20 +70,22 @@ public class TestSequenceGenerator extends SingleEMFTestCase {
|
||||
* currently allowed to fail.
|
||||
*/
|
||||
public void testSequenceSchema() {
|
||||
OpenJPAEntityManagerSPI em = emf.createEntityManager();
|
||||
NativeSequenceEntity nse = new NativeSequenceEntity();
|
||||
nse.setName("Test");
|
||||
em.getTransaction().begin();
|
||||
em.persist(nse);
|
||||
em.getTransaction().commit();
|
||||
em.refresh(nse);
|
||||
// Validate the id is >= the initial value
|
||||
// Assert the sequence was created in the DB
|
||||
assertTrue(sequenceExists(em, NativeSequenceEntity.SCHEMA_NAME,
|
||||
if (enabled) {
|
||||
OpenJPAEntityManagerSPI em = emf.createEntityManager();
|
||||
NativeSequenceEntity nse = new NativeSequenceEntity();
|
||||
nse.setName("Test");
|
||||
em.getTransaction().begin();
|
||||
em.persist(nse);
|
||||
em.getTransaction().commit();
|
||||
em.refresh(nse);
|
||||
// Validate the id is >= the initial value
|
||||
// Assert the sequence was created in the DB
|
||||
assertTrue(sequenceExists(em, NativeSequenceEntity.SCHEMA_NAME,
|
||||
NativeSequenceEntity.SEQ_NAME));
|
||||
// Assert the id is >= the initial value
|
||||
assertTrue(nse.getId() >= 10);
|
||||
em.close();
|
||||
// Assert the id is >= the initial value
|
||||
assertTrue(nse.getId() >= 10);
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -80,19 +94,21 @@ public class TestSequenceGenerator extends SingleEMFTestCase {
|
||||
* currently allowed to fail.
|
||||
*/
|
||||
public void testORMSequenceSchema() {
|
||||
OpenJPAEntityManagerSPI em = emf.createEntityManager();
|
||||
NativeORMSequenceEntity nse = new NativeORMSequenceEntity();
|
||||
nse.setName("TestORM");
|
||||
em.getTransaction().begin();
|
||||
em.persist(nse);
|
||||
em.getTransaction().commit();
|
||||
em.refresh(nse);
|
||||
// Assert the sequence was created in the DB
|
||||
assertTrue(sequenceExists(em, NativeORMSequenceEntity.SCHEMA_NAME,
|
||||
NativeORMSequenceEntity.SEQ_NAME));
|
||||
// Assert the id is >= the initial value
|
||||
assertTrue(nse.getId() >= 2000);
|
||||
em.close();
|
||||
if (enabled) {
|
||||
OpenJPAEntityManagerSPI em = emf.createEntityManager();
|
||||
NativeORMSequenceEntity nse = new NativeORMSequenceEntity();
|
||||
nse.setName("TestORM");
|
||||
em.getTransaction().begin();
|
||||
em.persist(nse);
|
||||
em.getTransaction().commit();
|
||||
em.refresh(nse);
|
||||
// Assert the sequence was created in the DB
|
||||
assertTrue(sequenceExists(em, NativeORMSequenceEntity.SCHEMA_NAME,
|
||||
NativeORMSequenceEntity.SEQ_NAME));
|
||||
// Assert the id is >= the initial value
|
||||
assertTrue(nse.getId() >= 2000);
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,9 +41,8 @@ public class TestAutoIncrement extends SingleEMFTestCase {
|
||||
private static String PLATFORM = "oracle";
|
||||
|
||||
public void setUp() throws Exception {
|
||||
// run with -Dplatform= ${PLATFORM} to activate
|
||||
if (!isTargetPlatform(PLATFORM)) {
|
||||
System.err.println("*** " + getName() + " skipped. Run with "
|
||||
+ "-Dplatform=" + PLATFORM + " to activate");
|
||||
return;
|
||||
}
|
||||
if ("testAutoIncrementIdentityWithNamedSequence".equals(getName())) {
|
||||
|
@ -21,8 +21,6 @@ package org.apache.openjpa.persistence.jdbc.query;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.apache.openjpa.persistence.jdbc.query.domain.Applicant;
|
||||
import org.apache.openjpa.persistence.jdbc.query.domain.Application;
|
||||
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||
|
||||
/**
|
||||
@ -36,7 +34,7 @@ import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||
*
|
||||
*/
|
||||
public class TestNativeQueryParameterBinding extends SingleEMFTestCase {
|
||||
private static Class NO_ERROR = null;
|
||||
private static Class<? extends Exception> NO_ERROR = null;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
@ -58,28 +56,28 @@ public class TestNativeQueryParameterBinding extends SingleEMFTestCase {
|
||||
verifyParams(sql, IllegalArgumentException.class, 0, 10);
|
||||
}
|
||||
|
||||
void verifyParams(String jpql, Class error, Object...params) {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
Query query = em.createNativeQuery(jpql);
|
||||
for (int i=0; params != null && i<params.length; i=+2) {
|
||||
try {
|
||||
if (params[i] instanceof Number) {
|
||||
query.setParameter(((Number)params[i]).intValue(), params[i+1]);
|
||||
} else {
|
||||
query.setParameter(params[i].toString(), params[i+1]);
|
||||
}
|
||||
void verifyParams(String jpql, Class<? extends Exception> error,
|
||||
Object... params) {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
Query query = em.createNativeQuery(jpql);
|
||||
for (int i = 0; params != null && i < params.length; i = +2) {
|
||||
try {
|
||||
if (params[i] instanceof Number) {
|
||||
query.setParameter(((Number) params[i]).intValue(),
|
||||
params[i + 1]);
|
||||
} else {
|
||||
query.setParameter(params[i].toString(), params[i + 1]);
|
||||
}
|
||||
if (error != null)
|
||||
fail("Expected " + error.getName());
|
||||
} catch (Exception e) {
|
||||
if (error.isAssignableFrom(e.getClass())) {
|
||||
System.err.println(e.getMessage());
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
if (!error.isAssignableFrom(e.getClass())) {
|
||||
// let the test harness handle the exception.
|
||||
throw new RuntimeException("An unexpected exception " +
|
||||
"occurred see the initCause for details", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
|
@ -283,9 +283,7 @@ public class TestQueryParameterBinding extends SingleEMFTestCase {
|
||||
q.getResultList();
|
||||
fail("Expeceted " + ArgumentException.class.getName());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// good
|
||||
System.err.println("*** ERROR " + getName());
|
||||
System.err.println("*** ERROR " + ex.getMessage());
|
||||
// good
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,9 +54,11 @@ public class TestTemporalTypeQueryParameterBinding extends SingleEMFTestCase {
|
||||
|
||||
|
||||
private static String JPQL_NAMED =
|
||||
"SELECT p FROM TimeKeeper p WHERE p.date=:d AND p.time=:t AND p.tstamp=:ts";
|
||||
"SELECT p FROM TimeKeeper p " +
|
||||
"WHERE p.date=:d AND p.time=:t AND p.tstamp=:ts";
|
||||
private static String JPQL_POSITIONAL =
|
||||
"SELECT p FROM TimeKeeper p WHERE p.date=?1 AND p.time=?2 AND p.tstamp=?3";
|
||||
"SELECT p FROM TimeKeeper p " +
|
||||
"WHERE p.date=?1 AND p.time=?2 AND p.tstamp=?3";
|
||||
|
||||
private EntityManager em;
|
||||
@Override
|
||||
@ -147,7 +149,6 @@ public class TestTemporalTypeQueryParameterBinding extends SingleEMFTestCase {
|
||||
fail("Expeceted " + ArgumentException.class.getName());
|
||||
} catch (ArgumentException ex) {
|
||||
// good
|
||||
System.err.println(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,33 +166,33 @@ public class TestTemporalTypeQueryParameterBinding extends SingleEMFTestCase {
|
||||
q.getResultList();
|
||||
fail("Expeceted " + ArgumentException.class.getName());
|
||||
} catch (ArgumentException ex) {
|
||||
// MDD I'm assuming good == expected.
|
||||
// good
|
||||
System.err.println(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
void verifyParams(String jpql, Class error, Object...params) {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
void verifyParams(String jpql, Class<? extends Exception> error,
|
||||
Object... params) {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
Query query = em.createNativeQuery(jpql);
|
||||
for (int i=0; params != null && i<params.length; i=+2) {
|
||||
try {
|
||||
if (params[i] instanceof Number) {
|
||||
query.setParameter(((Number)params[i]).intValue(), params[i+1]);
|
||||
} else {
|
||||
query.setParameter(params[i].toString(), params[i+1]);
|
||||
query.setParameter(((Number) params[i]).intValue(),
|
||||
params[i + 1]);
|
||||
} else {
|
||||
query.setParameter(params[i].toString(), params[i+1]);
|
||||
}
|
||||
if (error != null)
|
||||
fail("Expected " + error.getName());
|
||||
} catch (Exception e) {
|
||||
if (error.isAssignableFrom(e.getClass())) {
|
||||
System.err.println(e.getMessage());
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
if (!error.isAssignableFrom(e.getClass())) {
|
||||
// let the test harness handle the exception
|
||||
throw new RuntimeException("An unexpected exception " +
|
||||
"occurred see initCause for details", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
|
@ -124,18 +124,18 @@ public abstract class SingleEMFTestCase
|
||||
* Count number of instances of the given class assuming that the alias
|
||||
* for the class is its simple name.
|
||||
*/
|
||||
public int count(Class c) {
|
||||
return count(c.getSimpleName());
|
||||
public int count(Class<?> c) {
|
||||
return count(getAlias(c));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the instances of given type.
|
||||
* The returned instances are obtained without a persistence context.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> getAll(Class<T> t) {
|
||||
String alias = t.getSimpleName();
|
||||
return (List<T>)emf.createEntityManager()
|
||||
.createQuery("SELECT p FROM " + alias + " p")
|
||||
.createQuery("SELECT p FROM " + getAlias(t) + " p")
|
||||
.getResultList();
|
||||
}
|
||||
|
||||
@ -143,9 +143,14 @@ public abstract class SingleEMFTestCase
|
||||
* Get all the instances of given type.
|
||||
* The returned instances are obtained within the given persistence context.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> getAll(EntityManager em, Class<T> t) {
|
||||
String alias = t.getSimpleName();
|
||||
return (List<T>)em.createQuery("SELECT p FROM " + alias + " p")
|
||||
return (List<T>)em.createQuery("SELECT p FROM " + getAlias(t) + " p")
|
||||
.getResultList();
|
||||
}
|
||||
|
||||
public String getAlias(Class<?> t) {
|
||||
return emf.getConfiguration().getMetaDataRepositoryInstance()
|
||||
.getMetaData(t, null, true).getTypeAlias();
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +66,6 @@ public class TestXMLCustomerOrder
|
||||
public void setUp() {
|
||||
// skip test if dictionary has no support for XML column type
|
||||
if (!dictionarySupportsXMLColumn()) {
|
||||
System.err.println("*** " + getName() + " skipped since "
|
||||
+ "DBDictionary.supportsXMLColumn property is false.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -81,6 +79,7 @@ public class TestXMLCustomerOrder
|
||||
em.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testXMLFieldProjection() {
|
||||
if (!enabled)
|
||||
return;
|
||||
@ -102,7 +101,8 @@ public class TestXMLCustomerOrder
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testXMLFieldInEntity() {
|
||||
if (!enabled)
|
||||
return;
|
||||
@ -127,6 +127,7 @@ public class TestXMLCustomerOrder
|
||||
em.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testXMLStringToXMLStringComparison() {
|
||||
if (!enabled)
|
||||
return;
|
||||
@ -154,6 +155,7 @@ public class TestXMLCustomerOrder
|
||||
em.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testXMLStringToEmbeddedStringComparison() {
|
||||
if (!enabled)
|
||||
return;
|
||||
@ -171,6 +173,7 @@ public class TestXMLCustomerOrder
|
||||
em.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testXMLStringToConstantStringComparison() {
|
||||
if (!enabled)
|
||||
return;
|
||||
@ -187,6 +190,7 @@ public class TestXMLCustomerOrder
|
||||
em.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testXMLStringToParameterStringComparison() {
|
||||
if (!enabled)
|
||||
return;
|
||||
@ -204,6 +208,7 @@ public class TestXMLCustomerOrder
|
||||
em.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testParameterStringToXMLStringComparison() {
|
||||
if (!enabled)
|
||||
return;
|
||||
@ -278,9 +283,9 @@ public class TestXMLCustomerOrder
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
try {
|
||||
List<Order> orders = em.createQuery(
|
||||
"select o from Order o where o.shipAddress.city = 95141")
|
||||
.getResultList();
|
||||
em.createQuery(
|
||||
"select o from Order o where o.shipAddress.city = 95141")
|
||||
.getResultList();
|
||||
} catch (IllegalArgumentException iae) {
|
||||
return;
|
||||
} finally {
|
||||
@ -295,10 +300,9 @@ public class TestXMLCustomerOrder
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
try {
|
||||
List<Order> orders = em.createQuery(
|
||||
"select o from Order o where o.shipAddress.street " +
|
||||
"= '555 Bailey'")
|
||||
.getResultList();
|
||||
em.createQuery(
|
||||
"select o from Order o where o.shipAddress.street "
|
||||
+ "= '555 Bailey'").getResultList();
|
||||
} catch (IllegalArgumentException iae) {
|
||||
return;
|
||||
} finally {
|
||||
@ -313,9 +317,9 @@ public class TestXMLCustomerOrder
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
try {
|
||||
List<Order> orders = em.createQuery(
|
||||
"select o from Order o where o.shipAddress.zip = 95141")
|
||||
.getResultList();
|
||||
em.createQuery(
|
||||
"select o from Order o where o.shipAddress.zip = 95141")
|
||||
.getResultList();
|
||||
} catch (IllegalArgumentException iae) {
|
||||
return;
|
||||
} finally {
|
||||
|
Loading…
x
Reference in New Issue
Block a user