Search in sources :

Example 1 with SeatRepository

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

the class SeatManagerTests method ReadSeat_ReturnsSeat.

@Test
public void ReadSeat_ReturnsSeat() {
    // Arrange
    Mockery mock = new Mockery();
    seatRepository = mock.mock(SeatRepository.class);
    final Seat seat = new Seat();
    seat.setSeatModified(new Date());
    seat.setSeatTaken(true);
    mock.checking(new Expectations() {

        {
            oneOf(seatRepository).findOne(1);
            will(returnValue(seat));
        }
    });
    SeatManager manager = new SeatManager(seatRepository);
    // Act
    SeatDTO dto = manager.Read(1);
    // Assert
    Assert.assertNotNull(dto);
    Assert.assertEquals(dto.getSeatId(), seat.getSeatId());
    Assert.assertEquals(dto.getSeatModified(), seat.getSeatModified());
    Assert.assertEquals(dto.isSeatTaken(), seat.isSeatTaken());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) SeatDTO(com.management.dto.SeatDTO) Seat(com.management.entities.Seat) SeatRepository(com.management.repositories.SeatRepository) Mockery(org.jmock.Mockery) Date(java.util.Date) Test(org.junit.Test)

Example 2 with SeatRepository

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

the class SeatManagerTests method ReadAllSeats_ReturnsAllSeats.

@Test
public void ReadAllSeats_ReturnsAllSeats() {
    // Arrange
    Mockery mock = new Mockery();
    seatRepository = mock.mock(SeatRepository.class);
    final ArrayList<Seat> list = new ArrayList<Seat>();
    Seat seat1 = new Seat();
    seat1.setSeatModified(new Date());
    seat1.setSeatTaken(true);
    Seat seat2 = new Seat();
    seat2.setSeatModified(new Date());
    seat2.setSeatTaken(false);
    list.add(seat1);
    list.add(seat2);
    mock.checking(new Expectations() {

        {
            oneOf(seatRepository).findAll();
            will(returnValue(list));
        }
    });
    SeatManager manager = new SeatManager(seatRepository);
    // Act
    ArrayList<SeatDTO> listDTO = manager.ReadAll();
    // Assert
    Assert.assertNotNull(listDTO);
    Assert.assertEquals(listDTO.get(0).getSeatId(), list.get(0).getSeatId());
    Assert.assertEquals(listDTO.get(0).getSeatModified(), list.get(0).getSeatModified());
    Assert.assertEquals(listDTO.get(0).isSeatTaken(), list.get(0).isSeatTaken());
    Assert.assertEquals(listDTO.get(1).getSeatId(), list.get(1).getSeatId());
    Assert.assertEquals(listDTO.get(1).getSeatModified(), list.get(1).getSeatModified());
    Assert.assertEquals(listDTO.get(1).isSeatTaken(), list.get(1).isSeatTaken());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) SeatDTO(com.management.dto.SeatDTO) Seat(com.management.entities.Seat) ArrayList(java.util.ArrayList) SeatRepository(com.management.repositories.SeatRepository) Mockery(org.jmock.Mockery) Date(java.util.Date) Test(org.junit.Test)

Example 3 with SeatRepository

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

the class SeatControllerTests method ReadAllSeats_ReturnsOK.

@Test
public void ReadAllSeats_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    seatRepository = mock.mock(SeatRepository.class);
    final ArrayList<Seat> list = new ArrayList<Seat>();
    Seat seat1 = new Seat();
    seat1.setSeatModified(new Date());
    seat1.setSeatTaken(true);
    Seat seat2 = new Seat();
    seat2.setSeatModified(new Date());
    seat2.setSeatTaken(false);
    list.add(seat1);
    list.add(seat2);
    mock.checking(new Expectations() {

        {
            oneOf(seatRepository).findAll();
            will(returnValue(list));
        }
    });
    SeatManager manager = new SeatManager(seatRepository);
    SeatController controller = new SeatController(manager);
    // Act
    ResponseEntity<List<SeatDTO>> response = controller.getSeats();
    ArrayList<SeatDTO> listDTO = (ArrayList<SeatDTO>) response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<List<SeatDTO>>(listDTO, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) Seat(com.management.entities.Seat) ArrayList(java.util.ArrayList) SeatRepository(com.management.repositories.SeatRepository) Mockery(org.jmock.Mockery) Date(java.util.Date) SeatDTO(com.management.dto.SeatDTO) ArrayList(java.util.ArrayList) List(java.util.List) SeatManager(com.management.managers.SeatManager) Test(org.junit.Test)

Example 4 with SeatRepository

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

the class SeatManagerTests method DeletingSeat_ReturnsBoolean.

@Test
public void DeletingSeat_ReturnsBoolean() {
    // Arrange
    Mockery mock = new Mockery();
    seatRepository = mock.mock(SeatRepository.class);
    // expectations
    mock.checking(new Expectations() {

        {
            oneOf(seatRepository).delete(1);
        }
    });
    // Act and assert
    SeatManager manager = new SeatManager(seatRepository);
    Assert.assertNotNull(manager);
    Assert.assertTrue(manager.Delete(1));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) SeatRepository(com.management.repositories.SeatRepository) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Example 5 with SeatRepository

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

the class SeatControllerTests method DeletingSeat_ReturnsOK.

@Test
public void DeletingSeat_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    seatRepository = mock.mock(SeatRepository.class);
    // expectations
    mock.checking(new Expectations() {

        {
            oneOf(seatRepository).delete(1);
        }
    });
    // Act and assert
    SeatManager manager = new SeatManager(seatRepository);
    SeatController controller = new SeatController(manager);
    Assert.assertNotNull(controller);
    Assert.assertEquals(controller.deleteSeat(1), new ResponseEntity<SeatDTO>(HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) SeatDTO(com.management.dto.SeatDTO) SeatRepository(com.management.repositories.SeatRepository) Mockery(org.jmock.Mockery) SeatManager(com.management.managers.SeatManager) Test(org.junit.Test)

Aggregations

SeatRepository (com.management.repositories.SeatRepository)6 Expectations (org.jmock.Expectations)6 Mockery (org.jmock.Mockery)6 Test (org.junit.Test)6 SeatDTO (com.management.dto.SeatDTO)5 Seat (com.management.entities.Seat)4 Date (java.util.Date)4 SeatManager (com.management.managers.SeatManager)3 ArrayList (java.util.ArrayList)2 List (java.util.List)1