Search in sources :

Example 1 with Image

use of org.jpwh.model.customsql.Image 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)

Aggregations

BigDecimal (java.math.BigDecimal)1 EntityManager (javax.persistence.EntityManager)1 UserTransaction (javax.transaction.UserTransaction)1 Bid (org.jpwh.model.customsql.Bid)1 Category (org.jpwh.model.customsql.Category)1 Image (org.jpwh.model.customsql.Image)1 Item (org.jpwh.model.customsql.Item)1 User (org.jpwh.model.customsql.User)1 TestData (org.jpwh.shared.util.TestData)1