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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations