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