Search in sources :

Example 1 with TestData

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

the class BulkStatementsCriteria method storeTestData.

public BulkBatchTestData 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);
    }
    em.persist(new BankAccount(janeroe, "Jane Roe", "445566", "One Percent Bank Inc.", "999"));
    em.persist(new CreditCard(johndoe, "John Doe", "1234123412341234", "06", "2015"));
    tx.commit();
    em.close();
    BulkBatchTestData testData = new BulkBatchTestData();
    testData.items = new TestData(itemIds);
    testData.users = new TestData(userIds);
    return testData;
}
Also used : UserTransaction(javax.transaction.UserTransaction) User(org.jpwh.model.bulkbatch.User) TestData(org.jpwh.shared.util.TestData) BankAccount(org.jpwh.model.bulkbatch.BankAccount) BigDecimal(java.math.BigDecimal) CreditCard(org.jpwh.model.bulkbatch.CreditCard) Item(org.jpwh.model.bulkbatch.Item) EntityManager(javax.persistence.EntityManager) Bid(org.jpwh.model.bulkbatch.Bid)

Example 2 with TestData

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

the class BulkStatementsSQL method storeTestData.

public BulkBatchTestData 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);
    }
    em.persist(new BankAccount(janeroe, "Jane Roe", "445566", "One Percent Bank Inc.", "999"));
    em.persist(new CreditCard(johndoe, "John Doe", "1234123412341234", "06", "2015"));
    tx.commit();
    em.close();
    BulkBatchTestData testData = new BulkBatchTestData();
    testData.items = new TestData(itemIds);
    testData.users = new TestData(userIds);
    return testData;
}
Also used : UserTransaction(javax.transaction.UserTransaction) User(org.jpwh.model.bulkbatch.User) TestData(org.jpwh.shared.util.TestData) BankAccount(org.jpwh.model.bulkbatch.BankAccount) BigDecimal(java.math.BigDecimal) CreditCard(org.jpwh.model.bulkbatch.CreditCard) StolenCreditCard(org.jpwh.model.bulkbatch.StolenCreditCard) Item(org.jpwh.model.bulkbatch.Item) EntityManager(javax.persistence.EntityManager) Bid(org.jpwh.model.bulkbatch.Bid)

Example 3 with TestData

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

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

the class LazyProxyCollections method storeTestData.

public FetchTestData storeTestData() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    tx.begin();
    EntityManager em = JPA.createEntityManager();
    Long[] categoryIds = new Long[3];
    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();
    Category category = new Category("Category One");
    em.persist(category);
    categoryIds[0] = category.getId();
    Item item = new Item("Item One", CalendarUtil.TOMORROW.getTime(), johndoe);
    em.persist(item);
    itemIds[0] = item.getId();
    category.getItems().add(item);
    item.getCategories().add(category);
    for (int i = 1; i <= 3; i++) {
        Bid bid = new Bid(item, robertdoe, new BigDecimal(9 + i));
        item.getBids().add(bid);
        em.persist(bid);
    }
    category = new Category("Category Two");
    em.persist(category);
    categoryIds[1] = category.getId();
    item = new Item("Item Two", CalendarUtil.TOMORROW.getTime(), johndoe);
    em.persist(item);
    itemIds[1] = item.getId();
    category.getItems().add(item);
    item.getCategories().add(category);
    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();
    category.getItems().add(item);
    item.getCategories().add(category);
    category = new Category("Category Three");
    em.persist(category);
    categoryIds[2] = category.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.proxy.Item) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.fetching.proxy.User) Category(org.jpwh.model.fetching.proxy.Category) TestData(org.jpwh.shared.util.TestData) Bid(org.jpwh.model.fetching.proxy.Bid) BigDecimal(java.math.BigDecimal)

Example 5 with TestData

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

the class NPlusOneSelects 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.nplusoneselects.Item) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.fetching.nplusoneselects.User) TestData(org.jpwh.shared.util.TestData) Bid(org.jpwh.model.fetching.nplusoneselects.Bid) BigDecimal(java.math.BigDecimal)

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