Search in sources :

Example 11 with UserTestDbo

use of org.webpieces.plugins.hibernate.app.dbo.UserTestDbo in project webpieces by deanhiller.

the class TestSyncHibernate method testHibernateNoUserIdParamWillSaveNewUser.

@Test
public void testHibernateNoUserIdParamWillSaveNewUser() {
    String email = "test1";
    HttpDummyRequest req = Requests.createPostRequest("/testmerge", "user.email", email, "user.name", "blah1", "user.firstName", "blah2");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    UserTestDbo user2 = loadByEmail(email);
    //name changed
    Assert.assertEquals("blah1", user2.getName());
    //firstname changed
    Assert.assertEquals("blah2", user2.getFirstName());
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 12 with UserTestDbo

use of org.webpieces.plugins.hibernate.app.dbo.UserTestDbo in project webpieces by deanhiller.

the class TestSyncHibernate method loadByEmail.

private UserTestDbo loadByEmail(String email) {
    EntityManagerFactory factory = Persistence.createEntityManagerFactory(HibernateAppMeta.PERSISTENCE_TEST_UNIT);
    EntityManager mgr = factory.createEntityManager();
    EntityTransaction tx = mgr.getTransaction();
    tx.begin();
    UserTestDbo user = UserTestDbo.findByEmailId(mgr, email);
    tx.commit();
    return user;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 13 with UserTestDbo

use of org.webpieces.plugins.hibernate.app.dbo.UserTestDbo in project webpieces by deanhiller.

the class CrudTestController method postDeleteUser.

public Redirect postDeleteUser(Integer id) {
    UserTestDbo user = Em.get().getReference(UserTestDbo.class, id);
    Em.get().remove(user);
    Em.get().flush();
    Current.flash().setMessage("User " + user.getFirstName() + " " + user.getLastName() + " was deleted");
    return Actions.redirect(HibernateRouteId.LIST_USERS);
}
Also used : UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)

Example 14 with UserTestDbo

use of org.webpieces.plugins.hibernate.app.dbo.UserTestDbo in project webpieces by deanhiller.

the class TestFlashAndSelect method loadDataInDb.

public static UserTestDbo loadDataInDb() {
    String email = "dean2@sync.xsoftware.biz";
    //populate database....
    EntityManagerFactory factory = Persistence.createEntityManagerFactory(HibernateAppMeta.PERSISTENCE_TEST_UNIT);
    EntityManager mgr = factory.createEntityManager();
    EntityTransaction tx = mgr.getTransaction();
    tx.begin();
    UserTestDbo manager = new UserTestDbo();
    manager.setEmail("asdf@asf.com");
    manager.setName("somadsf");
    UserTestDbo user = new UserTestDbo();
    user.setEmail(email);
    user.setName("SomeName");
    user.setFirstName("Dean");
    user.setLastName("Hill");
    user.setLevelOfEducation(LevelEducation.KINDERGARTEN);
    user.setManager(manager);
    UserRoleDbo role1 = new UserRoleDbo(user, Role.DELINQUINT);
    UserRoleDbo role2 = new UserRoleDbo(user, Role.BADASS);
    mgr.persist(manager);
    mgr.persist(user);
    mgr.persist(role1);
    mgr.persist(role2);
    mgr.flush();
    tx.commit();
    return user;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) EntityManagerFactory(javax.persistence.EntityManagerFactory) UserRoleDbo(org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo)

Example 15 with UserTestDbo

use of org.webpieces.plugins.hibernate.app.dbo.UserTestDbo in project webpieces by deanhiller.

the class TestSyncHibernate method testHibernateNoUserIdWillSaveNewUser.

@Test
public void testHibernateNoUserIdWillSaveNewUser() {
    String email = "test2";
    HttpDummyRequest req = Requests.createPostRequest("/testmerge", "user.id", "", "user.email", email, "user.name", "blah1", "user.firstName", "blah2", "user.levelOfEducation", LevelEducation.COLLEGE.getDbCode() + "");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    UserTestDbo user2 = loadByEmail(email);
    //name changed
    Assert.assertEquals("blah1", user2.getName());
    //firstname changed
    Assert.assertEquals("blah2", user2.getFirstName());
    Assert.assertEquals(LevelEducation.COLLEGE, user2.getLevelOfEducation());
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Aggregations

UserTestDbo (org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)20 EntityManager (javax.persistence.EntityManager)13 EntityManagerFactory (javax.persistence.EntityManagerFactory)6 EntityTransaction (javax.persistence.EntityTransaction)6 Query (javax.persistence.Query)3 Test (org.junit.Test)3 WebserverForTest (org.webpieces.webserver.WebserverForTest)3 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)3 FullResponse (org.webpieces.webserver.test.FullResponse)3 HttpDummyRequest (org.webpieces.webserver.test.HttpDummyRequest)3 UserRoleDbo (org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Singleton (javax.inject.Singleton)1 Current (org.webpieces.ctx.api.Current)1 Em (org.webpieces.plugins.hibernate.Em)1 ADD_USER_PAGE (org.webpieces.plugins.hibernate.app.HibernateRouteId.ADD_USER_PAGE)1 EDIT_USER_PAGE (org.webpieces.plugins.hibernate.app.HibernateRouteId.EDIT_USER_PAGE)1 LevelEducation (org.webpieces.plugins.hibernate.app.dbo.LevelEducation)1