Search in sources :

Example 1 with IsaacEventPageDTO

use of uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO in project isaac-api by isaacphysics.

the class EventBookingManagerTest method requestBooking_checkTeacherAllowedOnStudentEventDespiteCapacityFull_noExceptionThrown.

@Test
public void requestBooking_checkTeacherAllowedOnStudentEventDespiteCapacityFull_noExceptionThrown() throws Exception {
    EventBookingManager ebm = this.buildEventBookingManager();
    IsaacEventPageDTO testEvent = new IsaacEventPageDTO();
    testEvent.setId("someEventId");
    testEvent.setNumberOfPlaces(1);
    testEvent.setTags(ImmutableSet.of("student", "physics"));
    testEvent.setEmailEventDetails("Some Details");
    testEvent.setDate(someFutureDate);
    RegisteredUserDTO someUser = new RegisteredUserDTO();
    someUser.setId(6L);
    someUser.setEmailVerificationStatus(EmailVerificationStatus.VERIFIED);
    someUser.setRole(Role.TEACHER);
    RegisteredUserDTO someStudentUser = new RegisteredUserDTO();
    someStudentUser.setId(1L);
    someStudentUser.setEmailVerificationStatus(EmailVerificationStatus.VERIFIED);
    someStudentUser.setRole(Role.STUDENT);
    EventBookingDTO firstBooking = new EventBookingDTO();
    UserSummaryDTO firstUser = new UserSummaryDTO();
    firstUser.setRole(Role.STUDENT);
    firstUser.setId(someStudentUser.getId());
    firstBooking.setUserBooked(firstUser);
    firstBooking.setBookingStatus(BookingStatus.CONFIRMED);
    Map<BookingStatus, Map<Role, Long>> placesAvailableMap = generatePlacesAvailableMap();
    placesAvailableMap.get(BookingStatus.CONFIRMED).put(Role.STUDENT, 1L);
    expect(dummyEventBookingPersistenceManager.getEventBookingStatusCounts(testEvent.getId(), false)).andReturn(placesAvailableMap).atLeastOnce();
    expect(dummyEventBookingPersistenceManager.getBookingByEventIdAndUserId(testEvent.getId(), someUser.getId())).andReturn(null).once();
    dummyEventBookingPersistenceManager.lockEventUntilTransactionComplete(dummyTransaction, testEvent.getId());
    expectLastCall().once();
    expect(dummyTransactionManager.getTransaction()).andReturn(dummyTransaction).once();
    dummyTransaction.commit();
    expectLastCall().once();
    dummyTransaction.close();
    expectLastCall().once();
    expect(dummyEventBookingPersistenceManager.createBooking(dummyTransaction, testEvent.getId(), someUser.getId(), BookingStatus.CONFIRMED, someAdditionalInformation)).andReturn(firstBooking).atLeastOnce();
    expect(dummyEmailManager.getEmailTemplateDTO("email-event-booking-confirmed")).andReturn(new EmailTemplateDTO()).atLeastOnce();
    dummyEmailManager.sendTemplatedEmailToUser(anyObject(), anyObject(), anyObject(), anyObject(), anyObject());
    expectLastCall().atLeastOnce();
    replay(mockedObjects);
    ebm.requestBooking(testEvent, someUser, someAdditionalInformation);
    verify(mockedObjects);
}
Also used : EmailTemplateDTO(uk.ac.cam.cl.dtg.isaac.dto.content.EmailTemplateDTO) UserSummaryDTO(uk.ac.cam.cl.dtg.isaac.dto.users.UserSummaryDTO) RegisteredUserDTO(uk.ac.cam.cl.dtg.isaac.dto.users.RegisteredUserDTO) IsaacEventPageDTO(uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO) EventBookingDTO(uk.ac.cam.cl.dtg.isaac.dto.eventbookings.EventBookingDTO) DetailedEventBookingDTO(uk.ac.cam.cl.dtg.isaac.dto.eventbookings.DetailedEventBookingDTO) BookingStatus(uk.ac.cam.cl.dtg.isaac.dos.eventbookings.BookingStatus) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 2 with IsaacEventPageDTO

use of uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO in project isaac-api by isaacphysics.

the class EventBookingManagerTest method requestBooking_addressNotVerified_addressNotVerifiedExceptionThrown.

@Test
public void requestBooking_addressNotVerified_addressNotVerifiedExceptionThrown() throws Exception {
    EventBookingManager ebm = this.buildEventBookingManager();
    IsaacEventPageDTO testEvent = new IsaacEventPageDTO();
    testEvent.setId("someEventId");
    testEvent.setNumberOfPlaces(1);
    testEvent.setTags(ImmutableSet.of("student", "physics"));
    RegisteredUserDTO someUser = new RegisteredUserDTO();
    someUser.setId(6L);
    someUser.setEmailVerificationStatus(EmailVerificationStatus.NOT_VERIFIED);
    someUser.setRole(Role.STUDENT);
    try {
        ebm.requestBooking(testEvent, someUser, someAdditionalInformation);
        fail("Expected an EventFullException and one didn't happen.");
    } catch (EmailMustBeVerifiedException e) {
    // success !
    }
}
Also used : RegisteredUserDTO(uk.ac.cam.cl.dtg.isaac.dto.users.RegisteredUserDTO) IsaacEventPageDTO(uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO) EmailMustBeVerifiedException(uk.ac.cam.cl.dtg.segue.comm.EmailMustBeVerifiedException) Test(org.junit.Test)

Example 3 with IsaacEventPageDTO

use of uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO in project isaac-api by isaacphysics.

the class EventBookingManagerTest method requestBooking_cancelledSpaceAndSomeWaitingList_Success.

@Test
public void requestBooking_cancelledSpaceAndSomeWaitingList_Success() throws Exception {
    EventBookingManager ebm = this.buildEventBookingManager();
    IsaacEventPageDTO testEvent = new IsaacEventPageDTO();
    testEvent.setId("someEventId");
    testEvent.setNumberOfPlaces(2);
    testEvent.setTags(ImmutableSet.of("teacher", "physics"));
    testEvent.setEmailEventDetails("Some Details");
    testEvent.setDate(someFutureDate);
    RegisteredUserDTO firstUserFull = new RegisteredUserDTO();
    firstUserFull.setId(6L);
    firstUserFull.setEmailVerificationStatus(EmailVerificationStatus.VERIFIED);
    firstUserFull.setRole(Role.TEACHER);
    DetailedEventBookingDTO firstBooking = new DetailedEventBookingDTO();
    UserSummaryDTO firstUser = new UserSummaryDTO();
    firstUser.setId(firstUserFull.getId());
    firstUser.setRole(Role.TEACHER);
    firstBooking.setUserBooked(firstUser);
    firstBooking.setBookingStatus(BookingStatus.WAITING_LIST);
    EventBookingDTO secondBooking = new EventBookingDTO();
    UserSummaryDTO secondUser = new UserSummaryDTO();
    secondUser.setRole(Role.TEACHER);
    secondUser.setId(7L);
    secondBooking.setUserBooked(firstUser);
    secondBooking.setBookingStatus(BookingStatus.CANCELLED);
    List<EventBookingDTO> currentBookings = Arrays.asList(firstBooking, secondBooking);
    Map<BookingStatus, Map<Role, Long>> placesAvailableMap = generatePlacesAvailableMap();
    placesAvailableMap.get(BookingStatus.CANCELLED).put(Role.TEACHER, 1L);
    placesAvailableMap.get(BookingStatus.WAITING_LIST).put(Role.TEACHER, 1L);
    expect(dummyEventBookingPersistenceManager.getEventBookingStatusCounts(testEvent.getId(), false)).andReturn(placesAvailableMap).atLeastOnce();
    expect(dummyEventBookingPersistenceManager.getBookingByEventIdAndUserId(testEvent.getId(), firstUserFull.getId())).andReturn(firstBooking).once();
    dummyEventBookingPersistenceManager.lockEventUntilTransactionComplete(dummyTransaction, testEvent.getId());
    expectLastCall().once();
    expect(dummyTransactionManager.getTransaction()).andReturn(dummyTransaction).once();
    dummyTransaction.commit();
    expectLastCall().once();
    dummyTransaction.close();
    expectLastCall().once();
    expect(dummyEventBookingPersistenceManager.createBooking(dummyTransaction, testEvent.getId(), firstUserFull.getId(), BookingStatus.CONFIRMED, someAdditionalInformation)).andReturn(secondBooking).atLeastOnce();
    dummyEmailManager.sendTemplatedEmailToUser(anyObject(), anyObject(), anyObject(), anyObject(), anyObject());
    expectLastCall().atLeastOnce();
    expect(dummyEmailManager.getEmailTemplateDTO("email-event-booking-confirmed")).andReturn(new EmailTemplateDTO()).atLeastOnce();
    replay(mockedObjects);
    try {
        ebm.requestBooking(testEvent, firstUserFull, someAdditionalInformation);
    // success
    } catch (EventIsFullException e) {
        fail("Expected successful booking as no waiting list bookings.");
    }
    verify(mockedObjects);
}
Also used : EmailTemplateDTO(uk.ac.cam.cl.dtg.isaac.dto.content.EmailTemplateDTO) UserSummaryDTO(uk.ac.cam.cl.dtg.isaac.dto.users.UserSummaryDTO) RegisteredUserDTO(uk.ac.cam.cl.dtg.isaac.dto.users.RegisteredUserDTO) DetailedEventBookingDTO(uk.ac.cam.cl.dtg.isaac.dto.eventbookings.DetailedEventBookingDTO) IsaacEventPageDTO(uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO) EventBookingDTO(uk.ac.cam.cl.dtg.isaac.dto.eventbookings.EventBookingDTO) DetailedEventBookingDTO(uk.ac.cam.cl.dtg.isaac.dto.eventbookings.DetailedEventBookingDTO) BookingStatus(uk.ac.cam.cl.dtg.isaac.dos.eventbookings.BookingStatus) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 4 with IsaacEventPageDTO

use of uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO in project isaac-api by isaacphysics.

the class EventBookingManagerTest method getPlacesAvailable_checkEventCapacity_capacityCalculatedCorrectly.

@Test
public void getPlacesAvailable_checkEventCapacity_capacityCalculatedCorrectly() throws Exception {
    // Create a future event and event booking manager
    EventBookingManager ebm = this.buildEventBookingManager();
    int initialNumberOfPlaces = 1000;
    IsaacEventPageDTO testEvent = new IsaacEventPageDTO() {

        {
            setId("someEventId");
            setNumberOfPlaces(initialNumberOfPlaces);
            setTags(ImmutableSet.of("student"));
            setEventStatus(EventStatus.OPEN);
            setDate(someFutureDate);
        }
    };
    // Mock the event booking status count result from the event booking persistence manager
    Map<BookingStatus, Map<Role, Long>> placesAvailableMap = generatePlacesAvailableMap();
    // Student places
    placesAvailableMap.get(BookingStatus.CONFIRMED).put(Role.STUDENT, 1L);
    placesAvailableMap.get(BookingStatus.WAITING_LIST).put(Role.STUDENT, 10L);
    placesAvailableMap.get(BookingStatus.CANCELLED).put(Role.STUDENT, 100L);
    // Teacher places
    placesAvailableMap.get(BookingStatus.CONFIRMED).put(Role.TEACHER, 2L);
    placesAvailableMap.get(BookingStatus.WAITING_LIST).put(Role.TEACHER, 20L);
    placesAvailableMap.get(BookingStatus.CANCELLED).put(Role.TEACHER, 200L);
    expect(dummyEventBookingPersistenceManager.getEventBookingStatusCounts(testEvent.getId(), false)).andReturn(placesAvailableMap).atLeastOnce();
    // Run the test for a student event
    replay(mockedObjects);
    Long actualPlacesAvailable = ebm.getPlacesAvailable(testEvent);
    Long expectedPlacesAvailable = (long) initialNumberOfPlaces - 1 - 10;
    assertEquals("STUDENT events should only count confirmed and waiting list student places in availability calculations", expectedPlacesAvailable, actualPlacesAvailable);
    verify(mockedObjects);
}
Also used : IsaacEventPageDTO(uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO) BookingStatus(uk.ac.cam.cl.dtg.isaac.dos.eventbookings.BookingStatus) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 5 with IsaacEventPageDTO

use of uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO in project isaac-api by isaacphysics.

the class EventBookingManagerTest method getEventPage_checkWaitingListOnlyEventCapacity_capacityCalculatedCorrectly.

@Test
public void getEventPage_checkWaitingListOnlyEventCapacity_capacityCalculatedCorrectly() throws Exception {
    EventBookingManager ebm = this.buildEventBookingManager();
    IsaacEventPageDTO testEvent = new IsaacEventPageDTO();
    testEvent.setId("someEventId");
    testEvent.setNumberOfPlaces(2);
    testEvent.setTags(ImmutableSet.of("student", "physics"));
    testEvent.setEventStatus(EventStatus.WAITING_LIST_ONLY);
    testEvent.setDate(someFutureDate);
    RegisteredUserDTO someUser = new RegisteredUserDTO();
    someUser.setId(6L);
    someUser.setEmailVerificationStatus(EmailVerificationStatus.VERIFIED);
    someUser.setRole(Role.STUDENT);
    EventBookingDTO firstBooking = new EventBookingDTO();
    UserSummaryDTO firstUser = new UserSummaryDTO();
    firstUser.setRole(Role.STUDENT);
    firstBooking.setUserBooked(firstUser);
    firstBooking.setBookingStatus(BookingStatus.CONFIRMED);
    EventBookingDTO secondBooking = new EventBookingDTO();
    UserSummaryDTO secondUser = new UserSummaryDTO();
    secondUser.setRole(Role.STUDENT);
    secondBooking.setUserBooked(secondUser);
    secondBooking.setBookingStatus(BookingStatus.WAITING_LIST);
    List<EventBookingDTO> currentBookings = Arrays.asList(firstBooking, secondBooking);
    Map<BookingStatus, Map<Role, Long>> placesAvailableMap = generatePlacesAvailableMap();
    placesAvailableMap.get(BookingStatus.CONFIRMED).put(Role.STUDENT, 1L);
    placesAvailableMap.get(BookingStatus.WAITING_LIST).put(Role.STUDENT, 1L);
    expect(dummyEventBookingPersistenceManager.getEventBookingStatusCounts(testEvent.getId(), false)).andReturn(placesAvailableMap).atLeastOnce();
    replay(mockedObjects);
    Long placesAvailable = ebm.getPlacesAvailable(testEvent);
    Long expectedPlacesAvailable = 1L;
    assertEquals("WAITING_LIST_ONLY events should only count confirmed places in availability calculations", placesAvailable, expectedPlacesAvailable);
    verify(mockedObjects);
}
Also used : UserSummaryDTO(uk.ac.cam.cl.dtg.isaac.dto.users.UserSummaryDTO) RegisteredUserDTO(uk.ac.cam.cl.dtg.isaac.dto.users.RegisteredUserDTO) IsaacEventPageDTO(uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO) EventBookingDTO(uk.ac.cam.cl.dtg.isaac.dto.eventbookings.EventBookingDTO) DetailedEventBookingDTO(uk.ac.cam.cl.dtg.isaac.dto.eventbookings.DetailedEventBookingDTO) BookingStatus(uk.ac.cam.cl.dtg.isaac.dos.eventbookings.BookingStatus) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

IsaacEventPageDTO (uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO)35 RegisteredUserDTO (uk.ac.cam.cl.dtg.isaac.dto.users.RegisteredUserDTO)28 DetailedEventBookingDTO (uk.ac.cam.cl.dtg.isaac.dto.eventbookings.DetailedEventBookingDTO)20 EventBookingDTO (uk.ac.cam.cl.dtg.isaac.dto.eventbookings.EventBookingDTO)20 BookingStatus (uk.ac.cam.cl.dtg.isaac.dos.eventbookings.BookingStatus)19 ContentManagerException (uk.ac.cam.cl.dtg.segue.dao.content.ContentManagerException)18 ImmutableMap (com.google.common.collect.ImmutableMap)16 Map (java.util.Map)16 SegueDatabaseException (uk.ac.cam.cl.dtg.segue.dao.SegueDatabaseException)16 ApiOperation (io.swagger.annotations.ApiOperation)15 Path (javax.ws.rs.Path)15 Produces (javax.ws.rs.Produces)15 SegueErrorResponse (uk.ac.cam.cl.dtg.isaac.dto.SegueErrorResponse)15 NoUserLoggedInException (uk.ac.cam.cl.dtg.segue.auth.exceptions.NoUserLoggedInException)15 GZIP (org.jboss.resteasy.annotations.GZIP)14 Test (org.junit.Test)14 UserSummaryDTO (uk.ac.cam.cl.dtg.isaac.dto.users.UserSummaryDTO)13 Date (java.util.Date)12 POST (javax.ws.rs.POST)11 NoUserException (uk.ac.cam.cl.dtg.segue.auth.exceptions.NoUserException)11