Search in sources :

Example 1 with EventRepository

use of com.management.repositories.EventRepository 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 2 with EventRepository

use of com.management.repositories.EventRepository 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 3 with EventRepository

use of com.management.repositories.EventRepository in project Internet-Software-Architectures by zivko11.

the class EvenetManagerTests method ReadAllEvents_ReturnsAllEvents.

@Test
public void ReadAllEvents_ReturnsAllEvents() {
    // 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);
    // Act
    ArrayList<EventDTO> listDTO = manager.ReadAll();
    // Assert
    Assert.assertNotNull(listDTO);
    Assert.assertEquals(listDTO.get(0).getEventId(), list.get(0).getEventId());
    Assert.assertEquals(listDTO.get(1).getEventId(), list.get(1).getEventId());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) ArrayList(java.util.ArrayList) 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 EventRepository

use of com.management.repositories.EventRepository in project Internet-Software-Architectures by zivko11.

the class EvenetManagerTests method ReadEvent_ReturnsEvent.

@Test
public void ReadEvent_ReturnsEvent() {
    // 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);
    // Act
    EventDTO dto = manager.Read(1);
    // Assert
    Assert.assertNotNull(dto);
    Assert.assertEquals(dto.getEventId(), event.getEventId());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) 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 5 with EventRepository

use of com.management.repositories.EventRepository in project Internet-Software-Architectures by zivko11.

the class EvenetManagerTests method DeletingEvent_ReturnsBoolean.

@Test
public void DeletingEvent_ReturnsBoolean() {
    // 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);
    Assert.assertNotNull(manager);
    Assert.assertTrue(manager.Delete(1));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) EventRepository(com.management.repositories.EventRepository) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Aggregations

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