Search in sources :

Example 6 with TestData

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

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

Example 7 with TestData

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

the class QueryingTest method storeTestData.

public TestDataCategoriesItems storeTestData() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    tx.begin();
    EntityManager em = JPA.createEntityManager();
    Long[] categoryIds = new Long[4];
    Long[] itemIds = new Long[3];
    Long[] userIds = new Long[3];
    User johndoe = new User("johndoe", "John", "Doe");
    Address homeAddress = new Address("Some Street 123", "12345", "Some City");
    johndoe.setActivated(true);
    johndoe.setHomeAddress(homeAddress);
    em.persist(johndoe);
    userIds[0] = johndoe.getId();
    User janeroe = new User("janeroe", "Jane", "Roe");
    janeroe.setActivated(true);
    janeroe.setHomeAddress(new Address("Other Street 11", "1234", "Other City"));
    em.persist(janeroe);
    userIds[1] = janeroe.getId();
    User robertdoe = new User("robertdoe", "Robert", "Doe");
    em.persist(robertdoe);
    userIds[2] = robertdoe.getId();
    Category categoryOne = new Category("One");
    em.persist(categoryOne);
    categoryIds[0] = categoryOne.getId();
    Item item = new Item("Foo", CalendarUtil.TOMORROW.getTime(), johndoe);
    item.setBuyNowPrice(new BigDecimal("19.99"));
    em.persist(item);
    itemIds[0] = item.getId();
    categoryOne.getItems().add(item);
    item.getCategories().add(categoryOne);
    for (int i = 1; i <= 3; i++) {
        Bid bid = new Bid(item, robertdoe, new BigDecimal(98 + i));
        item.getBids().add(bid);
        em.persist(bid);
    }
    item.getImages().add(new Image("Foo", "foo.jpg", 640, 480));
    item.getImages().add(new Image("Bar", "bar.jpg", 800, 600));
    item.getImages().add(new Image("Baz", "baz.jpg", 1024, 768));
    Category categoryTwo = new Category("Two");
    categoryTwo.setParent(categoryOne);
    em.persist(categoryTwo);
    categoryIds[1] = categoryTwo.getId();
    item = new Item("Bar", CalendarUtil.TOMORROW.getTime(), johndoe);
    em.persist(item);
    itemIds[1] = item.getId();
    categoryTwo.getItems().add(item);
    item.getCategories().add(categoryTwo);
    Bid bid = new Bid(item, janeroe, new BigDecimal("4.99"));
    item.getBids().add(bid);
    em.persist(bid);
    item = new Item("Baz", CalendarUtil.AFTER_TOMORROW.getTime(), janeroe);
    item.setApproved(false);
    em.persist(item);
    itemIds[2] = item.getId();
    categoryTwo.getItems().add(item);
    item.getCategories().add(categoryTwo);
    Category categoryThree = new Category("Three");
    categoryThree.setParent(categoryOne);
    em.persist(categoryThree);
    categoryIds[2] = categoryThree.getId();
    Category categoryFour = new Category("Four");
    categoryFour.setParent(categoryTwo);
    em.persist(categoryFour);
    categoryIds[3] = categoryFour.getId();
    CreditCard cc = new CreditCard("John Doe", "1234123412341234", "06", "2015");
    em.persist(cc);
    BankAccount ba = new BankAccount("Jane Roe", "445566", "One Percent Bank Inc.", "999");
    em.persist(ba);
    LogRecord lr = new LogRecord("johndoe", "This is a log message");
    em.persist(lr);
    lr = new LogRecord("johndoe", "Another log message");
    em.persist(lr);
    tx.commit();
    em.close();
    TestDataCategoriesItems testData = new TestDataCategoriesItems();
    testData.categories = new TestData(categoryIds);
    testData.items = new TestData(itemIds);
    testData.users = new TestData(userIds);
    return testData;
}
Also used : UserTransaction(javax.transaction.UserTransaction) User(org.jpwh.model.querying.User) Category(org.jpwh.model.querying.Category) Address(org.jpwh.model.querying.Address) TestData(org.jpwh.shared.util.TestData) BankAccount(org.jpwh.model.inheritance.tableperclass.BankAccount) Image(org.jpwh.model.querying.Image) BigDecimal(java.math.BigDecimal) CreditCard(org.jpwh.model.inheritance.tableperclass.CreditCard) Item(org.jpwh.model.querying.Item) EntityManager(javax.persistence.EntityManager) LogRecord(org.jpwh.model.querying.LogRecord) Bid(org.jpwh.model.querying.Bid)

Example 8 with TestData

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

the class CustomSQL method create.

public CustomSQLTestData create() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    tx.begin();
    EntityManager em = JPA.createEntityManager();
    CustomSQLTestData testData = new CustomSQLTestData();
    testData.categories = new TestData(new Long[1]);
    testData.items = new TestData(new Long[2]);
    testData.bids = new TestData(new Long[3]);
    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");
    em.persist(janeroe);
    testData.users.identifiers[1] = janeroe.getId();
    Category category = new Category();
    category.setName("Foo");
    em.persist(category);
    testData.categories.identifiers[0] = category.getId();
    Item item = new Item();
    item.setName("Some item");
    item.setCategory(category);
    item.setSeller(johndoe);
    item.setAuctionEnd(CalendarUtil.TOMORROW.getTime());
    item.getImages().add(new Image("foo.jpg", 640, 480));
    item.getImages().add(new Image("bar.jpg", 800, 600));
    item.getImages().add(new Image("baz.jpg", 640, 480));
    em.persist(item);
    testData.items.identifiers[0] = item.getId();
    for (int i = 1; i <= 3; i++) {
        Bid bid = new Bid();
        bid.setAmount(new BigDecimal(10 + i));
        bid.setItem(item);
        bid.setBidder(janeroe);
        em.persist(bid);
        testData.bids.identifiers[i - 1] = bid.getId();
    }
    Item otherItem = new Item(category, "Inactive item", CalendarUtil.TOMORROW.getTime(), johndoe);
    otherItem.setActive(false);
    em.persist(otherItem);
    tx.commit();
    em.close();
    return testData;
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.customsql.Item) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.customsql.User) Category(org.jpwh.model.customsql.Category) TestData(org.jpwh.shared.util.TestData) Image(org.jpwh.model.customsql.Image) Bid(org.jpwh.model.customsql.Bid) BigDecimal(java.math.BigDecimal)

Example 9 with TestData

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

the class CartesianProduct 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);
    item.getImages().add("foo.jpg");
    item.getImages().add("bar.jpg");
    item.getImages().add("baz.jpg");
    em.persist(item);
    itemIds[0] = item.getId();
    for (int i = 1; i <= 3; i++) {
        Bid bid = new Bid(item, new BigDecimal(9 + i));
        item.getBids().add(bid);
        em.persist(bid);
    }
    item = new Item("Item Two", CalendarUtil.TOMORROW.getTime(), johndoe);
    item.getImages().add("a.jpg");
    item.getImages().add("b.jpg");
    em.persist(item);
    itemIds[1] = item.getId();
    for (int i = 1; i <= 1; i++) {
        Bid bid = new Bid(item, 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.cartesianproduct.Item) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.fetching.cartesianproduct.User) TestData(org.jpwh.shared.util.TestData) Bid(org.jpwh.model.fetching.cartesianproduct.Bid) BigDecimal(java.math.BigDecimal)

Example 10 with TestData

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

the class EagerJoin 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.eagerjoin.Item) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.fetching.eagerjoin.User) TestData(org.jpwh.shared.util.TestData) Bid(org.jpwh.model.fetching.eagerjoin.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