use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Department in project eclipselink by eclipse-ee4j.
the class AdvancedJPAJunitTest method testRemoveDepartmentWithPrivateOwnedEquipment.
/**
* Tests a @PrivateOwned @OneToMany mapping.
*/
public void testRemoveDepartmentWithPrivateOwnedEquipment() {
EntityManager em = createEntityManager("fieldaccess");
beginTransaction(em);
try {
Department department = em.find(Department.class, deptId);
if (department == null) {
fail("Department with id=" + deptId + ", was not found.");
} else {
Collection<Equipment> equipment = department.getEquipment().values();
if (equipment.isEmpty()) {
fail("Department with id=" + deptId + ", did not have any equipment.");
} else {
em.remove(department);
commitTransaction(em);
assertNull("Department itself was not removed.", em.find(Department.class, deptId));
for (Equipment e : equipment) {
assertNull("New equipment was not deleted.", em.find(Equipment.class, e.getId()));
}
}
}
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
// Re-throw exception to ensure stacktrace appears in test result.
throw e;
}
closeEntityManager(em);
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Department in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testOneToManyDefaultJoinTableName.
// gf 1217 - Ensure join table defaults correctly when 'mappedby' not specified
public void testOneToManyDefaultJoinTableName() {
Department dept = new Department();
Employee manager = new Employee();
dept.addManager(manager);
EntityManager em = createEntityManager();
try {
beginTransaction(em);
em.persist(dept);
commitTransaction(em);
} catch (RuntimeException e) {
throw e;
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Department in project eclipselink by eclipse-ee4j.
the class AdvancedJPAJunitTest method testAddNewEquipmentToDepartment.
/**
* Tests adding objects to a 1-M mapping that uses a map.
*/
public void testAddNewEquipmentToDepartment() {
EntityManager em = createEntityManager("fieldaccess");
beginTransaction(em);
try {
EJBQueryImpl query = (EJBQueryImpl) em.createNamedQuery("findAllSQLEquipment");
Collection<Equipment> equipment = query.getResultCollection();
if (equipment.isEmpty()) {
fail("No Equipment was found. testCreateNewEquipment should have created new equipment and should have run before this test.");
} else {
Department department = new Department();
department.setName("Department with equipment");
for (Equipment e : equipment) {
department.addEquipment(e);
}
em.persist(department);
deptId = department.getId();
commitTransaction(em);
}
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
// Re-throw exception to ensure stacktrace appears in test result.
throw e;
}
closeEntityManager(em);
}
Aggregations