use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.PartnerLink 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 (JUnitTestCase.isWeavingEnabled("fieldaccess")) {
internalTestWeaving(new Employee(), true, true);
internalTestWeaving(new FormerEmployment(), true, false);
internalTestWeaving(new Address(), true, false);
internalTestWeaving(new PhoneNumber(), true, false);
internalTestWeaving(new EmploymentPeriod(), true, false);
// field-locking
internalTestWeaving(new Buyer(), false, false);
// field-locking
internalTestWeaving(new GoldBuyer(), false, false);
// field-locking
internalTestWeaving(new PlatinumBuyer(), false, false);
internalTestWeaving(new Department(), true, false);
internalTestWeaving(new Golfer(), true, false);
internalTestWeaving(new GolferPK(), true, false);
internalTestWeaving(new SmallProject(), true, false);
internalTestWeaving(new LargeProject(), true, false);
internalTestWeaving(new Man(), true, false);
internalTestWeaving(new Woman(), true, false);
// serialized
internalTestWeaving(new Vegetable(), false, false);
internalTestWeaving(new VegetablePK(), false, false);
internalTestWeaving(new WorldRank(), true, false);
internalTestWeaving(new Equipment(), true, false);
internalTestWeaving(new EquipmentCode(), true, false);
internalTestWeaving(new PartnerLink(), true, false);
}
if (((OneToOneMapping) getDatabaseSession().getDescriptor(DatabaseField.class).getMappingForAttributeName("table")).usesIndirection()) {
fail("LAZY mapping should have been reverted as class was not weaved.");
}
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.PartnerLink in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testDeleteMan.
// Test that deleting an Man works correctly.
public void testDeleteMan() {
if (getDatabaseSession().getPlatform().isSymfoware()) {
getDatabaseSession().logMessage("Test testDeleteMan skipped for this platform, " + "The CascadeOnDelete doesn't work on a relation where CascadeType.Remove or CascadeType.All is specified on Symfoware Platform.");
return;
}
EntityManager em = createEntityManager("fieldaccess");
QuerySQLTracker counter = null;
try {
beginTransaction(em);
Man man = new Man();
em.persist(man);
Woman woman = new Woman();
em.persist(woman);
PartnerLink link = new PartnerLink();
man.setPartnerLink(link);
link.setMan(man);
woman.setPartnerLink(link);
link.setWoman(woman);
commitTransaction(em);
closeEntityManager(em);
clearCache();
counter = new QuerySQLTracker(getDatabaseSession());
em = createEntityManager();
beginTransaction(em);
// Count SQL.
man = em.find(Man.class, man.getId());
woman = em.find(Woman.class, woman.getId());
woman.setPartnerLink(null);
counter.getSqlStatements().clear();
em.remove(man);
commitTransaction(em);
if (counter.getSqlStatements().size() > 1) {
if (getDatabaseSession().getPlatform().supportsDeleteOnCascade()) {
fail("Only one delete should have occured.");
}
}
beginTransaction(em);
verifyDelete(man);
commitTransaction(em);
} finally {
if (counter != null) {
counter.remove();
}
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.PartnerLink in project eclipselink by eclipse-ee4j.
the class AdvancedJunitTest method testManAndWoman.
public void testManAndWoman() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
PartnerLink pLink1 = new PartnerLink();
pLink1.setMan(new Man());
em.persist(pLink1);
PartnerLink pLink2 = new PartnerLink();
pLink2.setWoman(new Woman());
em.persist(pLink2);
PartnerLink pLink3 = new PartnerLink();
pLink3.setMan(new Man());
pLink3.setWoman(new Woman());
em.persist(pLink3);
commitTransaction(em);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
fail("An exception was caught: [" + e.getMessage() + "]");
}
closeEntityManager(em);
}
Aggregations