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);
}
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 !
}
}
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);
}
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);
}
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);
}
Aggregations