Search in sources :

Example 1 with EventManager

use of com.management.managers.EventManager in project Internet-Software-Architectures by zivko11.

the class EventControllerTests method AddingNewEvent_ReturnsOK.

@Test
public void AddingNewEvent_ReturnsOK() {
    // Arrange
    eventRepository = new EventRepositoryFake();
    EventDTO dto = new EventDTO();
    dto.setEventDate(new Date());
    EventManager manager = new EventManager(eventRepository);
    EventController controller = new EventController(manager);
    // Act and assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(controller.addEvent(dto), new ResponseEntity<EventDTO>(dto, HttpStatus.OK));
}
Also used : EventManager(com.management.managers.EventManager) EventDTO(com.management.dto.EventDTO) EventRepositoryFake(com.management.fake.EventRepositoryFake) Date(java.util.Date) Test(org.junit.Test)

Example 2 with EventManager

use of com.management.managers.EventManager in project Internet-Software-Architectures by zivko11.

the class EventControllerTests method DeletingEvent_ReturnsOK.

@Test
public void DeletingEvent_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    eventRepository = mock.mock(EventRepository.class);
    // expectations
    mock.checking(new Expectations() {

        {
            oneOf(eventRepository).delete(1);
        }
    });
    // Act and assert
    EventManager manager = new EventManager(eventRepository);
    EventController controller = new EventController(manager);
    Assert.assertNotNull(controller);
    Assert.assertEquals(controller.deleteEvent(1), new ResponseEntity<EventDTO>(HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) EventManager(com.management.managers.EventManager) EventDTO(com.management.dto.EventDTO) EventRepository(com.management.repositories.EventRepository) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Example 3 with EventManager

use of com.management.managers.EventManager in project Internet-Software-Architectures by zivko11.

the class EventControllerTests method ReadEvent_ReturnsOK.

@Test
public void ReadEvent_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    eventRepository = mock.mock(EventRepository.class);
    final Event event = new Event();
    event.setEventDate(new Date());
    mock.checking(new Expectations() {

        {
            oneOf(eventRepository).findOne(1);
            will(returnValue(event));
        }
    });
    EventManager manager = new EventManager(eventRepository);
    EventController controller = new EventController(manager);
    // Act
    ResponseEntity<EventDTO> response = controller.getEvent(1);
    EventDTO dto = response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<EventDTO>(dto, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) EventManager(com.management.managers.EventManager) EventDTO(com.management.dto.EventDTO) Event(com.management.entities.Event) EventRepository(com.management.repositories.EventRepository) Mockery(org.jmock.Mockery) Date(java.util.Date) Test(org.junit.Test)

Example 4 with EventManager

use of com.management.managers.EventManager in project Internet-Software-Architectures by zivko11.

the class EventControllerTests method ReadAllEvents_ReturnsOK.

@Test
public void ReadAllEvents_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    eventRepository = mock.mock(EventRepository.class);
    final ArrayList<Event> list = new ArrayList<Event>();
    Event event1 = new Event();
    event1.setEventDate(new Date());
    Event event2 = new Event();
    event2.setEventDate(new Date());
    list.add(event1);
    list.add(event2);
    mock.checking(new Expectations() {

        {
            oneOf(eventRepository).findAll();
            will(returnValue(list));
        }
    });
    EventManager manager = new EventManager(eventRepository);
    EventController controller = new EventController(manager);
    // Act
    ResponseEntity<List<EventDTO>> response = controller.getEvents();
    ArrayList<EventDTO> listDTO = (ArrayList<EventDTO>) response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<List<EventDTO>>(listDTO, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) EventManager(com.management.managers.EventManager) ArrayList(java.util.ArrayList) EventDTO(com.management.dto.EventDTO) Mockery(org.jmock.Mockery) Date(java.util.Date) Event(com.management.entities.Event) EventRepository(com.management.repositories.EventRepository) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

EventDTO (com.management.dto.EventDTO)4 EventManager (com.management.managers.EventManager)4 Test (org.junit.Test)4 EventRepository (com.management.repositories.EventRepository)3 Date (java.util.Date)3 Expectations (org.jmock.Expectations)3 Mockery (org.jmock.Mockery)3 Event (com.management.entities.Event)2 EventRepositoryFake (com.management.fake.EventRepositoryFake)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1