19 package com.mysql.clusterj.jpatest;
21 import java.util.Arrays;
22 import java.util.HashMap;
25 import javax.persistence.EntityManagerFactory;
26 import javax.persistence.Persistence;
28 import junit.framework.TestCase;
29 import junit.framework.TestResult;
57 protected EntityManagerFactory
createEMF(Object... props) {
73 String puName = System.getProperty(
74 "com.mysql.clusterj.jpa.PersistenceUnit",
"ndb");
75 if (puName.length() == 0 || puName.equals(
"${com.mysql.clusterj.jpa.PersistenceUnit}")) {
91 for (
int i = 0; props != null &&
i < props.length;
i++) {
93 map.put(props[
i - 1], props[
i]);
95 }
else if (props[
i] != null)
98 return Persistence.createEntityManagerFactory(pu,
map);
104 super.run(testResult);
108 public void tearDown() throws Exception {
111 }
catch (Exception e) {
115 if (testResult.wasSuccessful())
123 protected boolean closeEMF(EntityManagerFactory emf) {
124 if (emf == null || !emf.isOpen())
127 return !emf.isOpen();
130 protected void initializeErrorMessages() {
131 if (errorMessages == null) {
133 errorMessages.append(NL);
138 initializeErrorMessages();
139 errorMessages.append(message + NL);
142 protected void errorIfNotEqual(
String message, Object expected, Object actual) {
143 if (expected == null && actual == null) {
146 if (expected != null && expected.equals(actual)) {
149 initializeErrorMessages();
150 errorMessages.append(message + NL);
151 errorMessages.append(
152 "Expected: " + ((expected==null)?
"null":expected.toString())
153 +
" actual: " + ((actual==null)?
"null":actual.toString()) + NL);
157 protected void errorIfNull(
String message, Object actual) {
158 if (actual != null) {
161 initializeErrorMessages();
162 errorMessages.append(message + NL);
166 protected void failOnError() {
167 if (errorMessages != null) {
168 fail(errorMessages.toString());