Search in sources :

Example 16 with TestData

use of org.jpwh.shared.util.TestData 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 17 with TestData

use of org.jpwh.shared.util.TestData 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 18 with TestData

use of org.jpwh.shared.util.TestData in project microservices by pwillhan.

the class ReadOnly method storeTestData.

public FetchTestData storeTestData() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    tx.begin();
    EntityManager em = JPA.createEntityManager();
    Long[] itemIds = new Long[3];
    Long[] userIds = new Long[3];
    User johndoe = new User("johndoe");
    em.persist(johndoe);
    userIds[0] = johndoe.getId();
    User janeroe = new User("janeroe");
    em.persist(janeroe);
    userIds[1] = janeroe.getId();
    User robertdoe = new User("robertdoe");
    em.persist(robertdoe);
    userIds[2] = robertdoe.getId();
    Item item = new Item("Item One", CalendarUtil.TOMORROW.getTime(), johndoe);
    em.persist(item);
    itemIds[0] = item.getId();
    for (int i = 1; i <= 3; i++) {
        Bid bid = new Bid(item, robertdoe, new BigDecimal(9 + i));
        item.getBids().add(bid);
        em.persist(bid);
    }
    item = new Item("Item Two", CalendarUtil.TOMORROW.getTime(), johndoe);
    em.persist(item);
    itemIds[1] = item.getId();
    for (int i = 1; i <= 1; i++) {
        Bid bid = new Bid(item, janeroe, new BigDecimal(2 + i));
        item.getBids().add(bid);
        em.persist(bid);
    }
    item = new Item("Item Three", CalendarUtil.AFTER_TOMORROW.getTime(), janeroe);
    em.persist(item);
    itemIds[2] = item.getId();
    tx.commit();
    em.close();
    FetchTestData testData = new FetchTestData();
    testData.items = new TestData(itemIds);
    testData.users = new TestData(userIds);
    return testData;
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.fetching.readonly.Item) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.fetching.readonly.User) TestData(org.jpwh.shared.util.TestData) Bid(org.jpwh.model.fetching.readonly.Bid) BigDecimal(java.math.BigDecimal)

Example 19 with TestData

use of org.jpwh.shared.util.TestData in project microservices by pwillhan.

the class Subselect method storeTestData.

public FetchTestData storeTestData() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    tx.begin();
    EntityManager em = JPA.createEntityManager();
    Long[] itemIds = new Long[3];
    Long[] userIds = new Long[3];
    User johndoe = new User("johndoe");
    em.persist(johndoe);
    userIds[0] = johndoe.getId();
    User janeroe = new User("janeroe");
    em.persist(janeroe);
    userIds[1] = janeroe.getId();
    User robertdoe = new User("robertdoe");
    em.persist(robertdoe);
    userIds[2] = robertdoe.getId();
    Item item = new Item("Item One", CalendarUtil.TOMORROW.getTime(), johndoe);
    em.persist(item);
    itemIds[0] = item.getId();
    for (int i = 1; i <= 3; i++) {
        Bid bid = new Bid(item, robertdoe, new BigDecimal(9 + i));
        item.getBids().add(bid);
        em.persist(bid);
    }
    item = new Item("Item Two", CalendarUtil.TOMORROW.getTime(), johndoe);
    em.persist(item);
    itemIds[1] = item.getId();
    for (int i = 1; i <= 1; i++) {
        Bid bid = new Bid(item, janeroe, new BigDecimal(2 + i));
        item.getBids().add(bid);
        em.persist(bid);
    }
    item = new Item("Item Three", CalendarUtil.AFTER_TOMORROW.getTime(), janeroe);
    em.persist(item);
    itemIds[2] = item.getId();
    for (int i = 1; i <= 1; i++) {
        Bid bid = new Bid(item, johndoe, new BigDecimal(3 + i));
        item.getBids().add(bid);
        em.persist(bid);
    }
    tx.commit();
    em.close();
    FetchTestData testData = new FetchTestData();
    testData.items = new TestData(itemIds);
    testData.users = new TestData(userIds);
    return testData;
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.fetching.subselect.Item) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.fetching.subselect.User) TestData(org.jpwh.shared.util.TestData) Bid(org.jpwh.model.fetching.subselect.Bid) BigDecimal(java.math.BigDecimal)

Example 20 with TestData

use of org.jpwh.shared.util.TestData in project microservices by pwillhan.

the class DynamicFilter method storeTestData.

public DynamicFilterTestData storeTestData() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    tx.begin();
    EntityManager em = JPA.createEntityManager();
    DynamicFilterTestData testData = new DynamicFilterTestData();
    testData.users = new TestData(new Long[2]);
    User johndoe = new User("johndoe");
    em.persist(johndoe);
    testData.users.identifiers[0] = johndoe.getId();
    User janeroe = new User("janeroe", 100);
    em.persist(janeroe);
    testData.users.identifiers[1] = janeroe.getId();
    testData.categories = new TestData(new Long[2]);
    Category categoryOne = new Category("One");
    em.persist(categoryOne);
    testData.categories.identifiers[0] = categoryOne.getId();
    Category categoryTwo = new Category("Two");
    em.persist(categoryTwo);
    testData.categories.identifiers[1] = categoryTwo.getId();
    testData.items = new TestData(new Long[3]);
    Item itemFoo = new Item("Foo", categoryOne, johndoe);
    em.persist(itemFoo);
    testData.items.identifiers[0] = itemFoo.getId();
    Item itemBar = new Item("Bar", categoryOne, janeroe);
    em.persist(itemBar);
    testData.items.identifiers[1] = itemBar.getId();
    Item itemBaz = new Item("Baz", categoryTwo, janeroe);
    em.persist(itemBaz);
    testData.items.identifiers[2] = itemBaz.getId();
    tx.commit();
    em.close();
    return testData;
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.filtering.dynamic.Item) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.filtering.dynamic.User) Category(org.jpwh.model.filtering.dynamic.Category) TestData(org.jpwh.shared.util.TestData)

Aggregations

UserTransaction (javax.transaction.UserTransaction)26 TestData (org.jpwh.shared.util.TestData)26 EntityManager (javax.persistence.EntityManager)25 BigDecimal (java.math.BigDecimal)20 BankAccount (org.jpwh.model.bulkbatch.BankAccount)3 Bid (org.jpwh.model.bulkbatch.Bid)3 CreditCard (org.jpwh.model.bulkbatch.CreditCard)3 Item (org.jpwh.model.bulkbatch.Item)3 User (org.jpwh.model.bulkbatch.User)3 Item (org.jpwh.model.concurrency.version.Item)3 Image (org.jpwh.model.conversation.Image)3 Item (org.jpwh.model.conversation.Item)3 JPATest (org.jpwh.env.JPATest)2 StolenCreditCard (org.jpwh.model.bulkbatch.StolenCreditCard)2 Bid (org.jpwh.model.concurrency.version.Bid)2 Bid (org.jpwh.model.fetching.nplusoneselects.Bid)2 Item (org.jpwh.model.fetching.nplusoneselects.Item)2 User (org.jpwh.model.fetching.nplusoneselects.User)2 Test (org.testng.annotations.Test)2 Callable (java.util.concurrent.Callable)1