Example usage for org.hibernate Session save

List of usage examples for org.hibernate Session save

Introduction

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

Prototype

Serializable save(Object object);

Source Link

Document

Persist the given transient instance, first assigning a generated identifier.

Usage

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.impl.tests.UserClassAdminTester.java

License:Open Source License

@Test
public void testAddUserExists() {
    UserClass uc = new UserClass();
    uc.setName("clazz");
    uc.setPriority((short) 50);
    uc.setActive(true);//  w ww.  j ava2 s .c o m
    uc.setQueuable(true);
    uc.setBookable(true);
    uc.setUsersLockable(false);
    Session ses = this.dao.getSession();
    ses.beginTransaction();
    ses.save(uc);
    ses.getTransaction().commit();

    assertFalse(this.admin.addUserClass("clazz", 10, false, false, false, false));
    assertNotNull(this.admin.getFailureReason());

    this.dao.delete(uc);
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.impl.tests.UserClassAdminTester.java

License:Open Source License

@Test
public void testEditUser() {
    UserClass uc = new UserClass();
    uc.setName("clazz");
    uc.setPriority((short) 50);
    uc.setActive(true);/*from  w w w.j  ava 2  s  .  c  om*/
    uc.setQueuable(true);
    uc.setBookable(true);
    uc.setUsersLockable(false);
    uc.setKickable(true);
    Session ses = this.dao.getSession();
    ses.beginTransaction();
    ses.save(uc);
    ses.getTransaction().commit();

    assertTrue(this.admin.editUserClass("clazz", 10, true, false, true, false));
    assertNull(this.admin.getFailureReason());
    this.dao.refresh(uc);

    assertEquals("clazz", uc.getName());
    assertEquals(10, uc.getPriority());
    assertTrue(uc.isActive());
    assertTrue(uc.isKickable());
    assertFalse(uc.isQueuable());
    assertFalse(uc.isUsersLockable());

    this.dao.delete(uc);
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.impl.tests.UserClassAdminTester.java

License:Open Source License

@Test
public void testEditUserId() {
    UserClass uc = new UserClass();
    uc.setName("clazz");
    uc.setPriority((short) 50);
    uc.setActive(true);/*  ww  w. ja v  a  2 s.co m*/
    uc.setQueuable(true);
    uc.setBookable(true);
    uc.setUsersLockable(false);
    uc.setKickable(true);
    Session ses = this.dao.getSession();
    ses.beginTransaction();
    ses.save(uc);
    ses.getTransaction().commit();

    assertTrue(this.admin.editUserClass(uc.getId(), "userc", 10, true, false, true, false));
    assertNull(this.admin.getFailureReason());
    this.dao.refresh(uc);

    assertEquals("userc", uc.getName());
    assertEquals(10, uc.getPriority());
    assertTrue(uc.isActive());
    assertTrue(uc.isKickable());
    assertFalse(uc.isQueuable());
    assertFalse(uc.isUsersLockable());

    this.dao.delete(uc);
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.impl.tests.UserClassAdminTester.java

License:Open Source License

@Test
public void testDeleteUserClass() {
    UserClass uc = new UserClass();
    uc.setName("clazz");
    uc.setPriority((short) 50);
    uc.setActive(true);/* ww w  .  j  av  a  2s . c o  m*/
    uc.setQueuable(true);
    uc.setBookable(true);
    uc.setUsersLockable(false);
    uc.setKickable(true);
    Session ses = this.dao.getSession();
    ses.beginTransaction();
    ses.save(uc);
    ses.getTransaction().commit();

    assertTrue(this.admin.deleteUserClass("clazz"));
    assertNull(this.admin.getFailureReason());

    assertNull(this.dao.findByName("clazz"));

}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.impl.tests.UserClassAdminTester.java

License:Open Source License

@Test
public void testDeleteUserClassId() {
    UserClass uc = new UserClass();
    uc.setName("clazz");
    uc.setPriority((short) 50);
    uc.setActive(true);/*from   w  w w  . ja  v a 2  s. c  om*/
    uc.setQueuable(true);
    uc.setBookable(true);
    uc.setUsersLockable(false);
    uc.setKickable(true);
    Session ses = this.dao.getSession();
    ses.beginTransaction();
    ses.save(uc);
    ses.getTransaction().commit();

    assertTrue(this.admin.deleteUserClass(uc.getId()));
    assertNull(this.admin.getFailureReason());

    assertNull(this.dao.findByName(uc.getName()));
}

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  ww  w .  j a  va 2 s . c  om*/
@Test
public void testGetPermission() {
    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);
    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);
    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(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._TYPE, p.getResourceClass().toString());
    ResourceIDType rid = p.getResource();
    assertNotNull(rid);
    assertEquals(rigType1.getId().intValue(), rid.getResourceID());
    assertEquals(rigType1.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 .jav  a  2s  .  c  o  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.jav  a  2 s. co m
@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)}.
 */// w  w  w.  j a  va 2 s. c om
@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  w w  .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");
}