use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Vegetable in project eclipselink by eclipse-ee4j.
the class AdvancedJunitTest method testStringArrayField.
// GF1673, 2674 Java SE 6 classloading error for String[] field
public void testStringArrayField() {
EntityManager em = createEntityManager();
beginTransaction(em);
VegetablePK pk = new VegetablePK("Tomato", "Red");
String[] tags = { "California", "XE" };
try {
Vegetable vegetable = new Vegetable();
vegetable.setId(pk);
vegetable.setCost(2.09);
vegetable.setTags(tags);
em.persist(vegetable);
commitTransaction(em);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
throw e;
} finally {
closeEntityManager(em);
}
em = createEntityManager();
beginTransaction(em);
Vegetable vegetable;
try {
vegetable = em.find(Vegetable.class, pk);
commitTransaction(em);
assertNotNull(vegetable);
assertTrue(Arrays.equals(tags, vegetable.getTags()));
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
throw e;
} finally {
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Vegetable 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.Vegetable in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testCharFieldDefaultNullValue.
public void testCharFieldDefaultNullValue() {
EntityManager em = createEntityManager();
beginTransaction(em);
Vegetable vegetable;
Vegetable vegetable2;
VegetablePK pk = new VegetablePK("Eggplant", "Purple");
VegetablePK pk2 = new VegetablePK("Capsicum", "Green");
String[] tags = { "California", "DE" };
String[] tags2 = { "Florida", "FD" };
try {
// Usecase for char with value ' ' (space)
vegetable = new Vegetable();
vegetable.setId(pk);
vegetable.setCost(2.09);
vegetable.setTags(tags);
vegetable.setType(' ');
em.persist(vegetable);
// Usecase for char with value null
vegetable2 = new Vegetable();
vegetable2.setId(pk2);
vegetable2.setCost(1.35);
vegetable2.setTags(tags2);
em.persist(vegetable2);
commitTransaction(em);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
throw e;
} finally {
closeEntityManager(em);
}
em = createEntityManager();
em.clear();
clearCache("fieldaccess");
beginTransaction(em);
try {
vegetable = em.find(Vegetable.class, pk);
vegetable2 = em.find(Vegetable.class, pk2);
commitTransaction(em);
assertNotNull(vegetable);
assertNotNull(vegetable2);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
throw e;
} finally {
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Vegetable in project eclipselink by eclipse-ee4j.
the class AdvancedJunitTest method testGF1818.
public void testGF1818() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Vegetable vegetable = new Vegetable();
vegetable.setId(new VegetablePK("Carrot", "Orange"));
vegetable.setCost(2.09);
em.persist(vegetable);
commitTransaction(em);
} catch (Exception e) {
fail("An exception was caught: [" + e.getMessage() + "]");
}
closeEntityManager(em);
}
Aggregations