Search in sources :

Example 6 with Seat

use of com.management.entities.Seat 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 7 with Seat

use of com.management.entities.Seat in project Internet-Software-Architectures by zivko11.

the class SeatManagerTests method AddingNewSeat_ReturnsBoolean.

@Test
public void AddingNewSeat_ReturnsBoolean() {
    // Arrange
    seatRepository = new SeatRepositoryFake();
    SeatDTO dto = new SeatDTO();
    dto.setSeatModified(new Date());
    dto.setSeatTaken(true);
    SeatManager manager = new SeatManager(seatRepository);
    // Act and assert
    Assert.assertNotNull(manager);
    Assert.assertTrue(manager.Create(dto));
    Seat seat = seatRepository.findOne(0);
    Assert.assertEquals(dto.getSeatId(), seat.getSeatId());
    Assert.assertEquals(dto.getSeatModified(), seat.getSeatModified());
    Assert.assertEquals(dto.isSeatTaken(), seat.isSeatTaken());
}
Also used : SeatDTO(com.management.dto.SeatDTO) Seat(com.management.entities.Seat) SeatRepositoryFake(com.management.fake.SeatRepositoryFake) Date(java.util.Date) Test(org.junit.Test)

Example 8 with Seat

use of com.management.entities.Seat in project Internet-Software-Architectures by zivko11.

the class SeatManager method ReadAll.

public ArrayList<SeatDTO> ReadAll() {
    ModelMapper mapper = new ModelMapper();
    ArrayList<Seat> listEntities = (ArrayList<Seat>) seatRepository.findAll();
    ArrayList<SeatDTO> listDTO = new ArrayList<SeatDTO>();
    for (Seat tmp : listEntities) {
        try {
            SeatDTO dto = mapper.map(tmp, SeatDTO.class);
            listDTO.add(dto);
        } catch (Exception exc) {
            exc.printStackTrace();
            return null;
        }
    }
    return listDTO;
}
Also used : SeatDTO(com.management.dto.SeatDTO) Seat(com.management.entities.Seat) ArrayList(java.util.ArrayList) ModelMapper(org.modelmapper.ModelMapper)

Example 9 with Seat

use of com.management.entities.Seat in project Internet-Software-Architectures by zivko11.

the class SeatControllerTests method ReadSeat_ReturnsOK.

@Test
public void ReadSeat_ReturnsOK() {
    // 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);
    SeatController controller = new SeatController(manager);
    // Act
    ResponseEntity<SeatDTO> response = controller.getSeat(1);
    SeatDTO dto = response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<SeatDTO>(dto, HttpStatus.OK));
    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) SeatManager(com.management.managers.SeatManager) Test(org.junit.Test)

Aggregations

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