List of usage examples for org.hibernate Session save
Serializable save(Object object);
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.RigOfflineScheduleDaoTester.java
License:Open Source License
@Test public void testIsOfflineNotActive() { Session ses = this.dao.getSession(); ses.beginTransaction();/*from www.j a v a 2 s .c o m*/ RigType rt = new RigType(); rt.setName("offlineschedtype"); ses.save(rt); RigCapabilities caps = new RigCapabilities("offline,schedul,test"); ses.save(caps); Rig r = new Rig(); r.setName("offlineschedtest"); r.setLastUpdateTimestamp(new Date()); r.setRigCapabilities(caps); r.setRigType(rt); ses.save(r); RigOfflineSchedule ro = new RigOfflineSchedule(); ro.setActive(false); ro.setStartTime(new Date(System.currentTimeMillis() - 60000)); ro.setEndTime(new Date(System.currentTimeMillis() + 60000)); ro.setRig(r); ro.setReason("testcase"); ses.save(ro); ses.getTransaction().commit(); boolean off = this.dao.isOffline(r); ses.beginTransaction(); ses.delete(ro); ses.delete(r); ses.delete(rt); ses.delete(caps); ses.getTransaction().commit(); assertFalse(off); }
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.RigOfflineScheduleDaoTester.java
License:Open Source License
@Test public void testIsOfflineBefore() { Session ses = this.dao.getSession(); ses.beginTransaction();// w w w . j a v a 2 s . c om RigType rt = new RigType(); rt.setName("offlineschedtype"); ses.save(rt); RigCapabilities caps = new RigCapabilities("offline,schedul,test"); ses.save(caps); Rig r = new Rig(); r.setName("offlineschedtest"); r.setLastUpdateTimestamp(new Date()); r.setRigCapabilities(caps); r.setRigType(rt); ses.save(r); RigOfflineSchedule ro = new RigOfflineSchedule(); ro.setActive(true); ro.setStartTime(new Date(System.currentTimeMillis() - 120000)); ro.setEndTime(new Date(System.currentTimeMillis() - 60000)); ro.setRig(r); ro.setReason("testcase"); ses.save(ro); ses.getTransaction().commit(); boolean off = this.dao.isOffline(r); ses.beginTransaction(); ses.delete(ro); ses.delete(r); ses.delete(rt); ses.delete(caps); ses.getTransaction().commit(); assertFalse(off); }
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.RigOfflineScheduleDaoTester.java
License:Open Source License
@Test public void testIsOfflineAfter() { Session ses = this.dao.getSession(); ses.beginTransaction();//from ww w. j a va 2 s . c o m RigType rt = new RigType(); rt.setName("offlineschedtype"); ses.save(rt); RigCapabilities caps = new RigCapabilities("offline,schedul,test"); ses.save(caps); Rig r = new Rig(); r.setName("offlineschedtest"); r.setLastUpdateTimestamp(new Date()); r.setRigCapabilities(caps); r.setRigType(rt); ses.save(r); RigOfflineSchedule ro = new RigOfflineSchedule(); ro.setActive(true); ro.setStartTime(new Date(System.currentTimeMillis() + 60000)); ro.setEndTime(new Date(System.currentTimeMillis() + 1200000)); ro.setRig(r); ro.setReason("testcase"); ses.save(ro); ses.getTransaction().commit(); boolean off = this.dao.isOffline(r); ses.beginTransaction(); ses.delete(ro); ses.delete(r); ses.delete(rt); ses.delete(caps); ses.getTransaction().commit(); assertFalse(off); }
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.RigOfflineScheduleDaoTester.java
License:Open Source License
@Test public void testIsOfflineNot() { Session ses = this.dao.getSession(); ses.beginTransaction();/*from ww w . j a v a 2 s .c o m*/ RigType rt = new RigType(); rt.setName("offlineschedtype"); ses.save(rt); RigCapabilities caps = new RigCapabilities("offline,schedul,test"); ses.save(caps); Rig r = new Rig(); r.setName("offlineschedtest"); r.setLastUpdateTimestamp(new Date()); r.setRigCapabilities(caps); r.setRigType(rt); ses.save(r); ses.getTransaction().commit(); boolean off = this.dao.isOffline(r); ses.beginTransaction(); ses.delete(r); ses.delete(rt); ses.delete(caps); ses.getTransaction().commit(); assertFalse(off); }
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.RigOfflineScheduleDaoTester.java
License:Open Source License
@Test public void testGetOfflinePeriods() { Session ses = this.dao.getSession(); ses.beginTransaction();/*from w w w. ja v a 2 s .c om*/ RigType rt = new RigType(); rt.setName("offlineschedtype"); ses.save(rt); RigCapabilities caps = new RigCapabilities("offline,schedul,test"); ses.save(caps); Rig r = new Rig(); r.setName("offlineschedtest"); r.setLastUpdateTimestamp(new Date()); r.setRigCapabilities(caps); r.setRigType(rt); ses.save(r); RigOfflineSchedule ro = new RigOfflineSchedule(); ro.setActive(true); ro.setStartTime(new Date(System.currentTimeMillis() - 60000)); ro.setEndTime(new Date(System.currentTimeMillis() + 60000)); ro.setRig(r); ro.setReason("testcase"); ses.save(ro); RigOfflineSchedule ro1 = new RigOfflineSchedule(); ro1.setActive(true); ro1.setStartTime(new Date(System.currentTimeMillis() + 60000)); ro1.setEndTime(new Date(System.currentTimeMillis() + 1200000)); ro1.setRig(r); ro1.setReason("testcase"); ses.save(ro1); RigOfflineSchedule ro2 = new RigOfflineSchedule(); ro2.setActive(false); ro2.setStartTime(new Date(System.currentTimeMillis() + 60000)); ro2.setEndTime(new Date(System.currentTimeMillis() + 1200000)); ro2.setRig(r); ro2.setReason("testcase"); ses.save(ro2); ses.getTransaction().commit(); List<RigOfflineSchedule> list = this.dao.getOfflinePeriods(r); ses.beginTransaction(); ses.delete(ro2); ses.delete(ro1); ses.delete(ro); ses.delete(r); ses.delete(rt); ses.delete(caps); ses.getTransaction().commit(); assertNotNull(list); assertEquals(list.size(), 2); }
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.RigTypeDaoTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigTypeDao#findByName(java.lang.String)}. *//* ww w. j a v a 2s .c o m*/ @Test public void testFindByName() { Session ses = DataAccessActivator.getNewSession(); RigType type = new RigType(); type.setName("testType"); type.setLogoffGraceDuration(600); ses.beginTransaction(); ses.save(type); ses.getTransaction().commit(); ses.close(); RigType rigType = this.dao.findByName("testType"); assertNotNull(rigType); assertEquals(type.getId(), rigType.getId()); assertEquals(type.getLogoffGraceDuration(), rigType.getLogoffGraceDuration()); this.dao.delete(rigType); }
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.RigTypeDaoTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigTypeDao#loadOrCreate(String)} *//*from www.j ava2 s . c o m*/ @Test public void testLoadOrCreateExists() { Session ses = DataAccessActivator.getNewSession(); RigType type = new RigType(); type.setName("testType"); type.setLogoffGraceDuration(600); type.setCodeAssignable(true); ses.beginTransaction(); ses.save(type); ses.getTransaction().commit(); ses.close(); RigType same = this.dao.loadOrCreate("testType"); assertNotNull(same); assertEquals("testType", same.getName()); assertTrue(same.isCodeAssignable()); assertEquals(600, same.getLogoffGraceDuration()); this.dao.delete(same); }
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.UserAssociationDaoTester.java
License:Open Source License
public void testDeleteUserUserClass() { Session ses = this.dao.getSession(); ses.beginTransaction();/* w ww. ja va 2 s.com*/ User us = new User("user", "userns", "ADMIN"); ses.save(us); UserClass uc = new UserClass(); uc.setName("clazz"); uc.setPriority((short) 10); uc.setActive(true); uc.setKickable(true); uc.setQueuable(true); uc.setBookable(true); uc.setUsersLockable(true); ses.save(uc); UserAssociationId id = new UserAssociationId(us.getId(), uc.getId()); UserAssociation assoc = new UserAssociation(id, uc, us); ses.save(assoc); ses.getTransaction().commit(); this.dao.delete(us, uc); int num = (Integer) this.dao.getSession().createCriteria(UserAssociation.class) .add(Restrictions.eq("user", us)).add(Restrictions.eq("userClass", uc)) .setProjection(Projections.rowCount()).uniqueResult(); assertEquals(0, num); ses.beginTransaction(); ses.delete(us); ses.delete(uc); ses.getTransaction().commit(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.UserAssociationDaoTester.java
License:Open Source License
public void testDeleteUserUserClassNoDelete() { Session ses = this.dao.getSession(); ses.beginTransaction();//from w w w. j a v a2 s .co m User us = new User("user", "userns", "ADMIN"); ses.save(us); User us2 = new User("user2", "userns", "ADMIN"); ses.save(us2); UserClass uc = new UserClass(); uc.setName("clazz"); uc.setPriority((short) 10); uc.setActive(true); uc.setKickable(true); uc.setQueuable(true); uc.setBookable(true); uc.setUsersLockable(true); ses.save(uc); UserAssociationId id = new UserAssociationId(us.getId(), uc.getId()); UserAssociation assoc = new UserAssociation(id, uc, us); ses.save(assoc); ses.getTransaction().commit(); this.dao.delete(us2, uc); int num = (Integer) this.dao.getSession().createCriteria(UserAssociation.class) .add(Restrictions.eq("user", us)).add(Restrictions.eq("userClass", uc)) .setProjection(Projections.rowCount()).uniqueResult(); assertEquals(1, num); ses.beginTransaction(); ses.delete(assoc); ses.delete(us); ses.delete(us2); ses.delete(uc); ses.getTransaction().commit(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.UserClassDaoTester.java
License:Open Source License
@Test public void testDeleteId() { Session ses = DataAccessActivator.getNewSession(); ses.beginTransaction();// ww w. j av a 2 s. co m RigType ty = new RigType("type123", 10, false); ses.save(ty); RigCapabilities caps = new RigCapabilities("a,b"); ses.save(caps); Rig rig = new Rig(ty, caps, "rig123", "http://rig/", new Date(), true, null, false, true, true); ses.save(rig); User us = new User("user", "userns", "ADMIN"); ses.save(us); UserClass uc = new UserClass(); uc.setName("clazz"); uc.setPriority((short) 10); uc.setActive(true); uc.setKickable(true); uc.setQueuable(true); uc.setBookable(true); uc.setUsersLockable(true); ses.save(uc); ResourcePermission perm = new ResourcePermission(); perm.setUserClass(uc); perm.setType("RIG"); perm.setActivityDetected(false); perm.setAllowedExtensions((short) 5); perm.setSessionActivityTimeout(300); perm.setSessionDuration(3600); perm.setExtensionDuration(300); perm.setQueueActivityTimeout(300); perm.setExpiryTime(new Date()); perm.setStartTime(new Date()); perm.setRig(rig); ses.save(perm); UserAssociationId id = new UserAssociationId(us.getId(), uc.getId()); UserAssociation assoc = new UserAssociation(id, uc, us); ses.save(assoc); ses.getTransaction().commit(); this.dao.delete(uc.getId()); GenericDao<ResourcePermission> rpDao = new GenericDao<ResourcePermission>(ResourcePermission.class); assertNull(rpDao.get(perm.getId())); ses.refresh(us); assertEquals(0, us.getUserAssociations().size()); ses.beginTransaction(); ses.delete(us); ses.delete(rig); ses.delete(caps); ses.delete(ty); ses.getTransaction().commit(); }