use of org.jpwh.model.conversation.Image in project microservices by pwillhan.
the class ExtendedPC method storeItemImagesTestData.
/* ################################################################################### */
public TestData storeItemImagesTestData() throws Exception {
UserTransaction tx = TM.getUserTransaction();
tx.begin();
EntityManager em = JPA.createEntityManager();
Long[] ids = new Long[1];
Item item = new Item();
item.setName("Some Item");
em.persist(item);
ids[0] = item.getId();
for (int i = 1; i <= 3; i++) {
item.getImages().add(new Image("Image " + i, "image" + i + ".jpg", 640, 480));
}
tx.commit();
em.close();
return new TestData(ids);
}
use of org.jpwh.model.conversation.Image in project microservices by pwillhan.
the class Detached method storeItemImagesTestData.
/* ################################################################################### */
public TestData storeItemImagesTestData() throws Exception {
UserTransaction tx = TM.getUserTransaction();
tx.begin();
EntityManager em = JPA.createEntityManager();
Long[] ids = new Long[1];
Item item = new Item();
item.setName("Some Item");
em.persist(item);
ids[0] = item.getId();
for (int i = 1; i <= 3; i++) {
item.getImages().add(new Image("Image " + i, "image" + i + ".jpg", 640, 480));
}
tx.commit();
em.close();
return new TestData(ids);
}
use of org.jpwh.model.conversation.Image in project microservices by pwillhan.
the class ExtendedPC method conversationEditItem.
// TODO: Broken on MySQL https://hibernate.atlassian.net/browse/HHH-8402
@Test(groups = { "H2", "ORACLE", "POSTGRESQL" })
public void conversationEditItem() throws Exception {
final TestData testData = storeItemImagesTestData();
Long ITEM_ID = testData.getFirstId();
// First event in conversation
CreateEditItemService conversation = new CreateEditItemService();
Item item = conversation.getItem(ITEM_ID);
item.setName("New Name");
// Persistence context is still open, load collection on demand!
item.getImages().add(new Image("Foo", "foo.jpg", 800, 600));
// Possibly more events, loading necessary data into conversation...
// Final event in conversation
// Flush and close persistence context
conversation.commit();
{
UserTransaction tx = TM.getUserTransaction();
try {
tx.begin();
EntityManager em = JPA.createEntityManager();
item = em.find(Item.class, item.getId());
assertEquals(item.getName(), "New Name");
assertEquals(item.getImages().size(), 4);
} finally {
TM.rollback();
}
}
}
use of org.jpwh.model.conversation.Image in project microservices by pwillhan.
the class ExtendedPC method conversationCreateItem.
// TODO: Broken on MySQL https://hibernate.atlassian.net/browse/HHH-8402
@Test(groups = { "H2", "ORACLE", "POSTGRESQL" })
public void conversationCreateItem() throws Exception {
Item item = new Item("Some Item");
item.getImages().add(new Image("Foo", "foo.jpg", 800, 600));
CreateEditItemService conversation = new CreateEditItemService();
conversation.storeItem(item);
conversation.commit();
{
UserTransaction tx = TM.getUserTransaction();
try {
tx.begin();
EntityManager em = JPA.createEntityManager();
item = em.find(Item.class, item.getId());
assertEquals(item.getName(), "Some Item");
assertEquals(item.getImages().size(), 1);
} finally {
TM.rollback();
}
}
}
Aggregations