use of org.eclipse.persistence.testing.models.jpa.inherited.RedStripe in project eclipselink by eclipse-ee4j.
the class InheritedModelJunitTest method testVersionUpdateOnElementCollectionChange.
public void testVersionUpdateOnElementCollectionChange() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
BeerConsumer beerConsumer = (BeerConsumer) em.createQuery("select b from BeerConsumer b join b.redStripes r").getResultList().get(0);
int currentVersion = beerConsumer.getVersion();
beerConsumer.getRedStripes().put("version", new RedStripe(Double.valueOf("343")));
commitTransaction(em);
assertTrue("Did not increment version for change to element collection", beerConsumer.getVersion() == ++currentVersion);
} 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.inherited.RedStripe in project eclipselink by eclipse-ee4j.
the class InheritedModelJunitTest method testEmbeddableAggregateCollectionAndAggregate.
// Bug 334175
public void testEmbeddableAggregateCollectionAndAggregate() {
EntityManager em = createEntityManager();
beginTransaction(em);
BeerConsumer consumer = new BeerConsumer();
consumer.setName("Lionel");
RedStripe rs = new RedStripe();
rs.setAlcoholContent(4.5);
consumer.addRedStripeByAlcoholContent(rs);
em.persist(consumer);
Official official = new Official();
official.setName("George");
rs = new RedStripe();
rs.setAlcoholContent(4.6);
official.setLastRedStripeConsumed(rs);
em.persist(official);
em.flush();
em.clear();
clearCache();
consumer = em.find(BeerConsumer.class, consumer.getId());
assertNotNull("BeerConsumer had null red stripes.", consumer.getRedStripes());
assertTrue("BeerConsumer had wrong number of red stripes.", consumer.getRedStripesByAlcoholContent().size() == 1);
assertTrue("BeerConsumer had wrong red stripe.", consumer.getRedStripesByAlcoholContent().get(4.5) != null);
official = em.find(Official.class, official.getId());
assertNotNull("Official had null red stripe.", official.getLastRedStripeConsumed());
assertTrue("Official had the wrong red stripe", official.getLastRedStripeConsumed().getAlcoholContent() == 4.6);
rollbackTransaction(em);
}
use of org.eclipse.persistence.testing.models.jpa.inherited.RedStripe in project eclipselink by eclipse-ee4j.
the class InheritedModelJunitTest method testRedStripeExpertConsumer.
public void testRedStripeExpertConsumer() {
EntityManager em = createEntityManager();
beginTransaction(em);
ExpertBeerConsumer initialEBC = new ExpertBeerConsumer();
initialEBC.setAccredidation(new Accredidation());
int beerConsumerId = 0;
try {
RedStripe redStripe1 = new RedStripe();
redStripe1.setAlcoholContent(5.0);
initialEBC.addRedStripeBeersToConsume(redStripe1, "1");
RedStripe redStripe2 = new RedStripe();
redStripe2.setAlcoholContent(5.0);
initialEBC.addRedStripeBeersToConsume(redStripe2, "2");
initialEBC.setName("Expert Red Stripe Consumer");
em.persist(initialEBC);
beerConsumerId = initialEBC.getId();
commitTransaction(em);
} catch (RuntimeException e) {
e.printStackTrace();
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
fail("An exception was caught during create operation: [" + e.getMessage() + "]");
}
closeEntityManager(em);
clearCache();
em = createEntityManager();
ExpertBeerConsumer refreshedEBC = em.find(ExpertBeerConsumer.class, beerConsumerId);
assertTrue("The expert beer consumer read back did not match the original", getServerSession().compareObjects(initialEBC, refreshedEBC));
}
use of org.eclipse.persistence.testing.models.jpa.inherited.RedStripe in project eclipselink by eclipse-ee4j.
the class InheritedModelJunitTest method testRedStripeNoviceConsumer.
public void testRedStripeNoviceConsumer() {
EntityManager em = createEntityManager();
beginTransaction(em);
NoviceBeerConsumer initialNBC = new NoviceBeerConsumer();
initialNBC.setAccredidation(new Accredidation());
int beerConsumerId = 0;
try {
RedStripe redStripe1 = new RedStripe();
redStripe1.setAlcoholContent(5.0);
initialNBC.addRedStripeBeersToConsume(redStripe1, "3");
RedStripe redStripe2 = new RedStripe();
redStripe2.setAlcoholContent(5.0);
initialNBC.addRedStripeBeersToConsume(redStripe2, "4");
initialNBC.setName("Novice Red Stripe Consumer");
em.persist(initialNBC);
beerConsumerId = initialNBC.getId();
commitTransaction(em);
} catch (RuntimeException e) {
e.printStackTrace();
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
fail("An exception was caught during create operation: [" + e.getMessage() + "]");
}
closeEntityManager(em);
clearCache();
em = createEntityManager();
NoviceBeerConsumer refreshedNBC = em.find(NoviceBeerConsumer.class, beerConsumerId);
assertTrue("The novice beer consumer read back did not match the original", getServerSession().compareObjects(initialNBC, refreshedNBC));
}
use of org.eclipse.persistence.testing.models.jpa.inherited.RedStripe in project eclipselink by eclipse-ee4j.
the class InheritedModelJunitTest method testElementCollectionMapEmbeddable.
public void testElementCollectionMapEmbeddable() {
EntityManager em = createEntityManager();
try {
// Create an official
beginTransaction(em);
BeerConsumer consumer = new BeerConsumer();
consumer.setName("Lionel");
RedStripe rs = new RedStripe();
rs.setAlcoholContent(4.5);
consumer.addRedStripeByAlcoholContent(rs);
em.persist(consumer);
em.flush();
rs = new RedStripe();
rs.setAlcoholContent(3.5);
consumer.addRedStripeByAlcoholContent(rs);
em.flush();
} finally {
rollbackTransaction(em);
}
}
Aggregations