Example usage for org.hibernate Session delete

List of usage examples for org.hibernate Session delete

Introduction

In this page you can find the example usage for org.hibernate Session delete.

Prototype

void delete(Object object);

Source Link

Document

Remove a persistent instance from the datastore.

Usage

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsSOAPImplTester.java

License:Open Source License

/**
 * Test method for {@link PermissionsSOAPImpl#getPermission(GetPermission)}.
 *///  w  w  w  .j  a  v a2 s  . co m
@Test
public void testGetPermissionRig() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();
    UserClass uclass1 = new UserClass();
    uclass1.setName("permTestClass2");
    uclass1.setActive(true);
    uclass1.setQueuable(false);
    uclass1.setBookable(true);
    uclass1.setTimeHorizon(1000);
    ses.save(uclass1);
    RigType rigType1 = new RigType("interRigType1", 300, false);
    ses.save(rigType1);
    RigCapabilities rigCaps = new RigCapabilities("not,important");
    ses.save(rigCaps);
    Rig rig1 = new Rig(rigType1, rigCaps, "interRig1", "http://contact", new Date(), true, null, false, true,
            true);
    ses.save(rig1);
    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("RIG");
    perm1.setSessionDuration(3600);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setMaximumBookings(10);
    perm1.setRig(rig1);
    perm1.setStartTime(new Date());
    perm1.setExpiryTime(new Date());
    perm1.setDisplayName("display_name1");
    ses.save(perm1);
    ses.getTransaction().commit();

    GetPermission request = new GetPermission();
    PermissionIDType pid = new PermissionIDType();
    pid.setPermissionID(perm1.getId().intValue());
    request.setGetPermission(pid);

    GetPermissionResponse response = this.permissions.getPermission(request);

    ses.beginTransaction();
    ses.delete(perm1);
    ses.delete(rig1);
    ses.delete(rigCaps);
    ses.delete(rigType1);
    ses.delete(uclass1);
    ses.getTransaction().commit();

    assertNotNull(response);
    PermissionType p = response.getGetPermissionResponse();
    assertNotNull(p);

    /* User class. */
    UserClassIDType ucid = p.getUserClass();
    assertNotNull(ucid);
    assertEquals(uclass1.getId().intValue(), ucid.getUserClassID());
    assertEquals(uclass1.getName(), ucid.getUserClassName());

    assertEquals(ResourceClass._RIG, p.getResourceClass().toString());
    ResourceIDType rid = p.getResource();
    assertNotNull(rid);
    assertEquals(rig1.getId().intValue(), rid.getResourceID());
    assertEquals(rig1.getName(), rid.getResourceName());

    assertFalse(p.canQueue());
    assertTrue(p.canBook());

    assertEquals(uclass1.getTimeHorizon(), p.getTimeHorizon());
    assertEquals(perm1.getMaximumBookings(), p.getMaxBookings());
    assertEquals(perm1.getSessionDuration(), p.getSessionDuration());
    assertEquals(perm1.getExtensionDuration(), p.getExtensionDuration());
    assertEquals(perm1.getAllowedExtensions(), p.getAllowedExtensions());
    assertEquals(perm1.getQueueActivityTimeout(), p.getQueueActivityTmOut());
    assertEquals(perm1.getSessionActivityTimeout(), p.getSessionActivityTmOut());
    assertEquals(perm1.getDisplayName(), p.getDisplayName());

    assertEquals(perm1.getStartTime().getTime() / 1000, p.getStart().getTimeInMillis() / 1000);
    assertEquals(perm1.getExpiryTime().getTime() / 1000, p.getExpiry().getTimeInMillis() / 1000);
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsSOAPImplTester.java

License:Open Source License

/**
 * Test method for {@link PermissionsSOAPImpl#getPermission(GetPermission)}.
 *//*from  w w  w.j ava2 s  . c  om*/
@Test
public void testGetPermissionCaps() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();
    UserClass uclass1 = new UserClass();
    uclass1.setName("permTestClass2");
    uclass1.setActive(true);
    uclass1.setQueuable(false);
    uclass1.setBookable(true);
    uclass1.setTimeHorizon(1000);
    ses.save(uclass1);
    RequestCapabilities reqCaps = new RequestCapabilities("not,important");
    ses.save(reqCaps);
    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("CAPABILITY");
    perm1.setSessionDuration(3600);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setMaximumBookings(10);
    perm1.setRequestCapabilities(reqCaps);
    perm1.setStartTime(new Date());
    perm1.setExpiryTime(new Date());
    perm1.setDisplayName("display_name1");
    ses.save(perm1);
    ses.getTransaction().commit();

    GetPermission request = new GetPermission();
    PermissionIDType pid = new PermissionIDType();
    pid.setPermissionID(perm1.getId().intValue());
    request.setGetPermission(pid);

    GetPermissionResponse response = this.permissions.getPermission(request);

    ses.beginTransaction();
    ses.delete(perm1);
    ses.delete(reqCaps);
    ses.delete(uclass1);
    ses.getTransaction().commit();

    assertNotNull(response);
    PermissionType p = response.getGetPermissionResponse();
    assertNotNull(p);

    /* User class. */
    UserClassIDType ucid = p.getUserClass();
    assertNotNull(ucid);
    assertEquals(uclass1.getId().intValue(), ucid.getUserClassID());
    assertEquals(uclass1.getName(), ucid.getUserClassName());

    assertEquals(ResourceClass._CAPABILITY, p.getResourceClass().toString());
    ResourceIDType rid = p.getResource();
    assertNotNull(rid);
    assertEquals(reqCaps.getId().intValue(), rid.getResourceID());
    assertEquals(reqCaps.getCapabilities(), rid.getResourceName());

    assertFalse(p.canQueue());
    assertTrue(p.canBook());

    assertEquals(uclass1.getTimeHorizon(), p.getTimeHorizon());
    assertEquals(perm1.getMaximumBookings(), p.getMaxBookings());
    assertEquals(perm1.getSessionDuration(), p.getSessionDuration());
    assertEquals(perm1.getExtensionDuration(), p.getExtensionDuration());
    assertEquals(perm1.getAllowedExtensions(), p.getAllowedExtensions());
    assertEquals(perm1.getQueueActivityTimeout(), p.getQueueActivityTmOut());
    assertEquals(perm1.getSessionActivityTimeout(), p.getSessionActivityTmOut());
    assertEquals(perm1.getDisplayName(), p.getDisplayName());

    assertEquals(perm1.getStartTime().getTime() / 1000, p.getStart().getTimeInMillis() / 1000);
    assertEquals(perm1.getExpiryTime().getTime() / 1000, p.getExpiry().getTimeInMillis() / 1000);
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsSOAPImplTester.java

License:Open Source License

/**
 * Test method for {@link PermissionsSOAPImpl#getPermissionsForUser(GetPermissionsForUser)}.
 *//*from w  w  w.j a v  a 2  s  .  c  o  m*/
@Test
public void testGetPermissionsForUser() throws Exception {
    /**********************************************************************
     ** Test setup.                                                      **
     *********************************************************************/
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();
    /* User. */
    User user = new User("test", "permUser", "USER");
    ses.save(user);

    /* Three classes. */
    UserClass uclass1 = new UserClass();
    uclass1.setName("permTestClass1");
    uclass1.setActive(true);
    ses.save(uclass1);
    UserClass uclass2 = new UserClass();
    uclass2.setName("permTestClass2");
    uclass2.setActive(true);
    ses.save(uclass2);
    UserClass uclass3 = new UserClass();
    uclass3.setName("permTestClass3");
    uclass3.setActive(true);
    uclass3.setQueuable(true);
    uclass3.setBookable(true);
    ses.save(uclass3);

    /* User is a member of two. */
    UserAssociation assoc1 = new UserAssociation(new UserAssociationId(user.getId(), uclass1.getId()), uclass1,
            user);
    ses.save(assoc1);
    UserAssociation assoc2 = new UserAssociation(new UserAssociationId(user.getId(), uclass2.getId()), uclass2,
            user);
    ses.save(assoc2);

    /* Resources for the permissions. */
    /* -- Three rig types. */
    RigType rigType1 = new RigType("interRigType1", 300, false);
    ses.save(rigType1);
    RigType rigType2 = new RigType("interRigType2", 300, false);
    ses.save(rigType2);
    RigType rigType3 = new RigType("batchRigType3", 300, true);
    ses.save(rigType3);

    /* -- Five rigs all using the same rig caps (not important). */
    RigCapabilities rigCaps = new RigCapabilities("not,important");
    ses.save(rigCaps);
    Rig rig1 = new Rig(rigType1, rigCaps, "interRig1", "http://contact", new Date(), true, null, false, true,
            true);
    ses.save(rig1);
    Rig rig2 = new Rig(rigType1, rigCaps, "interRig2", "http://contact", new Date(), true, null, false, true,
            true);
    ses.save(rig2);
    Rig rig3 = new Rig(rigType2, rigCaps, "interRig3", "http://contact", new Date(), true, null, false, true,
            true);
    ses.save(rig3);
    Rig rig4 = new Rig(rigType2, rigCaps, "interRig4", "http://contact", new Date(), true, null, false, true,
            true);
    ses.save(rig4);
    Rig rig5 = new Rig(rigType2, rigCaps, "interRig5", "http://contact", new Date(), true, null, false, true,
            true);
    ses.save(rig5);

    /* -- One request capabilties. */
    RequestCapabilities caps = new RequestCapabilities("a, b, c, d");
    ses.save(caps);

    /* Resource permissions. */
    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("TYPE");
    perm1.setSessionDuration(3600);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setRigType(rigType1);
    perm1.setStartTime(new Date());
    perm1.setExpiryTime(new Date());
    perm1.setDisplayName("display_name1");
    ses.save(perm1);
    ResourcePermission perm2 = new ResourcePermission();
    perm2.setUserClass(uclass1);
    perm2.setType("RIG");
    perm2.setSessionDuration(3600);
    perm2.setQueueActivityTimeout(300);
    perm2.setAllowedExtensions((short) 10);
    perm2.setSessionActivityTimeout(300);
    perm2.setExtensionDuration(300);
    perm2.setRig(rig1);
    perm2.setStartTime(new Date());
    perm2.setExpiryTime(new Date());
    perm2.setDisplayName("display_name2");
    ses.save(perm2);
    ResourcePermission perm3 = new ResourcePermission();
    perm3.setUserClass(uclass1);
    perm3.setType("RIG");
    perm3.setSessionDuration(3600);
    perm3.setQueueActivityTimeout(300);
    perm3.setAllowedExtensions((short) 10);
    perm3.setSessionActivityTimeout(300);
    perm3.setExtensionDuration(300);
    perm3.setRig(rig2);
    perm3.setStartTime(new Date());
    perm3.setExpiryTime(new Date());
    ses.save(perm3);
    ResourcePermission perm4 = new ResourcePermission();
    perm4.setUserClass(uclass2);
    perm4.setType("TYPE");
    perm4.setSessionDuration(3600);
    perm4.setQueueActivityTimeout(300);
    perm4.setAllowedExtensions((short) 10);
    perm4.setSessionActivityTimeout(300);
    perm4.setExtensionDuration(300);
    perm4.setRigType(rigType2);
    perm4.setStartTime(new Date());
    perm4.setExpiryTime(new Date());
    ses.save(perm4);
    ResourcePermission perm5 = new ResourcePermission();
    perm5.setUserClass(uclass2);
    perm5.setType("RIG");
    perm5.setSessionDuration(3600);
    perm5.setQueueActivityTimeout(300);
    perm5.setAllowedExtensions((short) 10);
    perm5.setSessionActivityTimeout(300);
    perm5.setExtensionDuration(300);
    perm5.setRig(rig3);
    perm5.setStartTime(new Date());
    perm5.setExpiryTime(new Date());
    ses.save(perm5);
    ResourcePermission perm6 = new ResourcePermission();
    perm6.setUserClass(uclass2);
    perm6.setType("RIG");
    perm6.setSessionDuration(3600);
    perm6.setQueueActivityTimeout(300);
    perm6.setAllowedExtensions((short) 10);
    perm6.setSessionActivityTimeout(300);
    perm6.setExtensionDuration(300);
    perm6.setRig(rig4);
    perm6.setStartTime(new Date());
    perm6.setExpiryTime(new Date());
    ses.save(perm6);
    ResourcePermission perm7 = new ResourcePermission();
    perm7.setUserClass(uclass2);
    perm7.setType("CAPABILITY");
    perm7.setSessionDuration(3600);
    perm7.setQueueActivityTimeout(300);
    perm7.setAllowedExtensions((short) 10);
    perm7.setSessionActivityTimeout(300);
    perm7.setExtensionDuration(300);
    perm7.setRequestCapabilities(caps);
    perm7.setStartTime(new Date());
    perm7.setExpiryTime(new Date());
    ses.save(perm7);
    ResourcePermission perm8 = new ResourcePermission();
    perm8.setUserClass(uclass3);
    perm8.setType("RIG");
    perm8.setSessionDuration(3600);
    perm8.setQueueActivityTimeout(300);
    perm8.setAllowedExtensions((short) 10);
    perm8.setSessionActivityTimeout(300);
    perm8.setExtensionDuration(300);
    perm8.setRig(rig5);
    perm8.setStartTime(new Date());
    perm8.setExpiryTime(new Date());
    ses.save(perm8);
    ResourcePermission perm9 = new ResourcePermission();
    perm9.setUserClass(uclass3);
    perm9.setType("CAPABILITY");
    perm9.setSessionDuration(3600);
    perm9.setQueueActivityTimeout(300);
    perm9.setAllowedExtensions((short) 10);
    perm9.setSessionActivityTimeout(300);
    perm9.setExtensionDuration(300);
    perm9.setRequestCapabilities(caps);
    perm9.setStartTime(new Date());
    perm9.setExpiryTime(new Date());
    ses.save(perm9);

    /* User locks. */
    UserLock lock1 = new UserLock(user, perm1, true, "abc123");
    ses.save(lock1);
    UserLock lock2 = new UserLock(user, perm2, false, "abc123");
    ses.save(lock2);
    ses.getTransaction().commit();

    /**********************************************************************
     ** Actual test.                                                     **
     *********************************************************************/
    GetPermissionsForUser request = new GetPermissionsForUser();
    UserIDType uid = new UserIDType();
    request.setGetPermissionsForUser(uid);
    uid.setNameNamespace(user.getNamespace(), user.getName());

    GetPermissionsForUserResponse resp = this.permissions.getPermissionsForUser(request);
    assertNotNull(resp);

    /**********************************************************************
     ** Test cleanup.                                                    **
     *********************************************************************/
    ses.beginTransaction();
    ses.delete(lock2);
    ses.delete(lock1);
    ses.delete(perm1);
    ses.delete(perm2);
    ses.delete(perm3);
    ses.delete(perm4);
    ses.delete(perm5);
    ses.delete(perm6);
    ses.delete(perm7);
    ses.delete(perm8);
    ses.delete(perm9);
    ses.delete(caps);
    ses.delete(rig5);
    ses.delete(rig4);
    ses.delete(rig3);
    ses.delete(rig2);
    ses.delete(rig1);
    ses.delete(rigCaps);
    ses.delete(rigType3);
    ses.delete(rigType2);
    ses.delete(rigType1);
    ses.delete(assoc2);
    ses.delete(assoc1);
    ses.delete(uclass3);
    ses.delete(uclass2);
    ses.delete(uclass1);
    ses.delete(user);
    ses.getTransaction().commit();

    PermissionWithLockListType permListType = resp.getGetPermissionsForUserResponse();
    assertNotNull(permListType);

    PermissionWithLockType permList[] = permListType.getPermission();
    assertNotNull(permList);
    assertEquals(7, permList.length);

    for (PermissionWithLockType lock : permList) {
        assertNotNull(lock);
        PermissionType pt = lock.getPermission();
        assertNotNull(pt);

        assertEquals(3600, pt.getSessionDuration());
        assertEquals(300, pt.getExtensionDuration());
        assertEquals(10, pt.getAllowedExtensions());
        assertEquals(300, pt.getQueueActivityTmOut());
        assertEquals(300, pt.getSessionActivityTmOut());
        assertNotNull(pt.getStart());
        assertNotNull(pt.getExpiry());

        ResourceIDType res = pt.getResource();
        assertNotNull(res);
        assertTrue(res.getResourceID() > 0);
        assertNotNull(res.getResourceName());
    }

    OMElement ele = resp.getOMElement(GetPermissionsForUser.MY_QNAME, OMAbstractFactory.getOMFactory());
    assertNotNull(ele);

    String xml = ele.toStringWithConsume();
    assertNotNull(xml);
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsSOAPImplTester.java

License:Open Source License

/**
 * Test method for {@link PermissionsSOAPImpl#getPermissionsForUser(GetPermissionsForUser)}.
 *///from  w  ww  .j a v a  2  s.  co  m
@Test
public void testGetPermissionsForUserLocked() {
    /**********************************************************************
     ** Test setup.                                                      **
     *********************************************************************/
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();
    User user = new User("test", "permUser", "USER");
    ses.save(user);
    UserClass uclass1 = new UserClass();
    uclass1.setName("permTestClass1");
    uclass1.setActive(true);
    uclass1.setQueuable(false);
    uclass1.setBookable(true);
    uclass1.setTimeHorizon(1000);
    ses.save(uclass1);
    UserAssociation assoc1 = new UserAssociation(new UserAssociationId(user.getId(), uclass1.getId()), uclass1,
            user);
    ses.save(assoc1);
    RigType rigType1 = new RigType("interRigType1", 300, false);
    ses.save(rigType1);
    RigCapabilities rigCaps = new RigCapabilities("not,important");
    ses.save(rigCaps);
    Rig rig1 = new Rig(rigType1, rigCaps, "interRig1", "http://contact", new Date(), true, null, false, true,
            true);
    ses.save(rig1);
    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("TYPE");
    perm1.setSessionDuration(3600);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setMaximumBookings(10);
    perm1.setRigType(rigType1);
    perm1.setStartTime(new Date());
    perm1.setExpiryTime(new Date());
    perm1.setDisplayName("display_name1");
    ses.save(perm1);
    UserLock lock1 = new UserLock(user, perm1, true, "abc123");
    ses.save(lock1);
    ses.getTransaction().commit();

    /**********************************************************************
     ** Actual test.                                                     **
     *********************************************************************/
    GetPermissionsForUser request = new GetPermissionsForUser();
    UserIDType uid = new UserIDType();
    request.setGetPermissionsForUser(uid);
    uid.setNameNamespace(user.getNamespace(), user.getName());

    GetPermissionsForUserResponse resp = this.permissions.getPermissionsForUser(request);
    assertNotNull(resp);

    /**********************************************************************
     ** Test cleanup.                                                    **
     *********************************************************************/
    ses.beginTransaction();
    ses.delete(lock1);
    ses.delete(perm1);
    ses.delete(rig1);
    ses.delete(rigCaps);
    ses.delete(rigType1);
    ses.delete(assoc1);
    ses.delete(uclass1);
    ses.delete(user);
    ses.getTransaction().commit();

    PermissionWithLockListType permListType = resp.getGetPermissionsForUserResponse();
    assertNotNull(permListType);

    PermissionWithLockType permList[] = permListType.getPermission();
    assertNotNull(permList);
    assertEquals(1, permList.length);

    PermissionWithLockType perm = permList[0];
    assertNotNull(perm);
    assertTrue(perm.getIsLocked());

    PermissionType p = perm.getPermission();
    assertNotNull(p);
    assertTrue(p.canBook());
    assertFalse(p.canQueue());
    assertEquals(perm1.getAllowedExtensions(), p.getAllowedExtensions());
    assertEquals(perm1.getExtensionDuration(), p.getExtensionDuration());
    assertEquals(perm1.getQueueActivityTimeout(), p.getQueueActivityTmOut());
    assertEquals(perm1.getSessionActivityTimeout(), p.getSessionActivityTmOut());
    assertEquals(perm1.getSessionDuration(), p.getSessionDuration());
    assertEquals(perm1.getMaximumBookings(), p.getMaxBookings());
    assertEquals(uclass1.getTimeHorizon(), p.getTimeHorizon());
    assertEquals("TYPE", p.getResourceClass().getValue());
    assertEquals(perm1.getDisplayName(), p.getDisplayName());

    ResourceIDType res = p.getResource();
    assertNotNull(res);
    assertEquals(res.getResourceName(), "interRigType1");
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsSOAPImplTester.java

License:Open Source License

/**
 * Test method for {@link PermissionsSOAPImpl#getPermissionsForUser(GetPermissionsForUser)}.
 *//*  w  w  w.  j  av a 2s . c  o  m*/
@Test
public void testGetPermissionsForUserNotLocked() {
    /**********************************************************************
     ** Test setup.                                                      **
     *********************************************************************/
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();
    User user = new User("test", "permUser", "USER");
    ses.save(user);
    UserClass uclass1 = new UserClass();
    uclass1.setName("permTestClass1");
    uclass1.setActive(true);
    uclass1.setBookable(false);
    uclass1.setQueuable(true);
    ses.save(uclass1);
    UserAssociation assoc1 = new UserAssociation(new UserAssociationId(user.getId(), uclass1.getId()), uclass1,
            user);
    ses.save(assoc1);
    RigType rigType1 = new RigType("interRigType1", 300, false);
    ses.save(rigType1);
    RigCapabilities rigCaps = new RigCapabilities("not,important");
    ses.save(rigCaps);
    Rig rig1 = new Rig(rigType1, rigCaps, "interRig1", "http://contact", new Date(), true, null, false, true,
            true);
    ses.save(rig1);
    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("RIG");
    perm1.setSessionDuration(3600);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setRig(rig1);
    perm1.setStartTime(new Date());
    perm1.setExpiryTime(new Date());
    ses.save(perm1);
    UserLock lock1 = new UserLock(user, perm1, false, "abc123");
    ses.save(lock1);
    ses.getTransaction().commit();

    /**********************************************************************
     ** Actual test.                                                     **
     *********************************************************************/
    GetPermissionsForUser request = new GetPermissionsForUser();
    UserIDType uid = new UserIDType();
    request.setGetPermissionsForUser(uid);
    uid.setNameNamespace(user.getNamespace(), user.getName());

    GetPermissionsForUserResponse resp = this.permissions.getPermissionsForUser(request);
    assertNotNull(resp);

    /**********************************************************************
     ** Test cleanup.                                                    **
     *********************************************************************/
    ses.beginTransaction();
    ses.delete(lock1);
    ses.delete(perm1);
    ses.delete(rig1);
    ses.delete(rigCaps);
    ses.delete(rigType1);
    ses.delete(assoc1);
    ses.delete(uclass1);
    ses.delete(user);
    ses.getTransaction().commit();

    PermissionWithLockListType permListType = resp.getGetPermissionsForUserResponse();
    assertNotNull(permListType);

    PermissionWithLockType permList[] = permListType.getPermission();
    assertNotNull(permList);
    assertEquals(1, permList.length);

    PermissionWithLockType perm = permList[0];
    assertNotNull(perm);
    assertFalse(perm.getIsLocked());

    PermissionType p = perm.getPermission();
    assertNotNull(p);
    assertFalse(p.canBook());
    assertTrue(p.canQueue());
    assertEquals(perm1.getAllowedExtensions(), p.getAllowedExtensions());
    assertEquals(perm1.getExtensionDuration(), p.getExtensionDuration());
    assertEquals(perm1.getQueueActivityTimeout(), p.getQueueActivityTmOut());
    assertEquals(perm1.getSessionActivityTimeout(), p.getSessionActivityTmOut());
    assertEquals(perm1.getSessionDuration(), p.getSessionDuration());
    assertEquals("RIG", p.getResourceClass().getValue());

    ResourceIDType res = p.getResource();
    assertNotNull(res);
    assertEquals(res.getResourceName(), "interRig1");
}

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  .  jav  a  2  s.co  m*/
@Test
public void testUnlockUserLockID() {
    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");
    lockReq.setUserLockID(lock.getId().intValue());

    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 ww.  j a va  2 s . c om
@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)}.
 */// w w  w .ja  v  a  2  s .  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)}.
 *//*from   w  ww.  j a  v  a 2  s  .  co  m*/
@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.permissions.intf.tests.PermissionsSOAPImplTester.java

License:Open Source License

@Test
public void testGetUserFromUserID() throws Exception {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();//from  w w w. j a v a 2  s.c o m
    User user = new User("UserIdTest", "Permission", "USER");
    ses.persist(user);
    ses.getTransaction().commit();

    UserIDType uid = new UserIDType();
    uid.setUserID(String.valueOf(user.getId()));

    Method meth = PermissionsSOAPImpl.class.getDeclaredMethod("getUserFromUserID", UserIDType.class,
            Session.class);
    meth.setAccessible(true);
    User loaded = (User) meth.invoke(this.permissions, uid, ses);
    assertNotNull(loaded);

    ses.beginTransaction();
    ses.delete(user);
    ses.getTransaction().commit();

    assertEquals(user.getId().longValue(), loaded.getId().longValue());
    assertEquals(user.getName(), loaded.getName());
    assertEquals(user.getNamespace(), loaded.getNamespace());
    assertEquals(user.getPersona(), loaded.getPersona());

    ses.close();
}