List of usage examples for org.hibernate Session delete
void delete(Object object);
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 ww w .ja va 2 s . c o 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.RegisterLocalRigTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.RegisterLocalRig#registerRig(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. *///from w w w .java 2 s . co m @Test public void testAddRigToSchedServerAllNew() { Session ses = DataAccessActivator.getNewSession(); String name = "register1"; String type = "registertest"; String caps = "a,b,c,d,e,f"; String contactUrl = "http://lbremote1.eng.uts.edu.au:7070/services/RigClientService"; assertTrue(this.register.registerRig(name, type, caps, contactUrl)); assertNull(this.register.getFailedReason()); Rig rig = this.register.getRegisteredRig(); assertNotNull(rig); this.register.getSession().close(); assertEquals(name, rig.getName()); assertEquals(type, rig.getRigType().getName()); assertEquals(contactUrl, rig.getContactUrl()); assertNotNull(rig.getRigCapabilities()); /* Default values. */ assertTrue(rig.isActive()); assertFalse(rig.isInSession()); assertFalse(rig.isOnline()); assertTrue(rig.isManaged()); assertNotNull(rig.getOfflineReason()); assertNull(rig.getMeta()); assertNull(rig.getSession()); assertTrue(new Date(System.currentTimeMillis()).after(rig.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rig.getLastUpdateTimestamp())); /* Test caps record was created and added. */ RigCapabilities capsRec = new RigCapabilitiesDao(ses).findCapabilites(caps); assertNotNull(capsRec); assertEquals(caps, capsRec.getCapabilities()); /* Test type record was created and added. */ RigType typeRec = new RigTypeDao(ses).findByName(type); assertNotNull(typeRec); assertEquals(type, typeRec.getName()); assertEquals(180, typeRec.getLogoffGraceDuration()); assertFalse(typeRec.isCodeAssignable()); /* Test rig record was created and added. */ Rig rigRec = new RigDao(ses).findByName(name); assertNotNull(rigRec); assertNotNull(rigRec.getId()); assertEquals(name, rigRec.getName()); assertEquals(type, rigRec.getRigType().getName()); assertTrue(rigRec.isActive()); assertEquals(contactUrl, rigRec.getContactUrl()); assertFalse(rigRec.isInSession()); assertNotNull(rigRec.getLastUpdateTimestamp()); assertTrue(rigRec.isManaged()); assertNull(rigRec.getMeta()); assertNotNull(rigRec.getOfflineReason()); assertFalse(rigRec.isOnline()); assertEquals(caps, rigRec.getRigCapabilities().getCapabilities()); assertTrue(new Date(System.currentTimeMillis()).after(rig.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rig.getLastUpdateTimestamp())); ses.beginTransaction(); ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate(); ses.getTransaction().commit(); ses.beginTransaction(); ses.delete(rigRec); ses.delete(capsRec); ses.delete(typeRec); ses.getTransaction().commit(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.RegisterLocalRigTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.RegisterLocalRig#registerRig(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. *///w w w .ja va 2s . c om @Test public void testAddRigToSchedServerNewRigExistingTypeNewCaps() { Session ses = DataAccessActivator.getNewSession(); String name = "register1"; String type = "registertest"; String caps = "a,b,c,d,e,f"; String contactUrl = "http://lbremote1.eng.uts.edu.au:7070/services/RigClientService"; RigType existType = new RigType(type, 180, false); ses.beginTransaction(); ses.save(existType); ses.getTransaction().commit(); ses.flush(); ses.evict(existType); assertTrue(this.register.registerRig(name, type, caps, contactUrl)); assertNull(this.register.getFailedReason()); Rig rig = this.register.getRegisteredRig(); assertNotNull(rig); assertEquals(name, rig.getName()); assertEquals(type, rig.getRigType().getName()); assertEquals(contactUrl, rig.getContactUrl()); assertNotNull(rig.getRigCapabilities()); /* Default values. */ assertTrue(rig.isActive()); assertFalse(rig.isInSession()); assertFalse(rig.isOnline()); assertTrue(rig.isManaged()); assertNotNull(rig.getOfflineReason()); assertNull(rig.getMeta()); assertNull(rig.getSession()); assertTrue(new Date(System.currentTimeMillis()).after(rig.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rig.getLastUpdateTimestamp())); /* Test caps record was created and added. */ RigCapabilities capsRec = new RigCapabilitiesDao(ses).findCapabilites(caps); assertNotNull(capsRec); assertEquals(caps, capsRec.getCapabilities()); /* Test type record was created and added. */ RigType typeRec = new RigTypeDao(ses).findByName(type); assertNotNull(typeRec); assertEquals(type, typeRec.getName()); assertEquals(180, typeRec.getLogoffGraceDuration()); assertFalse(typeRec.isCodeAssignable()); /* Test rig record was created and added. */ Rig rigRec = new RigDao(ses).findByName(name); assertNotNull(rigRec); assertNotNull(rigRec.getId()); assertEquals(name, rigRec.getName()); assertEquals(type, rigRec.getRigType().getName()); assertTrue(rigRec.isActive()); assertEquals(contactUrl, rigRec.getContactUrl()); assertFalse(rigRec.isInSession()); assertNotNull(rigRec.getLastUpdateTimestamp()); assertTrue(rigRec.isManaged()); assertNull(rigRec.getMeta()); assertNotNull(rigRec.getOfflineReason()); assertFalse(rigRec.isOnline()); assertEquals(caps, rigRec.getRigCapabilities().getCapabilities()); assertTrue(new Date(System.currentTimeMillis()).after(rigRec.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rigRec.getLastUpdateTimestamp())); /* Cleanup. */ ses.beginTransaction(); ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate(); ses.getTransaction().commit(); ses.beginTransaction(); ses.delete(rigRec); ses.delete(capsRec); ses.delete(typeRec); ses.getTransaction().commit(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.RegisterLocalRigTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.RegisterLocalRig#registerRig(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. *///from w w w.j av a 2 s.c o m @Test public void testAddRigToSchedServerNewRigExistingTypeExistingCaps() { Session ses = DataAccessActivator.getNewSession(); String name = "register1"; String type = "registertest"; String caps = "a,b,c,d,e,f"; String contactUrl = "http://lbremote1.eng.uts.edu.au:7070/services/RigClientService"; RigType existType = new RigType(type, 180, false); RigCapabilities existCaps = new RigCapabilities(caps); ses.beginTransaction(); ses.save(existType); ses.save(existCaps); ses.getTransaction().commit(); ses.flush(); ses.evict(existType); assertTrue(this.register.registerRig(name, type, caps, contactUrl)); assertNull(this.register.getFailedReason()); Rig rig = this.register.getRegisteredRig(); assertNotNull(rig); assertEquals(name, rig.getName()); assertEquals(type, rig.getRigType().getName()); assertEquals(contactUrl, rig.getContactUrl()); assertNotNull(rig.getRigCapabilities()); /* Default values. */ assertTrue(rig.isActive()); assertFalse(rig.isInSession()); assertFalse(rig.isOnline()); assertTrue(rig.isManaged()); assertNotNull(rig.getOfflineReason()); assertNull(rig.getMeta()); assertNull(rig.getSession()); assertTrue(new Date(System.currentTimeMillis()).after(rig.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rig.getLastUpdateTimestamp())); /* Test caps record was created and added. */ RigCapabilities capsRec = new RigCapabilitiesDao(ses).findCapabilites(caps); assertNotNull(capsRec); assertEquals(caps, capsRec.getCapabilities()); /* Test type record was created and added. */ RigType typeRec = new RigTypeDao(ses).findByName(type); assertNotNull(typeRec); assertEquals(type, typeRec.getName()); assertEquals(180, typeRec.getLogoffGraceDuration()); assertFalse(typeRec.isCodeAssignable()); /* Test rig record was created and added. */ Rig rigRec = new RigDao(ses).findByName(name); assertNotNull(rigRec); assertNotNull(rigRec.getId()); assertEquals(name, rigRec.getName()); assertEquals(type, rigRec.getRigType().getName()); assertTrue(rigRec.isActive()); assertEquals(contactUrl, rigRec.getContactUrl()); assertFalse(rigRec.isInSession()); assertNotNull(rigRec.getLastUpdateTimestamp()); assertTrue(rigRec.isManaged()); assertNull(rigRec.getMeta()); assertNotNull(rigRec.getOfflineReason()); assertFalse(rigRec.isOnline()); assertEquals(caps, rigRec.getRigCapabilities().getCapabilities()); assertTrue(new Date(System.currentTimeMillis()).after(rigRec.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rigRec.getLastUpdateTimestamp())); /* Cleanup. */ ses.beginTransaction(); ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate(); ses.getTransaction().commit(); ses.beginTransaction(); ses.delete(rigRec); ses.delete(capsRec); ses.delete(typeRec); ses.getTransaction().commit(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.RegisterLocalRigTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.RegisterLocalRig#registerRig(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. *//*from www .ja v a 2 s.co m*/ @Test public void testAddRigToSchedServerInactiveRig() { Session ses = DataAccessActivator.getNewSession(); String name = "register1"; String type = "registertest"; String caps = "a,b,c,d,e,f"; String contactUrl = "http://lbremote1.eng.uts.edu.au:7070/services/RigClientService"; RigType existType = new RigType(type, 180, false); RigCapabilities existCaps = new RigCapabilities(caps); ses.beginTransaction(); ses.save(existType); ses.save(existCaps); ses.getTransaction().commit(); ses.flush(); ses.evict(existType); ses.evict(existCaps); Rig existRig = new Rig(existType, existCaps, name, contactUrl, new Date(), false, "Broken.", false, true, false); ses.beginTransaction(); ses.save(existRig); ses.getTransaction().commit(); ses.flush(); ses.evict(existRig); assertTrue(this.register.registerRig(name, type, caps, contactUrl)); assertNull(this.register.getFailedReason()); Rig rig = this.register.getRegisteredRig(); assertNotNull(rig); assertEquals(name, rig.getName()); assertEquals(type, rig.getRigType().getName()); assertEquals(contactUrl, rig.getContactUrl()); assertNotNull(rig.getRigCapabilities()); /* Default values. */ assertTrue(rig.isActive()); assertFalse(rig.isInSession()); assertFalse(rig.isOnline()); assertTrue(rig.isManaged()); assertNotNull(rig.getOfflineReason()); assertNull(rig.getMeta()); assertNull(rig.getSession()); assertTrue(new Date(System.currentTimeMillis()).after(rig.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rig.getLastUpdateTimestamp())); /* Test caps record was created and added. */ RigCapabilities capsRec = new RigCapabilitiesDao(ses).findCapabilites(caps); assertNotNull(capsRec); assertEquals(caps, capsRec.getCapabilities()); /* Test type record was created and added. */ RigType typeRec = new RigTypeDao(ses).findByName(type); assertNotNull(typeRec); assertEquals(type, typeRec.getName()); assertEquals(180, typeRec.getLogoffGraceDuration()); assertFalse(typeRec.isCodeAssignable()); /* Test rig record was created and added. */ Rig rigRec = new RigDao(ses).findByName(name); assertNotNull(rigRec); assertNotNull(rigRec.getId()); assertEquals(name, rigRec.getName()); assertEquals(type, rigRec.getRigType().getName()); assertTrue(rigRec.isActive()); assertEquals(contactUrl, rigRec.getContactUrl()); assertFalse(rigRec.isInSession()); assertNotNull(rigRec.getLastUpdateTimestamp()); assertTrue(rigRec.isManaged()); assertNull(rigRec.getMeta()); assertNotNull(rigRec.getOfflineReason()); assertFalse(rigRec.isOnline()); assertEquals(caps, rigRec.getRigCapabilities().getCapabilities()); assertTrue(new Date(System.currentTimeMillis()).after(rigRec.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rigRec.getLastUpdateTimestamp())); /* Cleanup. */ ses.beginTransaction(); ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate(); ses.getTransaction().commit(); ses.beginTransaction(); ses.delete(rigRec); ses.delete(capsRec); ses.delete(typeRec); ses.getTransaction().commit(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.RegisterLocalRigTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.RegisterLocalRig#registerRig(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. *///from ww w . j a v a 2s .c o m @Test public void testAddRigToSchedServerActiveRig() { Session ses = DataAccessActivator.getNewSession(); String name = "register1"; String type = "registertest"; String caps = "a,b,c,d,e,f"; String contactUrl = "http://lbremote1.eng.uts.edu.au:7070/services/RigClientService"; RigType existType = new RigType(type, 180, false); RigCapabilities existCaps = new RigCapabilities(caps); ses.beginTransaction(); ses.save(existType); ses.save(existCaps); ses.getTransaction().commit(); ses.flush(); ses.evict(existType); ses.evict(existCaps); Rig existRig = new Rig(existType, existCaps, name, contactUrl, new Date(), false, "Broken.", false, true, true); ses.beginTransaction(); ses.save(existRig); ses.getTransaction().commit(); ses.flush(); ses.evict(existRig); assertFalse(this.register.registerRig(name, type, caps, contactUrl)); RigCapabilities capsRec = new RigCapabilitiesDao(ses).findCapabilites(caps); RigType typeRec = new RigTypeDao(ses).findByName(type); Rig rigRec = new RigDao(ses).findByName(name); /* Cleanup. */ ses.beginTransaction(); ses.createQuery("DELETE FROM RigLog WHERE rig='" + rigRec.getId() + "'").executeUpdate(); ses.getTransaction().commit(); ses.beginTransaction(); ses.delete(rigRec); ses.delete(capsRec); ses.delete(typeRec); ses.getTransaction().commit(); assertEquals("Exists", this.register.getFailedReason()); }
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 www. j av a2 s . 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);/*w ww . j av a 2 s . co 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 www . j av a2 s. c o 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()}. *///w w w .ja v a 2 s. com @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(); }