Search in sources :

Example 1 with Seat

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

the class SeatManager method Create.

public boolean Create(SeatDTO dto) {
    ModelMapper mapper = new ModelMapper();
    Seat seat;
    try {
        seat = mapper.map(dto, Seat.class);
    } catch (Exception exc) {
        exc.printStackTrace();
        return false;
    }
    seatRepository.save(seat);
    return true;
}
Also used : Seat(com.management.entities.Seat) ModelMapper(org.modelmapper.ModelMapper)

Example 2 with Seat

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

the class SeatManager method Read.

public SeatDTO Read(int id) {
    ModelMapper mapper = new ModelMapper();
    SeatDTO dto;
    try {
        Seat seat = seatRepository.findOne(id);
        dto = mapper.map(seat, SeatDTO.class);
    } catch (Exception exc) {
        exc.printStackTrace();
        return null;
    }
    return dto;
}
Also used : SeatDTO(com.management.dto.SeatDTO) Seat(com.management.entities.Seat) ModelMapper(org.modelmapper.ModelMapper)

Example 3 with Seat

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

the class SeatManager method Update.

public boolean Update(SeatDTO dto) {
    ModelMapper mapper = new ModelMapper();
    Seat tmp;
    try {
        tmp = mapper.map(dto, Seat.class);
    } catch (Exception exc) {
        exc.printStackTrace();
        return false;
    }
    seatRepository.save(tmp);
    return true;
}
Also used : Seat(com.management.entities.Seat) ModelMapper(org.modelmapper.ModelMapper)

Example 4 with Seat

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

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

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