mirror of https://github.com/apache/openjpa.git
fix broken unit test. Illegal table 'ROLES'
The ROLES table exists by default in some datbases. So it's probably better to not use it as table name in our unit test.
This commit is contained in:
parent
11863ed932
commit
6e8c4d987f
|
@ -28,7 +28,7 @@ import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "roles")
|
@Table(name = "rolesx")
|
||||||
public class Role {
|
public class Role {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
|
|
@ -30,82 +30,83 @@ import org.apache.openjpa.persistence.QueryImpl;
|
||||||
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||||
|
|
||||||
public class TestOutOfBoundsEx extends SingleEMFTestCase {
|
public class TestOutOfBoundsEx extends SingleEMFTestCase {
|
||||||
private EntityManager em = null;
|
private EntityManager em = null;
|
||||||
private Lookup lookup;
|
private Lookup lookup;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp(Lookup.class, Case.class, Role.class, ScheduledAssignment.class, ScheduleDay.class,
|
super.setUp(DROP_TABLES, Lookup.class, Case.class, Role.class,
|
||||||
DROP_TABLES);
|
ScheduledAssignment.class, ScheduleDay.class,
|
||||||
em = emf.createEntityManager();
|
"openjpa.Log", "SQL=Trace");
|
||||||
insertLookups();
|
em = emf.createEntityManager();
|
||||||
}
|
insertLookups();
|
||||||
|
}
|
||||||
|
|
||||||
public void testOutOfBounds() throws Exception {
|
public void testOutOfBounds() throws Exception {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
final Date date = cal.getTime();
|
final Date date = cal.getTime();
|
||||||
ScheduleDay sd = insertScheduleDay(date);
|
ScheduleDay sd = insertScheduleDay(date);
|
||||||
|
|
||||||
Role role1 = insertJob();
|
Role role1 = insertJob();
|
||||||
Role role2 = insertJob();
|
Role role2 = insertJob();
|
||||||
Case kase1 = insertCase(sd);
|
Case kase1 = insertCase(sd);
|
||||||
Case kase2 = insertCase(sd);
|
Case kase2 = insertCase(sd);
|
||||||
insertScheduledAssignmentInCase(role1, kase2);
|
insertScheduledAssignmentInCase(role1, kase2);
|
||||||
|
|
||||||
// simulate new web transaction on different em
|
// simulate new web transaction on different em
|
||||||
em.close();
|
em.close();
|
||||||
em = emf.createEntityManager();
|
em = emf.createEntityManager();
|
||||||
|
|
||||||
Query query = em.createQuery("select o from Case as o" +
|
Query query = em.createQuery("select o from Case as o" +
|
||||||
" where o.scheduleDay = :sd");
|
" where o.scheduleDay = :sd");
|
||||||
query.setParameter("sd", sd);
|
query.setParameter("sd", sd);
|
||||||
FetchPlan fetchPlan = ((QueryImpl) query).getFetchPlan();
|
FetchPlan fetchPlan = ((QueryImpl) query).getFetchPlan();
|
||||||
fetchPlan.addField(Case.class, "scheduledAssignments");
|
fetchPlan.addField(Case.class, "scheduledAssignments");
|
||||||
|
|
||||||
//Without the changes of OJ1424, this next call would cause an
|
//Without the changes of OJ1424, this next call would cause an
|
||||||
//ArrayIndexOutOfBoundsException.
|
//ArrayIndexOutOfBoundsException.
|
||||||
List<Case> allCases = query.getResultList();
|
List<Case> allCases = query.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertLookups() {
|
public void insertLookups() {
|
||||||
lookup = new Lookup();
|
lookup = new Lookup();
|
||||||
lookup.setName("XYZ");
|
lookup.setName("XYZ");
|
||||||
lookup.setId(1);
|
lookup.setId(1);
|
||||||
save(lookup);
|
save(lookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(Object obj) {
|
public void save(Object obj) {
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.persist(obj);
|
em.persist(obj);
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Role insertJob() {
|
public Role insertJob() {
|
||||||
Role role = new Role();
|
Role role = new Role();
|
||||||
role.setLookup(lookup);
|
role.setLookup(lookup);
|
||||||
save(role);
|
save(role);
|
||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Case insertCase(ScheduleDay sd) throws Exception {
|
public Case insertCase(ScheduleDay sd) throws Exception {
|
||||||
Case kase = new Case();
|
Case kase = new Case();
|
||||||
kase.setScheduleDay(sd);
|
kase.setScheduleDay(sd);
|
||||||
save(kase);
|
save(kase);
|
||||||
return kase;
|
return kase;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertScheduledAssignmentInCase(Role job, Case kase) {
|
public void insertScheduledAssignmentInCase(Role job, Case kase) {
|
||||||
ScheduledAssignment sa = new ScheduledAssignment();
|
ScheduledAssignment sa = new ScheduledAssignment();
|
||||||
sa.setRole(job);
|
sa.setRole(job);
|
||||||
sa.setCase(kase);
|
sa.setCase(kase);
|
||||||
sa.setScheduleDay(kase.getScheduleDay());
|
sa.setScheduleDay(kase.getScheduleDay());
|
||||||
save(sa);
|
save(sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScheduleDay insertScheduleDay(Date date) {
|
public ScheduleDay insertScheduleDay(Date date) {
|
||||||
ScheduleDay sd = new ScheduleDay();
|
ScheduleDay sd = new ScheduleDay();
|
||||||
sd.setDate(date);
|
sd.setDate(date);
|
||||||
save(sd);
|
save(sd);
|
||||||
return sd;
|
return sd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue