Search in sources :

Example 1 with Image

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);
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.conversation.Item) EntityManager(javax.persistence.EntityManager) TestData(org.jpwh.shared.util.TestData) Image(org.jpwh.model.conversation.Image)

Example 2 with Image

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);
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.conversation.Item) EntityManager(javax.persistence.EntityManager) TestData(org.jpwh.shared.util.TestData) Image(org.jpwh.model.conversation.Image)

Example 3 with Image

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();
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.conversation.Item) EntityManager(javax.persistence.EntityManager) TestData(org.jpwh.shared.util.TestData) Image(org.jpwh.model.conversation.Image) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Example 4 with Image

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();
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.conversation.Item) EntityManager(javax.persistence.EntityManager) Image(org.jpwh.model.conversation.Image) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Aggregations

EntityManager (javax.persistence.EntityManager)4 UserTransaction (javax.transaction.UserTransaction)4 Image (org.jpwh.model.conversation.Image)4 Item (org.jpwh.model.conversation.Item)4 TestData (org.jpwh.shared.util.TestData)3 JPATest (org.jpwh.env.JPATest)2 Test (org.testng.annotations.Test)2