Search in sources :

Example 1 with User

use of org.jpwh.model.customsql.procedures.User in project microservices by pwillhan.

the class CRUDProcedures method update.

@Test(groups = "MYSQL")
public void update() throws Exception {
    CustomSQLTestData testData = create();
    Long USER_ID = testData.users.getFirstId();
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        {
            User user = em.find(User.class, USER_ID);
            user.setUsername("jdoe");
            em.flush();
        }
        em.clear();
        loadEventListener.reset();
        tx.commit();
        em.close();
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.customsql.procedures.User) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Example 2 with User

use of org.jpwh.model.customsql.procedures.User in project microservices by pwillhan.

the class CRUDProcedures method read.

@Test(groups = "MYSQL")
public void read() throws Exception {
    CustomSQLTestData testData = create();
    Long USER_ID = testData.users.getFirstId();
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        {
            User user = em.find(User.class, USER_ID);
            assertEquals(loadEventListener.getLoadCount(User.class), 1);
            assertEquals(user.getId(), USER_ID);
        }
        em.clear();
        loadEventListener.reset();
        tx.commit();
        em.close();
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.customsql.procedures.User) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Example 3 with User

use of org.jpwh.model.customsql.procedures.User in project microservices by pwillhan.

the class CRUDProcedures method create.

public CustomSQLTestData create() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    tx.begin();
    EntityManager em = JPA.createEntityManager();
    CustomSQLTestData testData = new CustomSQLTestData();
    testData.users = new TestData(new Long[2]);
    User johndoe = new User("johndoe");
    em.persist(johndoe);
    testData.users.identifiers[0] = johndoe.getId();
    tx.commit();
    em.close();
    return testData;
}
Also used : UserTransaction(javax.transaction.UserTransaction) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.customsql.procedures.User) TestData(org.jpwh.shared.util.TestData)

Example 4 with User

use of org.jpwh.model.customsql.procedures.User in project microservices by pwillhan.

the class CRUDProcedures method delete.

@Test(groups = "MYSQL")
public void delete() throws Exception {
    CustomSQLTestData testData = create();
    Long USER_ID = testData.users.getFirstId();
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        {
            User user = em.find(User.class, USER_ID);
            em.remove(user);
            em.flush();
            em.clear();
            assertNull(em.find(User.class, USER_ID));
        }
        em.clear();
        loadEventListener.reset();
        tx.commit();
        em.close();
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.customsql.procedures.User) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Aggregations

EntityManager (javax.persistence.EntityManager)4 UserTransaction (javax.transaction.UserTransaction)4 User (org.jpwh.model.customsql.procedures.User)4 JPATest (org.jpwh.env.JPATest)3 Test (org.testng.annotations.Test)3 TestData (org.jpwh.shared.util.TestData)1