Search in sources :

Example 1 with CinemaTheatreDTO

use of com.management.dto.CinemaTheatreDTO in project Internet-Software-Architectures by zivko11.

the class CinemaTheatreControllerTests method ReadCinemaTheatre_ReturnsOK.

@Test
public void ReadCinemaTheatre_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    cinemaTheatreRepository = mock.mock(CinemaTheatreRepository.class);
    final CinemaTheatre cinemaTheatre = new CinemaTheatre();
    cinemaTheatre.setCtAdress("Bulevar oslobodjenja 11");
    cinemaTheatre.setCtDescription("Ovo je opis.");
    cinemaTheatre.setCtName("Bioskop");
    cinemaTheatre.setCtPhone(1234567890);
    cinemaTheatre.setCtStateid("381");
    mock.checking(new Expectations() {

        {
            oneOf(cinemaTheatreRepository).findOne(1);
            will(returnValue(cinemaTheatre));
        }
    });
    CinemaTheatreManager manager = new CinemaTheatreManager(cinemaTheatreRepository);
    CinemaTheatreController controller = new CinemaTheatreController(manager);
    // Act
    ResponseEntity<CinemaTheatreDTO> response = controller.getCinemaTheatre(1);
    CinemaTheatreDTO dto = response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<CinemaTheatreDTO>(dto, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) CinemaTheatreManager(com.management.managers.CinemaTheatreManager) CinemaTheatreRepository(com.management.repositories.CinemaTheatreRepository) CinemaTheatreDTO(com.management.dto.CinemaTheatreDTO) Mockery(org.jmock.Mockery) CinemaTheatre(com.management.entities.CinemaTheatre) Test(org.junit.Test)

Example 2 with CinemaTheatreDTO

use of com.management.dto.CinemaTheatreDTO in project Internet-Software-Architectures by zivko11.

the class CinemaTheatreManagerTests method ReadCinemaTheatre_ReturnsUser.

@Test
public void ReadCinemaTheatre_ReturnsUser() {
    // Arrange
    Mockery mock = new Mockery();
    cinemaTheatreRepository = mock.mock(CinemaTheatreRepository.class);
    final CinemaTheatre cinemaTheatre = new CinemaTheatre();
    cinemaTheatre.setCtAdress("Bulevar oslobodjenja 11");
    cinemaTheatre.setCtDescription("Ovo je opis.");
    cinemaTheatre.setCtName("Bioskop");
    cinemaTheatre.setCtPhone(1234567890);
    cinemaTheatre.setCtStateid("381");
    mock.checking(new Expectations() {

        {
            oneOf(cinemaTheatreRepository).findOne(1);
            will(returnValue(cinemaTheatre));
        }
    });
    CinemaTheatreManager manager = new CinemaTheatreManager(cinemaTheatreRepository);
    // Act
    CinemaTheatreDTO dto = manager.Read(1);
    // Assert
    Assert.assertNotNull(dto);
    Assert.assertEquals(dto.getCtAdress(), cinemaTheatre.getCtAdress());
    Assert.assertEquals(dto.getCtDescription(), cinemaTheatre.getCtDescription());
    Assert.assertEquals(dto.getCtName(), cinemaTheatre.getCtName());
    Assert.assertEquals(dto.getCtPhone(), cinemaTheatre.getCtPhone());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) CinemaTheatreRepository(com.management.repositories.CinemaTheatreRepository) CinemaTheatreDTO(com.management.dto.CinemaTheatreDTO) Mockery(org.jmock.Mockery) CinemaTheatre(com.management.entities.CinemaTheatre) Test(org.junit.Test)

Example 3 with CinemaTheatreDTO

use of com.management.dto.CinemaTheatreDTO in project Internet-Software-Architectures by zivko11.

the class CinemaTheatreManager method ReadAll.

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

Example 4 with CinemaTheatreDTO

use of com.management.dto.CinemaTheatreDTO in project Internet-Software-Architectures by zivko11.

the class CinemaTheatreManager method Read.

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

Example 5 with CinemaTheatreDTO

use of com.management.dto.CinemaTheatreDTO in project Internet-Software-Architectures by zivko11.

the class CinemaTheatreManagerTests method AddingNewCinemaTheatre_ReturnsBoolean.

@Test
public void AddingNewCinemaTheatre_ReturnsBoolean() {
    // Arrange
    cinemaTheatreRepository = new CinemaTheatreRepositoryFake();
    CinemaTheatreDTO dto = new CinemaTheatreDTO();
    dto.setCtAdress("Bulevar oslobodjenja 11");
    dto.setCtDescription("Ovo je opis.");
    dto.setCtName("Bioskop");
    dto.setCtPhone(1234567890);
    CinemaTheatreManager manager = new CinemaTheatreManager(cinemaTheatreRepository);
    // Act and assert
    Assert.assertNotNull(manager);
    Assert.assertTrue(manager.Create(dto));
    CinemaTheatre cinemaTheatre = cinemaTheatreRepository.findOne(0);
    Assert.assertEquals(dto.getCtAdress(), cinemaTheatre.getCtAdress());
    Assert.assertEquals(dto.getCtDescription(), cinemaTheatre.getCtDescription());
    Assert.assertEquals(dto.getCtName(), cinemaTheatre.getCtName());
    Assert.assertEquals(dto.getCtPhone(), cinemaTheatre.getCtPhone());
}
Also used : CinemaTheatreRepositoryFake(com.management.fake.CinemaTheatreRepositoryFake) CinemaTheatreDTO(com.management.dto.CinemaTheatreDTO) CinemaTheatre(com.management.entities.CinemaTheatre) Test(org.junit.Test)

Aggregations

CinemaTheatreDTO (com.management.dto.CinemaTheatreDTO)9 CinemaTheatre (com.management.entities.CinemaTheatre)7 Test (org.junit.Test)7 CinemaTheatreRepository (com.management.repositories.CinemaTheatreRepository)5 Expectations (org.jmock.Expectations)5 Mockery (org.jmock.Mockery)5 CinemaTheatreManager (com.management.managers.CinemaTheatreManager)4 ArrayList (java.util.ArrayList)3 CinemaTheatreRepositoryFake (com.management.fake.CinemaTheatreRepositoryFake)2 ModelMapper (org.modelmapper.ModelMapper)2 List (java.util.List)1