List of usage examples for org.hibernate Session refresh
void refresh(Object object);
From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsSOAPImplTester.java
License:Open Source License
/** * Test method for {@link PermissionsSOAPImpl#unlockUserLock(UnlockUserLock)}. *///from w w w . j a v a 2s .c o m @Test public void testUnlockUserLockIDWrongKey() { Session ses = DataAccessActivator.getNewSession(); ses.beginTransaction(); User user = new User("locktest", "ns", "USER"); ses.persist(user); UserClass userClass = new UserClass(); userClass.setName("uc"); ses.persist(userClass); ResourcePermission perm = new ResourcePermission(); perm.setStartTime(new Date()); perm.setExpiryTime(new Date()); perm.setUserClass(userClass); perm.setType("RIG"); ses.persist(perm); UserLock lock = new UserLock(user, perm, true, "abc123"); ses.persist(lock); ses.getTransaction().commit(); /* Request. */ UnlockUserLock request = new UnlockUserLock(); UserLockType lockReq = new UserLockType(); request.setUnlockUserLock(lockReq); lockReq.setRequestorQName("TESTNS:mdiponio"); lockReq.setLockKey("wrongkey"); lockReq.setUserLockID(lock.getId().intValue()); UnlockUserLockResponse resp = this.permissions.unlockUserLock(request); assertNotNull(resp); OperationResponseType op = resp.getUnlockUserLockResponse(); assertNotNull(op); assertFalse(op.getSuccessful()); assertEquals(3, op.getFailureCode()); assertNotNull(op.getFailureReason()); ses.refresh(lock); assertTrue(lock.isIsLocked()); ses.beginTransaction(); ses.delete(lock); ses.delete(perm); ses.delete(userClass); ses.delete(user); ses.getTransaction().commit(); ses.close(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsSOAPImplTester.java
License:Open Source License
/** * Test method for {@link PermissionsSOAPImpl#unlockUserLock(UnlockUserLock)}. *///www. j a va2s . co m @Test public void testUnlockUserLockPermUser() { Session ses = DataAccessActivator.getNewSession(); ses.beginTransaction(); User user = new User("locktest", "ns", "USER"); ses.persist(user); UserClass userClass = new UserClass(); userClass.setName("uc"); ses.persist(userClass); ResourcePermission perm = new ResourcePermission(); perm.setStartTime(new Date()); perm.setExpiryTime(new Date()); perm.setUserClass(userClass); perm.setType("RIG"); ses.persist(perm); UserLock lock = new UserLock(user, perm, true, "abc123"); ses.persist(lock); ses.getTransaction().commit(); /* Request. */ UnlockUserLock request = new UnlockUserLock(); UserLockType lockReq = new UserLockType(); request.setUnlockUserLock(lockReq); lockReq.setRequestorQName("TESTNS:mdiponio"); lockReq.setLockKey("abc123"); UserLockIDUserPermSequence seq = new UserLockIDUserPermSequence(); PermissionIDType pId = new PermissionIDType(); pId.setPermissionID(perm.getId().intValue()); seq.setPermissionID(pId); UserIDType uId = new UserIDType(); uId.setUserQName(user.getNamespace() + ":" + user.getName()); seq.setUserID(uId); lockReq.setUserIDPermissionsTracker(seq); UnlockUserLockResponse resp = this.permissions.unlockUserLock(request); assertNotNull(resp); OperationResponseType op = resp.getUnlockUserLockResponse(); assertNotNull(op); assertTrue(op.getSuccessful()); assertEquals(0, op.getFailureCode()); assertNull(op.getFailureReason()); ses.refresh(lock); assertFalse(lock.isIsLocked()); ses.beginTransaction(); ses.delete(lock); ses.delete(perm); ses.delete(userClass); ses.delete(user); ses.getTransaction().commit(); ses.close(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsSOAPImplTester.java
License:Open Source License
/** * Test method for {@link PermissionsSOAPImpl#unlockUserLock(UnlockUserLock)}. */// w w w . j av a 2s .c om @Test public void testUnlockUserLockPermUserWrongKey() { Session ses = DataAccessActivator.getNewSession(); ses.beginTransaction(); User user = new User("locktest", "ns", "USER"); ses.persist(user); UserClass userClass = new UserClass(); userClass.setName("uc"); ses.persist(userClass); ResourcePermission perm = new ResourcePermission(); perm.setStartTime(new Date()); perm.setExpiryTime(new Date()); perm.setUserClass(userClass); perm.setType("RIG"); ses.persist(perm); UserLock lock = new UserLock(user, perm, true, "abc123"); ses.persist(lock); ses.getTransaction().commit(); /* Request. */ UnlockUserLock request = new UnlockUserLock(); UserLockType lockReq = new UserLockType(); request.setUnlockUserLock(lockReq); lockReq.setRequestorQName("TESTNS:mdiponio"); lockReq.setLockKey("wrongkey"); UserLockIDUserPermSequence seq = new UserLockIDUserPermSequence(); PermissionIDType pId = new PermissionIDType(); pId.setPermissionID(perm.getId().intValue()); seq.setPermissionID(pId); UserIDType uId = new UserIDType(); uId.setUserQName(user.getNamespace() + ":" + user.getName()); seq.setUserID(uId); lockReq.setUserIDPermissionsTracker(seq); UnlockUserLockResponse resp = this.permissions.unlockUserLock(request); assertNotNull(resp); OperationResponseType op = resp.getUnlockUserLockResponse(); assertNotNull(op); assertFalse(op.getSuccessful()); assertEquals(3, op.getFailureCode()); assertNotNull(op.getFailureReason()); ses.refresh(lock); assertTrue(lock.isIsLocked()); ses.beginTransaction(); ses.delete(lock); ses.delete(perm); ses.delete(userClass); ses.delete(user); ses.getTransaction().commit(); ses.close(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.tests.RigManagementTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.RigManagement#getTypeStatus(au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.types.GetTypeStatus)}. *///ww w. j a v a 2s. com @Test public void testGetTypeStatus() { Session ses = DataAccessActivator.getNewSession(); ses.beginTransaction(); RigType rt = new RigType(); rt.setName("rigmanagetest"); ses.save(rt); RigType rt2 = new RigType(); rt2.setName("rigmanagetest2"); ses.save(rt2); RigCapabilities caps = new RigCapabilities("rig,management,test"); ses.save(caps); Rig r = new Rig(); r.setOnline(false); r.setOfflineReason("test reason"); r.setName("rigmanagementrig"); 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); Rig r2 = new Rig(); r2.setName("rigmanagementrig2"); r2.setLastUpdateTimestamp(new Date()); r2.setRigCapabilities(caps); r2.setRigType(rt); r2.setActive(true); r2.setOnline(true); r2.setContactUrl("http://remotelabs/rig"); ses.save(r2); Rig r3 = new Rig(); r3.setName("rigmanagementrig3"); r3.setLastUpdateTimestamp(new Date()); r3.setRigCapabilities(caps); r3.setRigType(rt2); r3.setActive(true); r3.setOnline(true); r3.setContactUrl("http://remotelabs/rig"); ses.save(r3); ses.getTransaction().commit(); ses.refresh(rt); ses.refresh(r); ses.refresh(ro); GetTypeStatus request = new GetTypeStatus(); RigTypeIDType id = new RigTypeIDType(); id.setName(rt.getName()); request.setGetTypeStatus(id); GetTypeStatusResponse response = this.service.getTypeStatus(request); ses.beginTransaction(); ses.delete(ro); ses.delete(r); ses.delete(r2); ses.delete(r3); ses.delete(caps); ses.delete(rt); ses.delete(rt2); ses.getTransaction().commit(); assertNotNull(response); RigTypeType rigType = response.getGetTypeStatusResponse(); assertEquals(rt.getName(), rigType.getName()); assertNotNull(rigType); assertTrue(rigType.getIsOnline()); assertFalse(rigType.getIsAlarmed()); assertEquals(2, rigType.getNumberRigs()); au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.types.RigType rigs[] = rigType.getRigs(); assertNotNull(rigs); assertEquals(rigs.length, 2); for (au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.types.RigType rig : rigs) { assertNotNull(r.getName()); RigTypeIDType rtid = rig.getRigType(); assertNotNull(rtid); assertEquals(rt.getName(), rtid.getName()); assertEquals(caps.getCapabilities(), rig.getCapabilities()); assertNull(rig.getLastLogs()); assertNull(rig.getOfflinePeriods()); if (rig.getName().equals(r.getName())) { assertFalse(rig.getIsRegistered()); assertFalse(rig.getIsOnline()); assertFalse(rig.getIsInSession()); assertFalse(rig.getIsAlarmed()); assertNull(rig.getSessionUser()); assertEquals(r.getOfflineReason(), rig.getOfflineReason()); assertNull(rig.getContactURL()); } else if (rig.getName().equals(r2.getName())) { assertTrue(rig.getIsRegistered()); assertTrue(rig.getIsOnline()); assertFalse(rig.getIsInSession()); assertFalse(rig.getIsAlarmed()); assertNull(rig.getSessionUser()); assertNull(rig.getOfflineReason()); assertEquals(r2.getContactUrl(), rig.getContactURL()); } else { fail("Unknown rig name"); } } }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.tests.RigManagementTester.java
License:Open Source License
@Test public void testGetRig() { Session ses = DataAccessActivator.getNewSession(); ses.beginTransaction();// w w w .ja va 2 s . c o m RigType rt = new RigType(); rt.setName("rigmanagetest"); ses.save(rt); RigCapabilities caps = new RigCapabilities("rig,management,test"); ses.save(caps); Rig r = new Rig(); r.setActive(true); r.setOnline(true); r.setContactUrl("foo://bar"); r.setName("rigmanagementrig"); 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); RigLog l1 = new RigLog(); l1.setTimeStamp(new Date()); l1.setReason("register received"); l1.setRig(r); l1.setOldState(RigLog.NOT_REGISTERED); l1.setNewState(RigLog.OFFLINE); ses.save(l1); RigLog l2 = new RigLog(); l2.setTimeStamp(new Date(System.currentTimeMillis() + 100000)); l2.setReason("online received"); l2.setRig(r); l2.setOldState(RigLog.OFFLINE); l2.setNewState(RigLog.ONLINE); ses.save(l2); ses.getTransaction().commit(); ses.refresh(rt); ses.refresh(r); ses.refresh(ro); GetRig request = new GetRig(); RigIDType rid = new RigIDType(); rid.setName(r.getName()); request.setGetRig(rid); GetRigResponse response = this.service.getRig(request); ses.beginTransaction(); ses.delete(l1); ses.delete(l2); ses.delete(ro); ses.delete(r); ses.delete(caps); ses.delete(rt); ses.getTransaction().commit(); assertNotNull(response); au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.types.RigType rig = response.getGetRigResponse(); assertNotNull(rig); assertEquals(r.getName(), rig.getName()); assertEquals(caps.getCapabilities(), rig.getCapabilities()); RigTypeIDType tid = rig.getRigType(); assertNotNull(tid); assertEquals(rt.getName(), tid.getName()); assertTrue(rig.getIsOnline()); assertTrue(rig.getIsRegistered()); assertFalse(rig.getIsInSession()); assertNull(rig.getSessionUser()); assertFalse(rig.getIsAlarmed()); assertNull(rig.getOfflineReason()); assertEquals(r.getContactUrl(), rig.getContactURL()); RigLogType logs[] = rig.getLastLogs(); assertNotNull(logs); assertEquals(2, logs.length); RigLogType log = logs[1]; assertEquals(l1.getReason(), log.getReason()); assertEquals(log.getOldState(), RigStateType.NOT_REGISTERED); assertEquals(log.getNewState(), RigStateType.OFFLINE); log = logs[0]; assertEquals(l2.getReason(), log.getReason()); assertEquals(log.getOldState(), RigStateType.OFFLINE); assertEquals(log.getNewState(), RigStateType.ONLINE); OfflinePeriodType offs[] = rig.getOfflinePeriods(); assertNotNull(offs); assertEquals(1, offs.length); OfflinePeriodType off = offs[0]; assertEquals(ro.getId().intValue(), off.getId()); assertEquals(ro.getReason(), off.getReason()); assertEquals(ro.getStartTime().getTime(), off.getStart().getTimeInMillis()); assertEquals(ro.getEndTime().getTime(), off.getEnd().getTimeInMillis()); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.tests.RigManagementTester.java
License:Open Source License
@Test public void testGetRigAlarmed() { Session ses = DataAccessActivator.getNewSession(); ses.beginTransaction();/*from w w w . j ava2 s . co m*/ RigType rt = new RigType(); rt.setName("rigmanagetest"); ses.save(rt); RigType rt2 = new RigType(); rt2.setName("rigmanagetest2"); ses.save(rt2); RigCapabilities caps = new RigCapabilities("rig,management,test"); ses.save(caps); Rig r = new Rig(); r.setActive(true); r.setOnline(false); r.setContactUrl("foo://bar"); r.setOfflineReason("smothing broke"); r.setName("rigmanagementrig"); r.setLastUpdateTimestamp(new Date()); r.setRigCapabilities(caps); r.setRigType(rt); ses.save(r); ses.getTransaction().commit(); ses.refresh(rt); ses.refresh(r); GetRig request = new GetRig(); RigIDType rid = new RigIDType(); rid.setName(r.getName()); request.setGetRig(rid); GetRigResponse response = this.service.getRig(request); ses.beginTransaction(); ses.delete(r); ses.delete(caps); ses.delete(rt); ses.delete(rt2); ses.getTransaction().commit(); assertNotNull(response); au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.types.RigType rig = response.getGetRigResponse(); assertNotNull(rig); assertEquals(r.getName(), rig.getName()); assertEquals(caps.getCapabilities(), rig.getCapabilities()); RigTypeIDType tid = rig.getRigType(); assertNotNull(tid); assertEquals(rt.getName(), tid.getName()); assertFalse(rig.getIsOnline()); assertTrue(rig.getIsRegistered()); assertFalse(rig.getIsInSession()); assertNull(rig.getSessionUser()); assertTrue(rig.getIsAlarmed()); assertEquals(r.getOfflineReason(), rig.getOfflineReason()); assertEquals(r.getContactUrl(), rig.getContactURL()); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.RemoveLocalRigTester.java
License:Open Source License
@Test public void testRemoveRig() { Session ses = DataAccessActivator.getNewSession(); RigType type = new RigType("rlrType", 180, false); new RigTypeDao(ses).persist(type); RigCapabilities caps = new RigCapabilities("rlrA,rlrB"); new RigCapabilitiesDao(ses).persist(caps); Rig rig = new Rig(type, caps, "rlr", "http://rlr", new Date(System.currentTimeMillis() - 86400001), // A day ago true, null, false, false, true); rig.setActive(true);//from w ww.j a va2s .c om rig.setOnline(true); rig.setOfflineReason(null); new RigDao(ses).persist(rig); assertTrue(this.remove.removeRig("rlr", "Shutting down.")); ses.refresh(rig); assertFalse(rig.isActive()); assertFalse(rig.isOnline()); assertNull(rig.getContactUrl()); assertNotNull(rig.getOfflineReason()); assertEquals("Shutting down.", rig.getOfflineReason()); Date ts = rig.getLastUpdateTimestamp(); assertNotNull(ts); assertTrue(new Date().after(ts)); assertTrue(new Date(System.currentTimeMillis() - 5000).before(ts)); ses.beginTransaction(); ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate(); ses.getTransaction().commit(); ses.beginTransaction(); ses.delete(rig); ses.delete(type); ses.delete(caps); ses.getTransaction().commit(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.RemoveLocalRigTester.java
License:Open Source License
@Test public void testRemoveRigAlreadyInActive() { Session ses = DataAccessActivator.getNewSession(); RigType type = new RigType("rlrType", 180, false); new RigTypeDao(ses).persist(type); RigCapabilities caps = new RigCapabilities("rlrA,rlrB"); new RigCapabilitiesDao(ses).persist(caps); Rig rig = new Rig(type, caps, "rlr", "http://rlr", new Date(System.currentTimeMillis() - 86400001), // A day ago true, null, false, false, true); rig.setActive(false);/*from w w w . j a va2s.c o m*/ rig.setOnline(true); rig.setOfflineReason("foo bar"); new RigDao(ses).persist(rig); assertTrue(this.remove.removeRig("rlr", "Shutting down.")); ses.refresh(rig); assertFalse(rig.isActive()); assertFalse(rig.isOnline()); assertNull(rig.getContactUrl()); assertNotNull(rig.getOfflineReason()); assertEquals("Shutting down.", rig.getOfflineReason()); Date ts = rig.getLastUpdateTimestamp(); assertNotNull(ts); assertTrue(new Date().after(ts)); assertTrue(new Date(System.currentTimeMillis() - 5000).before(ts)); ses.beginTransaction(); ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate(); ses.getTransaction().commit(); ses.beginTransaction(); ses.delete(rig); ses.delete(type); ses.delete(caps); ses.getTransaction().commit(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.StatusTimeoutCheckerTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.StatusTimeoutChecker#run()}. *///from w w w .j ava 2 s . co m @Test public void testOneTimedOut() { Session ses = DataAccessActivator.getNewSession(); RigType type = new RigType("tmType", 180, false); new RigTypeDao(ses).persist(type); RigCapabilities caps = new RigCapabilities("time,out"); new RigCapabilitiesDao(ses).persist(caps); Rig tmdOut = new Rig(type, caps, "tm1", "http://tm", new Date(System.currentTimeMillis() - 86400001), // A day ago true, null, false, true, true); tmdOut.setActive(true); tmdOut.setOnline(true); tmdOut.setOfflineReason(null); RigDao rigDao = new RigDao(ses); rigDao.persist(tmdOut); this.checker.run(); ses.refresh(tmdOut); assertFalse(tmdOut.isOnline()); assertEquals("Timed out.", tmdOut.getOfflineReason()); assertFalse(tmdOut.isActive()); assertTrue(tmdOut.isManaged()); ses.beginTransaction(); ses.createQuery("DELETE RigLog WHERE rig='" + tmdOut.getId() + "'").executeUpdate(); ses.getTransaction().commit(); ses.beginTransaction(); ses.delete(tmdOut); ses.delete(type); ses.delete(caps); ses.getTransaction().commit(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.StatusTimeoutCheckerTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.StatusTimeoutChecker#run()}. *///from ww w .j a va2s . co m @Test public void testNoneTimedOut() { Session ses = DataAccessActivator.getNewSession(); RigType type = new RigType("tmType", 180, false); new RigTypeDao(ses).persist(type); RigCapabilities caps = new RigCapabilities("time,out"); new RigCapabilitiesDao(ses).persist(caps); Rig noTmdOut = new Rig(type, caps, "tm1", "http://tm", new Date(System.currentTimeMillis()), true, null, false, true, true); noTmdOut.setActive(true); noTmdOut.setOnline(true); noTmdOut.setOfflineReason(null); RigDao rigDao = new RigDao(ses); rigDao.persist(noTmdOut); this.checker.run(); ses.refresh(noTmdOut); assertTrue(noTmdOut.isOnline()); assertNull(noTmdOut.getOfflineReason()); assertTrue(noTmdOut.isActive()); assertTrue(noTmdOut.isManaged()); ses.beginTransaction(); ses.delete(noTmdOut); ses.delete(type); ses.delete(caps); ses.getTransaction().commit(); }