use of org.eclipse.persistence.testing.models.jpa.inherited.Alpine in project eclipselink by eclipse-ee4j.
the class EmbeddableSuperclassJunitTest method testInsertNewAlpine.
public void testInsertNewAlpine() {
Alpine alpine = null;
EntityManager em = createEntityManager();
// Part 1 ... add an alpine beer to the collection.
BeerConsumer beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
beginTransaction(em);
try {
beerConsumer = em.merge(beerConsumer);
SerialNumber serialNumber = new SerialNumber();
em.persist(serialNumber);
alpine = new Alpine(serialNumber);
em.persist(alpine);
alpine.setBestBeforeDate(Helper.dateFromYearMonthDate(2005, 8, 18));
alpine.setAlcoholContent(5.4);
alpine.setClassification(Alpine.Classification.BITTER);
beerConsumer.addAlpineBeerToConsume(alpine, 0);
commitTransaction(em);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
throw e;
}
// Part 2 ... read from cache.
beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
// Read the beerConsumer back from the cache, check the ordering.
Vector alpinesFromCache = (Vector) beerConsumer.getAlpineBeersToConsume();
assertTrue("The new alpine was not added at the correct index in the cache.", alpinesFromCache.indexOf(alpine) == 0);
// Part 3 ... read from database.
clearCache();
em.clear();
beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
// Read the beerConsumer back from the database, check the ordering.
Vector alpinesFromDB = (Vector) beerConsumer.getAlpineBeersToConsume();
assertTrue("The new alpine was not added at the correct index when retrieving from the database.", alpinesFromDB.indexOf(alpine) == 1);
}
use of org.eclipse.persistence.testing.models.jpa.inherited.Alpine in project eclipselink by eclipse-ee4j.
the class EmbeddableSuperclassJunitTest method testReadAlpine.
public void testReadAlpine() {
Alpine alpine = createEntityManager().find(Alpine.class, m_alpineId);
assertTrue("Error on reading back an Alpine beer", alpine != null);
assertTrue("The enum was not read back in properly.", alpine.getClassification() == Alpine.Classification.BITTER);
}
use of org.eclipse.persistence.testing.models.jpa.inherited.Alpine in project eclipselink by eclipse-ee4j.
the class EmbeddableSuperclassJunitTest method testUpdateAlpine.
public void testUpdateAlpine() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Alpine alpine = em.find(Alpine.class, m_alpineId);
alpine.setBestBeforeDate(Helper.dateFromYearMonthDate(2005, 8, 19));
em.merge(alpine);
commitTransaction(em);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
throw e;
}
clearCache();
em.clear();
Alpine newAlpine = em.find(Alpine.class, m_alpineId);
assertTrue("Error updating an Alpine beer.", newAlpine.getBestBeforeDate().equals(Helper.dateFromYearMonthDate(2005, 8, 19)));
}
use of org.eclipse.persistence.testing.models.jpa.inherited.Alpine in project eclipselink by eclipse-ee4j.
the class EmbeddableSuperclassJunitTest method testInsertNewAlpineAndModifyOrderOfExistingAlpines.
public void testInsertNewAlpineAndModifyOrderOfExistingAlpines() {
Alpine alpine1 = null, alpine2 = null;
EntityManager em = createEntityManager();
// Part 1 ... add an alpine beer to the collection.
BeerConsumer beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
beginTransaction(em);
try {
beerConsumer = em.merge(beerConsumer);
SerialNumber serialNumber = new SerialNumber();
em.persist(serialNumber);
alpine1 = new Alpine(serialNumber);
em.persist(alpine1);
alpine1.setBestBeforeDate(Helper.dateFromYearMonthDate(2005, 8, 16));
alpine1.setAlcoholContent(5.6);
alpine1.setClassification(Alpine.Classification.STRONG);
beerConsumer.addAlpineBeerToConsume(alpine1, 0);
// Part 2 ... change the date, hence the index, of an alpine.
alpine2 = beerConsumer.getAlpineBeerToConsume(4);
alpine2.setBestBeforeDate(Helper.dateFromYearMonthDate(2005, 8, 20));
beerConsumer.moveAlpineBeerToConsume(4, 3);
// Part 3 ... remove 2 alpines ...
beerConsumer.removeAlpineBeerToConsume(4);
beerConsumer.removeAlpineBeerToConsume(2);
commitTransaction(em);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
throw e;
}
// Part 3 ... read from cache.
beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
// Read the beerConsumer back from the cache, check the ordering.
Vector alpinesFromCache = (Vector) beerConsumer.getAlpineBeersToConsume();
assertTrue("The new alpine was not added at the correct index in the cache.", alpinesFromCache.indexOf(alpine1) == 0);
assertTrue("The alpine was not moved to the correct index in the cache.", alpinesFromCache.indexOf(alpine2) == 2);
// Part 4 ... read from database.
clearCache();
em.clear();
beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
// Read the beerConsumer back from the database, check the ordering.
Vector alpinesFromDB = (Vector) beerConsumer.getAlpineBeersToConsume();
assertTrue("The new alpine was not added at the correct index when retrieving from the database.", alpinesFromDB.indexOf(alpine1) == 0);
assertTrue("The alpine was not moved to the correct index when retrieving from the database.", alpinesFromDB.indexOf(alpine2) == 2);
}
use of org.eclipse.persistence.testing.models.jpa.inherited.Alpine in project eclipselink by eclipse-ee4j.
the class EmbeddableSuperclassJunitTest method testUpdateAlpineThroughBeerConsumer.
public void testUpdateAlpineThroughBeerConsumer() {
int id = 0;
EntityManager em = createEntityManager();
beginTransaction(em);
try {
BeerConsumer beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
Alpine alpine = (Alpine) beerConsumer.getAlpineBeersToConsume().iterator().next();
alpine.setBestBeforeDate(Helper.dateFromYearMonthDate(2005, 9, 19));
id = alpine.getId();
commitTransaction(em);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
throw e;
}
clearCache();
em.clear();
Alpine newAlpine = em.find(Alpine.class, id);
closeEntityManager(em);
assertTrue("Error updating an Alpine beer.", newAlpine.getBestBeforeDate().equals(Helper.dateFromYearMonthDate(2005, 9, 19)));
}
Aggregations