use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GoldBuyer 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.GoldBuyer in project eclipselink by eclipse-ee4j.
the class AdvancedJPAJunitTest method testCreateNewBuyer.
/**
* Tests:
* - BasicMap mapping with a TypeConverter on the map value and an
* ObjectTypeConverter on the map key.
* - Basic with a custom converter
* - Serialized Basic of type EnumSet.
*/
public void testCreateNewBuyer() {
EntityManager em = createEntityManager("fieldaccess");
beginTransaction(em);
try {
GoldBuyer buyer = new GoldBuyer();
buyer.setName("Guy Pelletier");
buyer.setGender("Made of testosterone");
buyer.setDescription("Loves to spend");
buyer.addVisa(visa);
buyer.addAmex(amex);
buyer.addDinersClub(diners);
buyer.addMastercard(mastercard);
buyer.setSaturdayToSundayBuyingDays();
em.persist(buyer);
commitTransaction(em);
buyerId = buyer.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.GoldBuyer in project eclipselink by eclipse-ee4j.
the class AdvancedJPAJunitTest method testBuyerOptimisticLocking.
/**
* Tests an OptimisticLocking policy set on Buyer.
*/
public void testBuyerOptimisticLocking() {
// Cannot create parallel entity managers in the server.
if (isOnServer()) {
return;
}
EntityManager em1 = createEntityManager("fieldaccess");
EntityManager em2 = createEntityManager("fieldaccess");
em1.getTransaction().begin();
em2.getTransaction().begin();
RuntimeException caughtException = null;
try {
GoldBuyer buyer1 = em1.find(GoldBuyer.class, buyerId);
GoldBuyer buyer2 = em2.find(GoldBuyer.class, buyerId);
buyer1.setName("Geezer");
buyer2.setName("Guyzer");
// Uses field locking, so need to update version.
buyer1.setVersion(buyer1.getVersion() + 1);
buyer2.setVersion(buyer2.getVersion() + 1);
em1.getTransaction().commit();
em2.getTransaction().commit();
em1.close();
em2.close();
} catch (RuntimeException e) {
caughtException = e;
if (em1.getTransaction().isActive()) {
em1.getTransaction().rollback();
}
if (em2.getTransaction().isActive()) {
em2.getTransaction().rollback();
}
em1.close();
em2.close();
}
if (caughtException == null) {
fail("Optimistic lock exception was not thrown.");
} else if (!(caughtException.getCause() instanceof jakarta.persistence.OptimisticLockException)) {
// Re-throw exception to ensure stacktrace appears in test result.
throw caughtException;
}
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GoldBuyer in project eclipselink by eclipse-ee4j.
the class AdvancedJPAJunitTest method testVerifyNewBuyer.
/**
* Verifies:
* - BasicMap mapping with a TypeConverter on the map value and an
* ObjectTypeConverter on the map key.
* - Basic with a custom converter
* - Serialized Basic of type EnumSet.
*/
public void testVerifyNewBuyer() {
EntityManager em = createEntityManager("fieldaccess");
beginTransaction(em);
try {
GoldBuyer buyer = em.find(GoldBuyer.class, buyerId);
assertNotNull("The new buyer was not found", buyer);
assertTrue("Gender was not persisted correctly.", buyer.isMale());
assertTrue("Visa card did not persist correctly.", buyer.hasVisa(visa));
assertTrue("Amex card did not persist correctly.", buyer.hasAmex(amex));
assertTrue("Diners Club card did not persist correctly.", buyer.hasDinersClub(diners));
assertTrue("Mastercard card did not persist correctly.", buyer.hasMastercard(mastercard));
assertTrue("The serialized enum set was not persisted correctly.", buyer.buysSaturdayToSunday());
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