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.bookings.intf.tests.BookingsServiceTester.java

License:Open Source License

@Test
public void testDeleteBookingsAcademicNotOwned() throws Exception {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/*from  ww  w.jav  a2 s  . co m*/
    UserClass uclass1 = new UserClass();
    uclass1.setName("booktestclass");
    uclass1.setActive(true);
    uclass1.setQueuable(false);
    uclass1.setBookable(true);
    uclass1.setTimeHorizon(1000);
    ses.save(uclass1);
    User us1 = new User();
    us1.setName("bktestuser1");
    us1.setNamespace("BKNS");
    us1.setPersona("USER");
    ses.save(us1);
    User us2 = new User();
    us2.setName("bktestuser2");
    us2.setNamespace("BKNS");
    us2.setPersona("ACADEMIC");
    ses.save(us2);
    UserAssociation assoc = new UserAssociation();
    assoc.setId(new UserAssociationId(us1.getId(), uclass1.getId()));
    assoc.setUser(us1);
    assoc.setUserClass(uclass1);
    UserAssociation assoc2 = new UserAssociation();
    assoc2.setId(new UserAssociationId(us2.getId(), uclass1.getId()));
    assoc2.setUser(us2);
    assoc2.setUserClass(uclass1);
    ses.save(assoc);
    RigType rigType1 = new RigType("booktestrigtype", 300, false);
    ses.save(rigType1);
    RigCapabilities caps1 = new RigCapabilities("book,test,foo");
    ses.save(caps1);
    Rig r1 = new Rig();
    r1.setName("bkrig1");
    r1.setRigType(rigType1);
    r1.setLastUpdateTimestamp(new Date());
    r1.setRigCapabilities(caps1);
    ses.save(r1);

    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("RIG");
    perm1.setSessionDuration(1800);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setMaximumBookings(10);
    perm1.setRig(r1);
    perm1.setStartTime(new Date());
    perm1.setExpiryTime(new Date());
    perm1.setDisplayName("bookperm");
    ses.save(perm1);

    Bookings bk1 = new Bookings();
    bk1.setActive(true);
    bk1.setDuration(3600);
    bk1.setStartTime(new Date());
    bk1.setEndTime(new Date());
    bk1.setResourcePermission(perm1);
    bk1.setResourceType("RIG");
    bk1.setRig(r1);
    bk1.setUser(us1);
    bk1.setUserName(us1.getName());
    bk1.setUserNamespace(us1.getNamespace());
    ses.save(bk1);

    ses.getTransaction().commit();

    CancelBooking request = new CancelBooking();
    CancelBookingType dbt = new CancelBookingType();
    request.setCancelBooking(dbt);
    UserIDType uid = new UserIDType();
    uid.setUserID(String.valueOf(us2.getId().intValue()));
    dbt.setUserID(uid);
    BookingIDType bid = new BookingIDType();
    bid.setBookingID(bk1.getId().intValue());
    dbt.setBookingID(bid);

    CancelBookingResponse response = this.service.cancelBooking(request);

    ses.beginTransaction();
    ses.delete(bk1);
    ses.delete(perm1);
    ses.delete(r1);
    ses.delete(caps1);
    ses.delete(rigType1);
    ses.delete(assoc);
    ses.delete(assoc2);
    ses.delete(us1);
    ses.delete(us2);
    ses.delete(uclass1);
    ses.getTransaction().commit();

    assertNotNull(response);

    BookingResponseType bresp = response.getCancelBookingResponse();
    assertNotNull(bresp);
    assertFalse(bresp.getSuccess());
    assertEquals("User does not own or have academic permission to cancel.", bresp.getFailureReason());
}

From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.tests.BookingsServiceTester.java

License:Open Source License

@Test
public void testDeleteBookingsBookingNotOwned() throws Exception {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/* w  ww  .  j a v a2s  .  com*/
    UserClass uclass1 = new UserClass();
    uclass1.setName("booktestclass");
    uclass1.setActive(true);
    uclass1.setQueuable(false);
    uclass1.setBookable(true);
    uclass1.setTimeHorizon(1000);
    ses.save(uclass1);
    User us1 = new User();
    us1.setName("bktestuser1");
    us1.setNamespace("BKNS");
    us1.setPersona("USER");
    ses.save(us1);
    User us2 = new User();
    us2.setName("bktestuser2");
    us2.setNamespace("BKNS");
    us2.setPersona("USER");
    ses.save(us2);
    UserAssociation assoc = new UserAssociation();
    assoc.setId(new UserAssociationId(us1.getId(), uclass1.getId()));
    assoc.setUser(us1);
    assoc.setUserClass(uclass1);
    UserAssociation assoc2 = new UserAssociation();
    assoc2.setId(new UserAssociationId(us2.getId(), uclass1.getId()));
    assoc2.setUser(us2);
    assoc2.setUserClass(uclass1);
    ses.save(assoc);
    RigType rigType1 = new RigType("booktestrigtype", 300, false);
    ses.save(rigType1);
    RigCapabilities caps1 = new RigCapabilities("book,test,foo");
    ses.save(caps1);
    Rig r1 = new Rig();
    r1.setName("bkrig1");
    r1.setRigType(rigType1);
    r1.setLastUpdateTimestamp(new Date());
    r1.setRigCapabilities(caps1);
    ses.save(r1);

    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("RIG");
    perm1.setSessionDuration(1800);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setMaximumBookings(10);
    perm1.setRig(r1);
    perm1.setStartTime(new Date());
    perm1.setExpiryTime(new Date());
    perm1.setDisplayName("bookperm");
    ses.save(perm1);

    Bookings bk1 = new Bookings();
    bk1.setActive(true);
    bk1.setDuration(3600);
    bk1.setStartTime(new Date());
    bk1.setEndTime(new Date());
    bk1.setResourcePermission(perm1);
    bk1.setResourceType("RIG");
    bk1.setRig(r1);
    bk1.setUser(us1);
    bk1.setUserName(us1.getName());
    bk1.setUserNamespace(us1.getNamespace());
    ses.save(bk1);

    ses.getTransaction().commit();

    CancelBooking request = new CancelBooking();
    CancelBookingType dbt = new CancelBookingType();
    request.setCancelBooking(dbt);
    UserIDType uid = new UserIDType();
    uid.setUserID(String.valueOf(us2.getId().intValue()));
    dbt.setUserID(uid);
    BookingIDType bid = new BookingIDType();
    bid.setBookingID(bk1.getId().intValue());
    dbt.setBookingID(bid);

    CancelBookingResponse response = this.service.cancelBooking(request);

    ses.beginTransaction();
    ses.delete(bk1);
    ses.delete(perm1);
    ses.delete(r1);
    ses.delete(caps1);
    ses.delete(rigType1);
    ses.delete(assoc);
    ses.delete(assoc2);
    ses.delete(us1);
    ses.delete(us2);
    ses.delete(uclass1);
    ses.getTransaction().commit();

    assertNotNull(response);

    BookingResponseType bresp = response.getCancelBookingResponse();
    assertNotNull(bresp);
    assertFalse(bresp.getSuccess());
    assertEquals("User does not own booking.", bresp.getFailureReason());
}

From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.tests.BookingsServiceTester.java

License:Open Source License

@Test
public void testDeleteBookingsBookingNotActive() throws Exception {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/*  w w w.j  ava  2 s  . c  om*/
    UserClass uclass1 = new UserClass();
    uclass1.setName("booktestclass");
    uclass1.setActive(true);
    uclass1.setQueuable(false);
    uclass1.setBookable(true);
    uclass1.setTimeHorizon(1000);
    ses.save(uclass1);
    User us1 = new User();
    us1.setName("bktestuser1");
    us1.setNamespace("BKNS");
    us1.setPersona("USER");
    ses.save(us1);
    UserAssociation assoc = new UserAssociation();
    assoc.setId(new UserAssociationId(us1.getId(), uclass1.getId()));
    assoc.setUser(us1);
    assoc.setUserClass(uclass1);
    ses.save(assoc);
    RigType rigType1 = new RigType("booktestrigtype", 300, false);
    ses.save(rigType1);
    RigCapabilities caps1 = new RigCapabilities("book,test,foo");
    ses.save(caps1);
    Rig r1 = new Rig();
    r1.setName("bkrig1");
    r1.setRigType(rigType1);
    r1.setLastUpdateTimestamp(new Date());
    r1.setRigCapabilities(caps1);
    ses.save(r1);

    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("RIG");
    perm1.setSessionDuration(1800);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setMaximumBookings(10);
    perm1.setRig(r1);
    perm1.setStartTime(new Date());
    perm1.setExpiryTime(new Date());
    perm1.setDisplayName("bookperm");
    ses.save(perm1);

    Bookings bk1 = new Bookings();
    bk1.setActive(false);
    bk1.setDuration(3600);
    bk1.setStartTime(new Date());
    bk1.setEndTime(new Date());
    bk1.setResourcePermission(perm1);
    bk1.setResourceType("RIG");
    bk1.setRig(r1);
    bk1.setUser(us1);
    bk1.setUserName(us1.getName());
    bk1.setUserNamespace(us1.getNamespace());
    ses.save(bk1);

    ses.getTransaction().commit();

    CancelBooking request = new CancelBooking();
    CancelBookingType dbt = new CancelBookingType();
    request.setCancelBooking(dbt);
    UserIDType uid = new UserIDType();
    uid.setUserID(String.valueOf(us1.getId().intValue()));
    dbt.setUserID(uid);
    BookingIDType bid = new BookingIDType();
    bid.setBookingID(bk1.getId().intValue());
    dbt.setBookingID(bid);

    CancelBookingResponse response = this.service.cancelBooking(request);

    ses.beginTransaction();
    ses.delete(bk1);
    ses.delete(perm1);
    ses.delete(r1);
    ses.delete(caps1);
    ses.delete(rigType1);
    ses.delete(assoc);
    ses.delete(us1);
    ses.delete(uclass1);
    ses.getTransaction().commit();

    assertNotNull(response);

    BookingResponseType bresp = response.getCancelBookingResponse();
    assertNotNull(bresp);
    assertFalse(bresp.getSuccess());
    assertEquals("Booking already canceled or redeemed.", bresp.getFailureReason());

    OMElement ele = response.getOMElement(CancelBookingResponse.MY_QNAME, OMAbstractFactory.getOMFactory());
    assertNotNull(ele);

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

From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.tests.BookingsServiceTester.java

License:Open Source License

@Test
public void testDeleteBookingsNoBooking() throws Exception {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/*w ww.  j  a va 2  s . c o  m*/
    User user = new User();
    user.setNamespace("bookingtuser");
    user.setName("buser");
    user.setPersona("USER");
    ses.save(user);
    ses.getTransaction().commit();

    CancelBooking request = new CancelBooking();
    CancelBookingType dbt = new CancelBookingType();
    request.setCancelBooking(dbt);
    UserIDType uid = new UserIDType();
    uid.setUserQName("bookingtuser:buser");
    dbt.setUserID(uid);
    BookingIDType bid = new BookingIDType();
    bid.setBookingID(10241024);
    dbt.setBookingID(bid);

    CancelBookingResponse response = this.service.cancelBooking(request);

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

    assertNotNull(response);

    BookingResponseType bresp = response.getCancelBookingResponse();
    assertNotNull(bresp);
    assertFalse(bresp.getSuccess());
    assertEquals("Booking not found.", bresp.getFailureReason());

    OMElement ele = response.getOMElement(CancelBookingResponse.MY_QNAME, OMAbstractFactory.getOMFactory());
    assertNotNull(ele);

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

}

From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.tests.BookingsServiceTester.java

License:Open Source License

@Test
public void testFindFreeTimesResType() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();//  www .j av a 2s .  com
    UserClass uclass1 = new UserClass();
    uclass1.setName("booktestclass");
    uclass1.setActive(true);
    uclass1.setQueuable(false);
    uclass1.setBookable(true);
    uclass1.setTimeHorizon(1000);
    ses.save(uclass1);
    UserClass uclass2 = new UserClass();
    uclass2.setName("booktestclass2");
    uclass2.setActive(true);
    uclass2.setQueuable(false);
    uclass2.setBookable(true);
    uclass2.setTimeHorizon(1000);
    ses.save(uclass2);
    User us1 = new User();
    us1.setName("bktestuser1");
    us1.setNamespace("BKNS");
    us1.setPersona("USER");
    ses.save(us1);
    UserAssociation assoc = new UserAssociation();
    assoc.setId(new UserAssociationId(us1.getId(), uclass1.getId()));
    assoc.setUser(us1);
    assoc.setUserClass(uclass1);
    ses.save(assoc);
    RigType rigType1 = new RigType("booktestrigtype", 300, false);
    ses.save(rigType1);
    RigCapabilities caps1 = new RigCapabilities("book,test,foo");
    ses.save(caps1);
    Rig r1 = new Rig();
    r1.setName("bkrig1");
    r1.setRigType(rigType1);
    r1.setLastUpdateTimestamp(new Date());
    r1.setRigCapabilities(caps1);
    ses.save(r1);

    Calendar start = TimeUtil.getDayBegin(this.dayStr);
    start.add(Calendar.HOUR_OF_DAY, 3);
    Calendar end = TimeUtil.getDayBegin(this.dayStr);
    end.add(Calendar.DAY_OF_MONTH, 1);
    end.add(Calendar.MINUTE, -30);
    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("TYPE");
    perm1.setSessionDuration(1800);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setMaximumBookings(10);
    perm1.setRigType(rigType1);
    perm1.setStartTime(start.getTime());
    perm1.setExpiryTime(end.getTime());
    perm1.setDisplayName("bookperm");
    ses.save(perm1);
    ResourcePermission perm2 = new ResourcePermission();
    perm2.setUserClass(uclass2);
    perm2.setType("TYPE");
    perm2.setSessionDuration(1800);
    perm2.setQueueActivityTimeout(300);
    perm2.setAllowedExtensions((short) 10);
    perm2.setSessionActivityTimeout(300);
    perm2.setExtensionDuration(300);
    perm2.setMaximumBookings(10);
    perm2.setRigType(rigType1);
    perm2.setStartTime(start.getTime());
    perm2.setExpiryTime(end.getTime());
    perm2.setDisplayName("bookperm");
    ses.save(perm2);
    ResourcePermission perm3 = new ResourcePermission();
    perm3.setUserClass(uclass1);
    perm3.setType("TYPE");
    perm3.setSessionDuration(1800);
    perm3.setQueueActivityTimeout(300);
    perm3.setAllowedExtensions((short) 10);
    perm3.setSessionActivityTimeout(300);
    perm3.setExtensionDuration(300);
    perm3.setMaximumBookings(10);
    perm3.setRigType(rigType1);
    Calendar out = Calendar.getInstance();
    out.add(Calendar.MONTH, 1);
    perm3.setStartTime(out.getTime());
    out.add(Calendar.DAY_OF_MONTH, 1);
    perm3.setExpiryTime(out.getTime());
    perm3.setDisplayName("bookperm");
    ses.save(perm3);
    ses.getTransaction().commit();

    ses.refresh(caps1);
    ses.refresh(r1);
    ses.refresh(rigType1);
    ses.refresh(uclass1);
    ses.refresh(us1);

    FindFreeBookings request = new FindFreeBookings();
    FindBookingSlotType slotReq = new FindBookingSlotType();
    request.setFindBookingSlots(slotReq);
    UserIDType uid = new UserIDType();
    uid.setUserQName(us1.getNamespace() + ':' + us1.getName());
    slotReq.setUserID(uid);
    ResourceIDType reqres = new ResourceIDType();
    reqres.setType("TYPE");
    reqres.setResourceName(rigType1.getName());
    slotReq.setResourceID(reqres);

    TimePeriodType tp = new TimePeriodType();
    start.add(Calendar.HOUR_OF_DAY, -3);
    end.add(Calendar.MINUTE, 30);
    tp.setStartTime(start);
    tp.setEndTime(end);
    slotReq.setPeriod(tp);

    FindFreeBookingsResponse response = this.service.findFreeBookings(request);

    ses.beginTransaction();
    ses.delete(perm3);
    ses.delete(perm2);
    ses.delete(perm1);
    ses.delete(r1);
    ses.delete(caps1);
    ses.delete(rigType1);
    ses.delete(assoc);
    ses.delete(us1);
    ses.delete(uclass1);
    ses.delete(uclass2);
    ses.getTransaction().commit();

    assertNotNull(response);
    BookingSlotListType slots = response.getFindFreeBookingsResponse();
    assertNotNull(slots);

    ResourceIDType res = slots.getResourceID();
    assertNotNull(res);
    assertEquals("TYPE", res.getType());
    assertEquals(rigType1.getName(), res.getResourceName());

    PermissionIDType pid = slots.getPermissionID();
    assertNotNull(pid);
    assertEquals(perm1.getId().intValue(), pid.getPermissionID());

    BookingSlotType slotsList[] = slots.getBookingSlot();
    assertNotNull(slotsList);

    for (BookingSlotType s : slotsList) {
        assertNotNull(s.getState());

        TimePeriodType t = s.getSlot();
        assertNotNull(t);
        assertNotNull(t.getStartTime());
        assertNotNull(t.getEndTime());
    }

    assertEquals(3, slotsList.length);

    BookingSlotType bs = slotsList[0];
    assertEquals(SlotState.NOPERMISSION, bs.getState());
    Calendar s = bs.getSlot().getStartTime();
    assertEquals(0, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    Calendar e = bs.getSlot().getEndTime();
    assertEquals(3, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));

    bs = slotsList[1];
    assertEquals(SlotState.FREE, bs.getState());
    s = bs.getSlot().getStartTime();
    assertEquals(3, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    e = bs.getSlot().getEndTime();
    assertEquals(23, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(30, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));

    bs = slotsList[2];
    assertEquals(SlotState.NOPERMISSION, bs.getState());
    s = bs.getSlot().getStartTime();
    assertEquals(23, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(30, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    e = bs.getSlot().getEndTime();
    assertEquals(0, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));
}

From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.tests.BookingsServiceTester.java

License:Open Source License

@Test
public void testFindFreeTimesResRig() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/*from  w  ww . j  a va2  s.  c o m*/
    UserClass uclass1 = new UserClass();
    uclass1.setName("booktestclass");
    uclass1.setActive(true);
    uclass1.setQueuable(false);
    uclass1.setBookable(true);
    uclass1.setTimeHorizon(1000);
    ses.save(uclass1);
    UserClass uclass2 = new UserClass();
    uclass2.setName("booktestclass2");
    uclass2.setActive(true);
    uclass2.setQueuable(false);
    uclass2.setBookable(true);
    uclass2.setTimeHorizon(1000);
    ses.save(uclass2);
    User us1 = new User();
    us1.setName("bktestuser1");
    us1.setNamespace("BKNS");
    us1.setPersona("USER");
    ses.save(us1);
    UserAssociation assoc = new UserAssociation();
    assoc.setId(new UserAssociationId(us1.getId(), uclass1.getId()));
    assoc.setUser(us1);
    assoc.setUserClass(uclass1);
    ses.save(assoc);
    RigType rigType1 = new RigType("booktestrigtype", 300, false);
    ses.save(rigType1);
    RigCapabilities caps1 = new RigCapabilities("book,test,foo");
    ses.save(caps1);
    Rig r1 = new Rig();
    r1.setName("bkrig1");
    r1.setRigType(rigType1);
    r1.setLastUpdateTimestamp(new Date());
    r1.setRigCapabilities(caps1);
    ses.save(r1);

    Calendar start = TimeUtil.getDayBegin(this.dayStr);
    start.add(Calendar.HOUR_OF_DAY, 3);
    Calendar end = TimeUtil.getDayBegin(this.dayStr);
    end.add(Calendar.DAY_OF_MONTH, 1);
    end.add(Calendar.MINUTE, -30);
    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("RIG");
    perm1.setSessionDuration(1800);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setMaximumBookings(10);
    perm1.setRig(r1);
    perm1.setStartTime(start.getTime());
    perm1.setExpiryTime(end.getTime());
    perm1.setDisplayName("bookperm");
    ses.save(perm1);
    ResourcePermission perm2 = new ResourcePermission();
    perm2.setUserClass(uclass2);
    perm2.setType("TYPE");
    perm2.setSessionDuration(1800);
    perm2.setQueueActivityTimeout(300);
    perm2.setAllowedExtensions((short) 10);
    perm2.setSessionActivityTimeout(300);
    perm2.setExtensionDuration(300);
    perm2.setMaximumBookings(10);
    perm2.setRigType(rigType1);
    perm2.setStartTime(start.getTime());
    perm2.setExpiryTime(end.getTime());
    perm2.setDisplayName("bookperm");
    ses.save(perm2);
    ses.getTransaction().commit();

    ses.refresh(caps1);
    ses.refresh(r1);
    ses.refresh(rigType1);
    ses.refresh(uclass1);
    ses.refresh(us1);

    FindFreeBookings request = new FindFreeBookings();
    FindBookingSlotType slotReq = new FindBookingSlotType();
    request.setFindBookingSlots(slotReq);
    UserIDType uid = new UserIDType();
    uid.setUserQName(us1.getNamespace() + ':' + us1.getName());
    slotReq.setUserID(uid);
    ResourceIDType reqres = new ResourceIDType();
    reqres.setType("RIG");
    reqres.setResourceID(r1.getId().intValue());
    slotReq.setResourceID(reqres);

    TimePeriodType tp = new TimePeriodType();
    start.add(Calendar.HOUR_OF_DAY, -3);
    end.add(Calendar.MINUTE, 30);
    tp.setStartTime(start);
    tp.setEndTime(end);
    slotReq.setPeriod(tp);

    FindFreeBookingsResponse response = this.service.findFreeBookings(request);

    ses.beginTransaction();
    ses.delete(perm2);
    ses.delete(perm1);
    ses.delete(r1);
    ses.delete(caps1);
    ses.delete(rigType1);
    ses.delete(assoc);
    ses.delete(us1);
    ses.delete(uclass1);
    ses.delete(uclass2);
    ses.getTransaction().commit();

    assertNotNull(response);
    BookingSlotListType slots = response.getFindFreeBookingsResponse();
    assertNotNull(slots);

    ResourceIDType res = slots.getResourceID();
    assertNotNull(res);
    assertEquals("RIG", res.getType());
    assertEquals(r1.getId().intValue(), res.getResourceID());
    assertEquals(r1.getName(), res.getResourceName());

    PermissionIDType pid = slots.getPermissionID();
    assertNotNull(pid);
    assertEquals(perm1.getId().intValue(), pid.getPermissionID());

    BookingSlotType slotsList[] = slots.getBookingSlot();
    assertNotNull(slotsList);

    for (BookingSlotType s : slotsList) {
        assertNotNull(s.getState());

        TimePeriodType t = s.getSlot();
        assertNotNull(t);
        assertNotNull(t.getStartTime());
        assertNotNull(t.getEndTime());
    }

    assertEquals(3, slotsList.length);

    BookingSlotType bs = slotsList[0];
    assertEquals(SlotState.NOPERMISSION, bs.getState());
    Calendar s = bs.getSlot().getStartTime();
    assertEquals(0, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    Calendar e = bs.getSlot().getEndTime();
    assertEquals(3, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));

    bs = slotsList[1];
    assertEquals(SlotState.FREE, bs.getState());
    s = bs.getSlot().getStartTime();
    assertEquals(3, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    e = bs.getSlot().getEndTime();
    assertEquals(23, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(30, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));

    bs = slotsList[2];
    assertEquals(SlotState.NOPERMISSION, bs.getState());
    s = bs.getSlot().getStartTime();
    assertEquals(23, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(30, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    e = bs.getSlot().getEndTime();
    assertEquals(0, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));
}

From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.tests.BookingsServiceTester.java

License:Open Source License

@Test
public void testFindFreeTimesResCaps() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();//from   w ww . j a  v  a 2  s .com
    UserClass uclass1 = new UserClass();
    uclass1.setName("booktestclass");
    uclass1.setActive(true);
    uclass1.setQueuable(false);
    uclass1.setBookable(true);
    uclass1.setTimeHorizon(1000);
    ses.save(uclass1);
    UserClass uclass2 = new UserClass();
    uclass2.setName("booktestclass2");
    uclass2.setActive(true);
    uclass2.setQueuable(false);
    uclass2.setBookable(true);
    uclass2.setTimeHorizon(1000);
    ses.save(uclass2);
    User us1 = new User();
    us1.setName("bktestuser1");
    us1.setNamespace("BKNS");
    us1.setPersona("USER");
    ses.save(us1);
    UserAssociation assoc = new UserAssociation();
    assoc.setId(new UserAssociationId(us1.getId(), uclass1.getId()));
    assoc.setUser(us1);
    assoc.setUserClass(uclass1);
    ses.save(assoc);
    RigType rigType1 = new RigType("booktestrigtype", 300, false);
    ses.save(rigType1);
    RigCapabilities caps1 = new RigCapabilities("book,test,foo");
    ses.save(caps1);
    RequestCapabilities rcaps1 = new RequestCapabilities("book");
    ses.save(rcaps1);
    Rig r1 = new Rig();
    r1.setName("bkrig1");
    r1.setRigType(rigType1);
    r1.setLastUpdateTimestamp(new Date());
    r1.setRigCapabilities(caps1);
    ses.save(r1);
    Calendar start = TimeUtil.getDayBegin(this.dayStr);
    start.add(Calendar.HOUR_OF_DAY, 3);
    Calendar end = TimeUtil.getDayBegin(this.dayStr);
    end.add(Calendar.DAY_OF_MONTH, 1);
    end.add(Calendar.MINUTE, -30);
    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("CAPABILITY");
    perm1.setSessionDuration(1800);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setMaximumBookings(10);
    perm1.setRequestCapabilities(rcaps1);
    perm1.setStartTime(start.getTime());
    perm1.setExpiryTime(end.getTime());
    perm1.setDisplayName("bookperm");
    ses.save(perm1);
    ResourcePermission perm2 = new ResourcePermission();
    perm2.setUserClass(uclass2);
    perm2.setType("TYPE");
    perm2.setSessionDuration(1800);
    perm2.setQueueActivityTimeout(300);
    perm2.setAllowedExtensions((short) 10);
    perm2.setSessionActivityTimeout(300);
    perm2.setExtensionDuration(300);
    perm2.setMaximumBookings(10);
    perm2.setRigType(rigType1);
    perm2.setStartTime(start.getTime());
    perm2.setExpiryTime(end.getTime());
    perm2.setDisplayName("bookperm");
    ses.save(perm2);
    ses.getTransaction().commit();

    ses.beginTransaction();
    MatchingCapabilities m1 = new MatchingCapabilities(rcaps1, caps1);
    ses.save(m1);
    ses.getTransaction().commit();

    ses.refresh(caps1);
    ses.refresh(r1);
    ses.refresh(rigType1);
    ses.refresh(uclass1);
    ses.refresh(us1);

    FindFreeBookings request = new FindFreeBookings();
    FindBookingSlotType slotReq = new FindBookingSlotType();
    request.setFindBookingSlots(slotReq);
    UserIDType uid = new UserIDType();
    uid.setUserQName(us1.getNamespace() + ':' + us1.getName());
    slotReq.setUserID(uid);
    ResourceIDType reqres = new ResourceIDType();
    reqres.setType("CAPABILITY");
    reqres.setResourceID(rcaps1.getId().intValue());
    reqres.setResourceName(rcaps1.getCapabilities());
    slotReq.setResourceID(reqres);

    TimePeriodType tp = new TimePeriodType();
    start.add(Calendar.HOUR_OF_DAY, -3);
    end.add(Calendar.MINUTE, 30);
    tp.setStartTime(start);
    tp.setEndTime(end);
    slotReq.setPeriod(tp);

    FindFreeBookingsResponse response = this.service.findFreeBookings(request);

    ses.beginTransaction();
    ses.delete(perm2);
    ses.delete(perm1);
    ses.delete(r1);
    ses.delete(m1);
    ses.delete(rcaps1);
    ses.delete(caps1);
    ses.delete(rigType1);
    ses.delete(assoc);
    ses.delete(us1);
    ses.delete(uclass1);
    ses.delete(uclass2);
    ses.getTransaction().commit();

    assertNotNull(response);
    BookingSlotListType slots = response.getFindFreeBookingsResponse();
    assertNotNull(slots);

    ResourceIDType res = slots.getResourceID();
    assertNotNull(res);
    assertEquals("CAPABILITY", res.getType());
    assertEquals(rcaps1.getId().intValue(), res.getResourceID());
    assertEquals(rcaps1.getCapabilities(), res.getResourceName());

    PermissionIDType pid = slots.getPermissionID();
    assertNotNull(pid);
    assertEquals(perm1.getId().intValue(), pid.getPermissionID());

    BookingSlotType slotsList[] = slots.getBookingSlot();
    assertNotNull(slotsList);

    for (BookingSlotType s : slotsList) {
        assertNotNull(s.getState());

        TimePeriodType t = s.getSlot();
        assertNotNull(t);
        assertNotNull(t.getStartTime());
        assertNotNull(t.getEndTime());
    }

    assertEquals(3, slotsList.length);

    BookingSlotType bs = slotsList[0];
    assertEquals(SlotState.NOPERMISSION, bs.getState());
    Calendar s = bs.getSlot().getStartTime();
    assertEquals(0, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    Calendar e = bs.getSlot().getEndTime();
    assertEquals(3, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));

    bs = slotsList[1];
    assertEquals(SlotState.FREE, bs.getState());
    s = bs.getSlot().getStartTime();
    assertEquals(3, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    e = bs.getSlot().getEndTime();
    assertEquals(23, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(30, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));

    bs = slotsList[2];
    assertEquals(SlotState.NOPERMISSION, bs.getState());
    s = bs.getSlot().getStartTime();
    assertEquals(23, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(30, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    e = bs.getSlot().getEndTime();
    assertEquals(0, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));
}

From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.tests.BookingsServiceTester.java

License:Open Source License

@Test
public void testFindFreeTimesPermPartial() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/*from   w w w  .  j a v  a  2 s .c o m*/
    UserClass uclass1 = new UserClass();
    uclass1.setName("booktestclass");
    uclass1.setActive(true);
    uclass1.setQueuable(false);
    uclass1.setBookable(true);
    uclass1.setTimeHorizon(1000);
    ses.save(uclass1);
    User us1 = new User();
    us1.setName("bktestuser1");
    us1.setNamespace("BKNS");
    us1.setPersona("USER");
    ses.save(us1);
    UserAssociation assoc = new UserAssociation();
    assoc.setId(new UserAssociationId(us1.getId(), uclass1.getId()));
    assoc.setUser(us1);
    assoc.setUserClass(uclass1);
    ses.save(assoc);
    RigType rigType1 = new RigType("booktestrigtype", 300, false);
    ses.save(rigType1);
    RigCapabilities caps1 = new RigCapabilities("book,test,foo");
    ses.save(caps1);
    Rig r1 = new Rig();
    r1.setName("bkrig1");
    r1.setRigType(rigType1);
    r1.setLastUpdateTimestamp(new Date());
    r1.setRigCapabilities(caps1);
    ses.save(r1);

    Calendar start = TimeUtil.getDayBegin(this.dayStr);
    start.add(Calendar.HOUR_OF_DAY, 3);
    Calendar end = TimeUtil.getDayBegin(this.dayStr);
    end.add(Calendar.DAY_OF_MONTH, 1);
    end.add(Calendar.MINUTE, -30);
    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("TYPE");
    perm1.setSessionDuration(1800);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setMaximumBookings(10);
    perm1.setRigType(rigType1);
    perm1.setStartTime(start.getTime());
    perm1.setExpiryTime(end.getTime());
    perm1.setDisplayName("bookperm");
    ses.save(perm1);

    ses.getTransaction().commit();

    ses.refresh(caps1);
    ses.refresh(r1);
    ses.refresh(rigType1);
    ses.refresh(uclass1);
    ses.refresh(us1);

    FindFreeBookings request = new FindFreeBookings();
    FindBookingSlotType slotReq = new FindBookingSlotType();
    request.setFindBookingSlots(slotReq);
    UserIDType uid = new UserIDType();
    uid.setUserQName(us1.getNamespace() + ':' + us1.getName());
    slotReq.setUserID(uid);
    PermissionIDType pid = new PermissionIDType();
    pid.setPermissionID(perm1.getId().intValue());
    slotReq.setPermissionID(pid);

    TimePeriodType tp = new TimePeriodType();
    start.add(Calendar.HOUR_OF_DAY, -3);
    end.add(Calendar.MINUTE, 30);
    tp.setStartTime(start);
    tp.setEndTime(end);
    slotReq.setPeriod(tp);

    FindFreeBookingsResponse response = this.service.findFreeBookings(request);

    ses.beginTransaction();
    ses.delete(perm1);
    ses.delete(r1);
    ses.delete(caps1);
    ses.delete(rigType1);
    ses.delete(assoc);
    ses.delete(us1);
    ses.delete(uclass1);
    ses.getTransaction().commit();

    assertNotNull(response);
    BookingSlotListType slots = response.getFindFreeBookingsResponse();
    assertNotNull(slots);

    ResourceIDType res = slots.getResourceID();
    assertNotNull(res);
    assertEquals("TYPE", res.getType());
    assertEquals(rigType1.getId().intValue(), res.getResourceID());
    assertEquals(rigType1.getName(), res.getResourceName());

    pid = slots.getPermissionID();
    assertNotNull(pid);
    assertEquals(perm1.getId().intValue(), pid.getPermissionID());

    BookingSlotType slotsList[] = slots.getBookingSlot();
    assertNotNull(slotsList);

    for (BookingSlotType s : slotsList) {
        assertNotNull(s.getState());

        TimePeriodType t = s.getSlot();
        assertNotNull(t);
        assertNotNull(t.getStartTime());
        assertNotNull(t.getEndTime());
    }

    assertEquals(3, slotsList.length);

    BookingSlotType bs = slotsList[0];
    assertEquals(SlotState.NOPERMISSION, bs.getState());
    Calendar s = bs.getSlot().getStartTime();
    assertEquals(0, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    Calendar e = bs.getSlot().getEndTime();
    assertEquals(3, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));

    bs = slotsList[1];
    assertEquals(SlotState.FREE, bs.getState());
    s = bs.getSlot().getStartTime();
    assertEquals(3, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    e = bs.getSlot().getEndTime();
    assertEquals(23, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(30, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));

    bs = slotsList[2];
    assertEquals(SlotState.NOPERMISSION, bs.getState());
    s = bs.getSlot().getStartTime();
    assertEquals(23, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(30, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    e = bs.getSlot().getEndTime();
    assertEquals(0, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));
}

From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.tests.BookingsServiceTester.java

License:Open Source License

@Test
public void testFindFreeTimesBeforePerm() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();//  w w  w .  j  a v  a 2s  .  com
    UserClass uclass1 = new UserClass();
    uclass1.setName("booktestclass");
    uclass1.setActive(true);
    uclass1.setQueuable(false);
    uclass1.setBookable(true);
    uclass1.setTimeHorizon(1000);
    ses.save(uclass1);
    User us1 = new User();
    us1.setName("bktestuser1");
    us1.setNamespace("BKNS");
    us1.setPersona("USER");
    ses.save(us1);
    UserAssociation assoc = new UserAssociation();
    assoc.setId(new UserAssociationId(us1.getId(), uclass1.getId()));
    assoc.setUser(us1);
    assoc.setUserClass(uclass1);
    ses.save(assoc);
    RigType rigType1 = new RigType("booktestrigtype", 300, false);
    ses.save(rigType1);
    RigCapabilities caps1 = new RigCapabilities("book,test,foo");
    ses.save(caps1);
    Rig r1 = new Rig();
    r1.setName("bkrig1");
    r1.setRigType(rigType1);
    r1.setLastUpdateTimestamp(new Date());
    r1.setRigCapabilities(caps1);
    ses.save(r1);

    Calendar start = TimeUtil.getDayBegin(this.dayStr);
    Calendar end = TimeUtil.getDayBegin(this.dayStr);
    end.add(Calendar.DAY_OF_MONTH, 1);
    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("TYPE");
    perm1.setSessionDuration(1800);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setMaximumBookings(10);
    perm1.setRigType(rigType1);
    perm1.setStartTime(start.getTime());
    perm1.setExpiryTime(end.getTime());
    perm1.setDisplayName("bookperm");
    ses.save(perm1);

    ses.getTransaction().commit();

    ses.refresh(caps1);
    ses.refresh(r1);
    ses.refresh(rigType1);
    ses.refresh(uclass1);
    ses.refresh(us1);

    FindFreeBookings request = new FindFreeBookings();
    FindBookingSlotType slotReq = new FindBookingSlotType();
    request.setFindBookingSlots(slotReq);
    UserIDType uid = new UserIDType();
    uid.setUserQName(us1.getNamespace() + ':' + us1.getName());
    slotReq.setUserID(uid);
    PermissionIDType pid = new PermissionIDType();
    pid.setPermissionID(perm1.getId().intValue());
    slotReq.setPermissionID(pid);

    TimePeriodType tp = new TimePeriodType();
    start.add(Calendar.DAY_OF_MONTH, -5);
    end.add(Calendar.DAY_OF_MONTH, -5);
    tp.setStartTime(start);
    tp.setEndTime(end);
    slotReq.setPeriod(tp);

    FindFreeBookingsResponse response = this.service.findFreeBookings(request);

    ses.beginTransaction();
    ses.delete(perm1);
    ses.delete(r1);
    ses.delete(caps1);
    ses.delete(rigType1);
    ses.delete(assoc);
    ses.delete(us1);
    ses.delete(uclass1);
    ses.getTransaction().commit();

    assertNotNull(response);
    BookingSlotListType slots = response.getFindFreeBookingsResponse();
    assertNotNull(slots);

    ResourceIDType res = slots.getResourceID();
    assertNotNull(res);
    assertEquals("TYPE", res.getType());
    assertEquals(rigType1.getId().intValue(), res.getResourceID());
    assertEquals(rigType1.getName(), res.getResourceName());

    pid = slots.getPermissionID();
    assertNotNull(pid);
    assertEquals(perm1.getId().intValue(), pid.getPermissionID());

    BookingSlotType slotsList[] = slots.getBookingSlot();
    assertNotNull(slotsList);

    for (BookingSlotType s : slotsList) {
        assertNotNull(s.getState());

        TimePeriodType t = s.getSlot();
        assertNotNull(t);
        assertNotNull(t.getStartTime());
        assertNotNull(t.getEndTime());
    }

    assertEquals(1, slotsList.length);

    BookingSlotType bs = slotsList[0];
    assertEquals(SlotState.NOPERMISSION, bs.getState());
    Calendar s = bs.getSlot().getStartTime();
    assertEquals(0, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    Calendar e = bs.getSlot().getEndTime();
    assertEquals(0, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));
    assertTrue(e.getTimeInMillis() - s.getTimeInMillis() > 80e6);
}

From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.tests.BookingsServiceTester.java

License:Open Source License

@Test
public void testFindFreeTimesAfterPerm() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/*from w  w  w  .  ja v  a 2s .co m*/
    UserClass uclass1 = new UserClass();
    uclass1.setName("booktestclass");
    uclass1.setActive(true);
    uclass1.setQueuable(false);
    uclass1.setBookable(true);
    uclass1.setTimeHorizon(1000);
    ses.save(uclass1);
    User us1 = new User();
    us1.setName("bktestuser1");
    us1.setNamespace("BKNS");
    us1.setPersona("USER");
    ses.save(us1);
    UserAssociation assoc = new UserAssociation();
    assoc.setId(new UserAssociationId(us1.getId(), uclass1.getId()));
    assoc.setUser(us1);
    assoc.setUserClass(uclass1);
    ses.save(assoc);
    RigType rigType1 = new RigType("booktestrigtype", 300, false);
    ses.save(rigType1);
    RigCapabilities caps1 = new RigCapabilities("book,test,foo");
    ses.save(caps1);
    Rig r1 = new Rig();
    r1.setName("bkrig1");
    r1.setRigType(rigType1);
    r1.setLastUpdateTimestamp(new Date());
    r1.setRigCapabilities(caps1);
    ses.save(r1);

    Calendar start = TimeUtil.getDayBegin(this.dayStr);
    Calendar end = TimeUtil.getDayBegin(this.dayStr);
    end.add(Calendar.DAY_OF_MONTH, 1);
    ResourcePermission perm1 = new ResourcePermission();
    perm1.setUserClass(uclass1);
    perm1.setType("TYPE");
    perm1.setSessionDuration(1800);
    perm1.setQueueActivityTimeout(300);
    perm1.setAllowedExtensions((short) 10);
    perm1.setSessionActivityTimeout(300);
    perm1.setExtensionDuration(300);
    perm1.setMaximumBookings(10);
    perm1.setRigType(rigType1);
    perm1.setStartTime(start.getTime());
    perm1.setExpiryTime(end.getTime());
    perm1.setDisplayName("bookperm");
    ses.save(perm1);

    ses.getTransaction().commit();

    ses.refresh(caps1);
    ses.refresh(r1);
    ses.refresh(rigType1);
    ses.refresh(uclass1);
    ses.refresh(us1);

    FindFreeBookings request = new FindFreeBookings();
    FindBookingSlotType slotReq = new FindBookingSlotType();
    request.setFindBookingSlots(slotReq);
    UserIDType uid = new UserIDType();
    uid.setUserQName(us1.getNamespace() + ':' + us1.getName());
    slotReq.setUserID(uid);
    PermissionIDType pid = new PermissionIDType();
    pid.setPermissionID(perm1.getId().intValue());
    slotReq.setPermissionID(pid);

    TimePeriodType tp = new TimePeriodType();
    start.add(Calendar.DAY_OF_MONTH, 5);
    end.add(Calendar.DAY_OF_MONTH, 5);
    tp.setStartTime(start);
    tp.setEndTime(end);
    slotReq.setPeriod(tp);

    FindFreeBookingsResponse response = this.service.findFreeBookings(request);

    ses.beginTransaction();
    ses.delete(perm1);
    ses.delete(r1);
    ses.delete(caps1);
    ses.delete(rigType1);
    ses.delete(assoc);
    ses.delete(us1);
    ses.delete(uclass1);
    ses.getTransaction().commit();

    assertNotNull(response);
    BookingSlotListType slots = response.getFindFreeBookingsResponse();
    assertNotNull(slots);

    ResourceIDType res = slots.getResourceID();
    assertNotNull(res);
    assertEquals("TYPE", res.getType());
    assertEquals(rigType1.getId().intValue(), res.getResourceID());
    assertEquals(rigType1.getName(), res.getResourceName());

    pid = slots.getPermissionID();
    assertNotNull(pid);
    assertEquals(perm1.getId().intValue(), pid.getPermissionID());

    BookingSlotType slotsList[] = slots.getBookingSlot();
    assertNotNull(slotsList);

    for (BookingSlotType s : slotsList) {
        assertNotNull(s.getState());

        TimePeriodType t = s.getSlot();
        assertNotNull(t);
        assertNotNull(t.getStartTime());
        assertNotNull(t.getEndTime());
    }

    assertEquals(1, slotsList.length);

    BookingSlotType bs = slotsList[0];
    assertEquals(SlotState.NOPERMISSION, bs.getState());
    Calendar s = bs.getSlot().getStartTime();
    assertEquals(0, s.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, s.get(Calendar.MINUTE));
    assertEquals(0, s.get(Calendar.SECOND));
    Calendar e = bs.getSlot().getEndTime();
    assertEquals(0, e.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, e.get(Calendar.MINUTE));
    assertEquals(0, e.get(Calendar.SECOND));
    assertTrue(e.getTimeInMillis() - s.getTimeInMillis() > 80e6);
}