@Test public void testInsert() throws Exception { final Connection cnn = databaseTestUtils.getConnection(); try { final int userId = databaseTestUtils.ensureTestUser(cnn); // insert the entity final UserSessionEntityHandler handler = new UserSessionEntityHandler(); final int userSessionId = handler.insert(cnn, userId); assertTrue("Expected the insert to return a valid ID", userSessionId > 0); } finally { DbUtils.close(cnn); } }
@Test public void testFindUserSessionById() throws Exception { final Connection cnn = databaseTestUtils.getConnection(); try { int userId = databaseTestUtils.ensureTestUser(cnn); int sessionId = insertUserSession(cnn, userId); // insert the entity final UserSessionEntityHandler handler = new UserSessionEntityHandler(); final UserSession userSession = handler.findUserSessionById(cnn, sessionId); assertNotNull("Expected a session to be retrieved", userSession); assertEquals( "Expected the ID of the loaded session to be the same", Integer.valueOf(sessionId), userSession.getId()); } finally { DbUtils.close(cnn); } }