use of org.eclipse.persistence.testing.models.jpa.advanced.Equipment in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testMergeNewObject2.
// bug6180972: Tests calling merge on a new Entity that uses int as its ID, verifying it is set and cached correctly
public void testMergeNewObject2() {
// create an Equipment
Equipment equip = new Equipment();
equip.setDescription("New Equipment");
EntityManager em = createEntityManager();
try {
beginTransaction(em);
Equipment managedEquip = em.merge(equip);
assertTrue("merged Equipment doesn't have its ID generated", managedEquip.getId() != 0);
assertNotNull("merged Equipment cannot be found using find", em.find(Equipment.class, managedEquip.getId()));
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Equipment in project eclipselink by eclipse-ee4j.
the class AdvancedJPAJunitTest method testBackpointerOnMerge.
/**
* Tests that backpointers are not changed after a merge operation.
*/
public void testBackpointerOnMerge() {
EntityManager em = createEntityManager();
try {
beginTransaction(em);
// create a new department
Department department = new Department();
department.setName("Football");
// persist the department
em.persist(department);
commitTransaction(em);
closeEntityManager(em);
// add equipment to the department
em = createEntityManager();
beginTransaction(em);
Equipment equipment = new Equipment();
equipment.setDescription("Shields & Dummies");
department.addEquipment(equipment);
em.merge(department);
commitTransaction(em);
closeEntityManager(em);
assertTrue(department.getEquipment().get(0) == equipment);
assertEquals(System.identityHashCode(department.getEquipment().get(0)), System.identityHashCode(equipment));
assertEquals(department.getId(), equipment.getDepartment().getId());
assertTrue("The department instance (backpointer) from equipment was modified after merge.", department == equipment.getDepartment());
assertEquals("The department instance (backpointer) from equipment was modified after merge.", System.identityHashCode(department), System.identityHashCode(equipment.getDepartment()));
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
throw e;
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Equipment in project eclipselink by eclipse-ee4j.
the class AdvancedJPAJunitTest method testRemoveDepartmentWithPrivateOwnedEquipment.
/**
* Tests a @PrivateOwned @OneToMany mapping.
*/
public void testRemoveDepartmentWithPrivateOwnedEquipment() {
EntityManager em = createEntityManager();
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.advanced.Equipment in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testWeaving.
/**
* Test that all of the classes in the advanced model were weaved as expected.
*/
public void testWeaving() {
// Only test if weaving was on, test runs without weaving must set this system property.
if (isWeavingEnabled()) {
internalTestWeaving(new Employee(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), true);
internalTestWeaving(new FormerEmployment(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Address(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new PhoneNumber(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new EmploymentPeriod(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
// field-locking
internalTestWeaving(new Buyer(), false, isWeavingForFetchGroupsEnabled(), false);
// field-locking
internalTestWeaving(new GoldBuyer(), false, isWeavingForFetchGroupsEnabled(), false);
// field-locking
internalTestWeaving(new PlatinumBuyer(), false, isWeavingForFetchGroupsEnabled(), false);
// eager 1-m
internalTestWeaving(new Department(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Golfer(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new GolferPK(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new SmallProject(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new LargeProject(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Man(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Woman(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
// serialized
internalTestWeaving(new Vegetable(), false, isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new VegetablePK(), false, isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new WorldRank(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Equipment(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new EquipmentCode(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new PartnerLink(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Equipment in project eclipselink by eclipse-ee4j.
the class AdvancedJPAJunitTest method testMapBuildReferencesPKList.
public void testMapBuildReferencesPKList() {
EntityManager em = createEntityManager();
beginTransaction(em);
ClassDescriptor descriptor;
AbstractSession session = (AbstractSession) JpaHelper.getEntityManager(em).getActiveSession();
descriptor = session.getDescriptorForAlias("ADV_DEPT");
Department dept = (Department) em.createQuery("SELECT d FROM ADV_DEPT d WHERE d.equipment IS NOT EMPTY").getResultList().get(0);
ForeignReferenceMapping mapping = (ForeignReferenceMapping) descriptor.getMappingForAttributeName("equipment");
Object[] pks = mapping.buildReferencesPKList(dept, mapping.getAttributeValueFromObject(dept), session);
assertTrue("PK list is of incorrect size. pks.size: " + pks.length + " expected: " + (dept.getEquipment().size() * 2), pks.length == (dept.getEquipment().size() * 2));
Map<Integer, Equipment> equipments = (Map<Integer, Equipment>) mapping.valueFromPKList(pks, null, session);
assertTrue("ValueFromPKList returned list of different size from actual entity.", equipments.size() == dept.getEquipment().size());
for (Equipment equip : dept.getEquipment().values()) {
assertTrue("Equipment not found in ValueFromPKList list", equipments.containsKey(equip.getId()));
}
rollbackTransaction(em);
}
Aggregations