use of org.eclipse.persistence.testing.models.jpa.inherited.BecksTag in project eclipselink by eclipse-ee4j.
the class InheritedModelJunitTest method testBecksBeerConsumer.
public void testBecksBeerConsumer() {
EntityManager em = createEntityManager();
beginTransaction(em);
BeerConsumer initialBC = new BeerConsumer();
int beerConsumerId = 0;
try {
Becks becks1 = new Becks();
becks1.setAlcoholContent(5.1);
BecksTag becksTag1 = new BecksTag();
becksTag1.setCallNumber("0A.789");
em.persist(becksTag1);
Becks becks2 = new Becks();
becks2.setAlcoholContent(5.1);
BecksTag becksTag2 = new BecksTag();
becksTag2.setCallNumber("BX.521");
em.persist(becksTag2);
Becks becks3 = new Becks();
becks3.setAlcoholContent(5.1);
BecksTag becksTag3 = new BecksTag();
becksTag3.setCallNumber("UY.429");
em.persist(becksTag3);
initialBC.setName("Becks Consumer");
initialBC.addBecksBeerToConsume(becks1, becksTag1);
initialBC.addBecksBeerToConsume(becks2, becksTag2);
initialBC.addBecksBeerToConsume(becks3, becksTag3);
em.persist(initialBC);
beerConsumerId = initialBC.getId();
commitTransaction(em);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
fail("An exception was caught during create operation: [" + e.getMessage() + "]");
}
closeEntityManager(em);
clearCache();
em = createEntityManager();
BeerConsumer refreshedBC = em.find(BeerConsumer.class, beerConsumerId);
assertTrue("The beer consumer read back did not match the original", getServerSession().compareObjects(initialBC, refreshedBC));
}
use of org.eclipse.persistence.testing.models.jpa.inherited.BecksTag in project eclipselink by eclipse-ee4j.
the class InheritedModelJunitTest method testMapOrphanRemoval.
public void testMapOrphanRemoval() {
EntityManager em = createEntityManager();
beginTransaction(em);
BeerConsumer initialBC = new BeerConsumer();
int beerConsumerId = 0;
try {
Becks becks1 = new Becks();
becks1.setAlcoholContent(5.1);
BecksTag becksTag1 = new BecksTag();
becksTag1.setCallNumber("0A.789");
em.persist(becksTag1);
initialBC.setName("Becks Consumer");
initialBC.addBecksBeerToConsume(becks1, becksTag1);
em.persist(initialBC);
beerConsumerId = initialBC.getId();
em.flush();
clearCache();
BeerConsumer refreshedBC = em.find(BeerConsumer.class, beerConsumerId);
refreshedBC.getBecksBeersToConsume().remove(becksTag1);
em.flush();
clearCache();
becksTag1 = em.find(BecksTag.class, becksTag1.getId());
assertTrue("Key was deleted when it should not be.", becksTag1 != null);
becks1 = em.find(Becks.class, becks1.getId());
assertTrue("Orphan removal did not remove the orphan", becks1 == null);
rollbackTransaction(em);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
fail("An exception was caught during create operation: [" + e.getMessage() + "]");
}
}
use of org.eclipse.persistence.testing.models.jpa.inherited.BecksTag in project eclipselink by eclipse-ee4j.
the class JUnitJPQLComplexTestSuite method mappedKeyMapContainerPolicyMapKeyInSelectionCriteriaTest.
public void mappedKeyMapContainerPolicyMapKeyInSelectionCriteriaTest() {
// skip test on OC4j some this test fails on some OC4j versions because of an issue with Timestamp
if (getServerSession().getServerPlatform() != null && getServerSession().getServerPlatform() instanceof Oc4jPlatform) {
return;
}
EntityManager em = createEntityManager();
beginTransaction(em);
try {
BeerConsumer consumer = new BeerConsumer();
consumer.setName("Marvin Monroe");
em.persist(consumer);
Becks becks = new Becks();
becks.setAlcoholContent(5.0);
BecksTag tag = new BecksTag();
tag.setCallNumber("123");
consumer.addBecksBeerToConsume(becks, tag);
em.persist(becks);
em.persist(tag);
BeerConsumer consumer2 = new BeerConsumer();
consumer.setName("Marvin Monroe2");
em.persist(consumer2);
Becks becks2 = new Becks();
becks2.setAlcoholContent(5.0);
BecksTag tag2 = new BecksTag();
tag2.setCallNumber("1234");
consumer2.addBecksBeerToConsume(becks2, tag2);
em.persist(becks2);
em.persist(tag2);
em.flush();
Vector expectedResult = new Vector();
expectedResult.add(consumer);
clearCache();
String ejbqlString = "SELECT bc FROM BeerConsumer bc join bc.becksBeersToConsume b where Key(b).callNumber = '123'";
List result = em.createQuery(ejbqlString).getResultList();
Assert.assertTrue("mappedKeyMapContainerPolicyMapKeyInSelectionCriteriaTest failed", comparer.compareObjects(result, expectedResult));
} finally {
rollbackTransaction(em);
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.inherited.BecksTag in project eclipselink by eclipse-ee4j.
the class JUnitJPQLComplexTestSuite method mappedKeyMapContainerPolicyMapKeyInSelectTest.
public void mappedKeyMapContainerPolicyMapKeyInSelectTest() {
// skip test on OC4j some this test fails on some OC4j versions because of an issue with Timestamp
if (getServerSession().getServerPlatform() != null && getServerSession().getServerPlatform() instanceof Oc4jPlatform) {
return;
}
EntityManager em = createEntityManager();
beginTransaction(em);
try {
BeerConsumer consumer = new BeerConsumer();
consumer.setName("Marvin Monroe");
em.persist(consumer);
Becks becks = new Becks();
becks.setAlcoholContent(5.0);
BecksTag tag = new BecksTag();
tag.setCallNumber("123");
consumer.addBecksBeerToConsume(becks, tag);
em.persist(becks);
em.persist(tag);
BeerConsumer consumer2 = new BeerConsumer();
consumer.setName("Marvin Monroe2");
em.persist(consumer2);
Becks becks2 = new Becks();
becks2.setAlcoholContent(5.0);
BecksTag tag2 = new BecksTag();
tag2.setCallNumber("1234");
consumer2.addBecksBeerToConsume(becks2, tag2);
em.persist(becks2);
em.persist(tag2);
em.flush();
Vector expectedResult = new Vector();
expectedResult.add(tag);
clearCache();
String ejbqlString = "SELECT Key(b) FROM BeerConsumer bc join bc.becksBeersToConsume b where Key(b).callNumber = '123'";
List result = em.createQuery(ejbqlString).getResultList();
Assert.assertTrue("mappedKeyMapContainerPolicyMapKeyInSelectTest failed", comparer.compareObjects(result, expectedResult));
} finally {
rollbackTransaction(em);
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.inherited.BecksTag in project eclipselink by eclipse-ee4j.
the class JUnitJPQLComplexTestSuite method mappedKeyMapContainerPolicyMapEntryInSelectTest.
public void mappedKeyMapContainerPolicyMapEntryInSelectTest() {
// skip test on OC4j some this test fails on some OC4j versions because of an issue with Timestamp
if (getServerSession().getServerPlatform() != null && getServerSession().getServerPlatform() instanceof Oc4jPlatform) {
return;
}
EntityManager em = createEntityManager();
beginTransaction(em);
try {
BeerConsumer consumer = new BeerConsumer();
consumer.setName("Marvin Monroe");
em.persist(consumer);
Becks becks = new Becks();
becks.setAlcoholContent(5.0);
BecksTag tag = new BecksTag();
tag.setCallNumber("123");
consumer.addBecksBeerToConsume(becks, tag);
em.persist(becks);
em.persist(tag);
BeerConsumer consumer2 = new BeerConsumer();
consumer2.setName("Marvin Monroe2");
em.persist(consumer2);
Becks becks2 = new Becks();
becks2.setAlcoholContent(5.0);
BecksTag tag2 = new BecksTag();
tag2.setCallNumber("1234");
consumer2.addBecksBeerToConsume(becks2, tag2);
em.persist(becks2);
em.persist(tag2);
em.flush();
clearCache();
String ejbqlString = "SELECT ENTRY(b) FROM BeerConsumer bc join bc.becksBeersToConsume b where Key(b) = :becksTag";
List result = em.createQuery(ejbqlString).setParameter("becksTag", tag).getResultList();
Assert.assertTrue("Incorrect number of values returned", result.size() == 1);
Assert.assertTrue("Did not return a Map.Entry", result.get(0) instanceof Map.Entry);
Map.Entry entry = (Map.Entry) result.get(0);
Assert.assertTrue("Keys do not match", comparer.compareObjects(entry.getKey(), tag));
Assert.assertTrue("Values do not match", comparer.compareObjects(entry.getValue(), becks));
} finally {
rollbackTransaction(em);
closeEntityManager(em);
}
}
Aggregations