Search in sources :

Example 1 with Hall

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

the class HallControllerTests method ReadHall_ReturnsOK.

@Test
public void ReadHall_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    hallRepository = mock.mock(HallRepository.class);
    final Hall hall = new Hall();
    hall.setHallName("A1");
    mock.checking(new Expectations() {

        {
            oneOf(hallRepository).findOne(1);
            will(returnValue(hall));
        }
    });
    HallManager manager = new HallManager(hallRepository);
    HallController controller = new HallController(manager);
    // Act
    ResponseEntity<HallDTO> response = controller.getHall(1);
    HallDTO dto = response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<HallDTO>(dto, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) HallManager(com.management.managers.HallManager) Hall(com.management.entities.Hall) HallDTO(com.management.dto.HallDTO) Mockery(org.jmock.Mockery) HallRepository(com.management.repositories.HallRepository) Test(org.junit.Test)

Example 2 with Hall

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

the class HallControllerTests method ReadAllHalls_ReturnsOK.

@Test
public void ReadAllHalls_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    hallRepository = mock.mock(HallRepository.class);
    final ArrayList<Hall> list = new ArrayList<Hall>();
    Hall hall1 = new Hall();
    hall1.setHallName("A1");
    Hall hall2 = new Hall();
    hall2.setHallName("A2");
    list.add(hall1);
    list.add(hall2);
    mock.checking(new Expectations() {

        {
            oneOf(hallRepository).findAll();
            will(returnValue(list));
        }
    });
    HallManager manager = new HallManager(hallRepository);
    HallController controller = new HallController(manager);
    // Act
    ResponseEntity<List<HallDTO>> response = controller.getHalls();
    ArrayList<HallDTO> listDTO = (ArrayList<HallDTO>) response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<List<HallDTO>>(listDTO, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) HallManager(com.management.managers.HallManager) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Hall(com.management.entities.Hall) HallDTO(com.management.dto.HallDTO) Mockery(org.jmock.Mockery) HallRepository(com.management.repositories.HallRepository) Test(org.junit.Test)

Example 3 with Hall

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

the class HallManagerTests method AddingNewHall_ReturnsBoolean.

@Test
public void AddingNewHall_ReturnsBoolean() {
    // Arrange
    hallRepository = new HallRepositoryFake();
    HallDTO dto = new HallDTO();
    dto.setHallName("A1");
    HallManager manager = new HallManager(hallRepository);
    // Act and assert
    Assert.assertNotNull(manager);
    Assert.assertTrue(manager.Create(dto));
    Hall hall = hallRepository.findOne(0);
    Assert.assertEquals(dto.getHallId(), hall.getHallId());
    Assert.assertEquals(dto.getHallName(), hall.getHallName());
}
Also used : HallRepositoryFake(com.management.fake.HallRepositoryFake) Hall(com.management.entities.Hall) HallDTO(com.management.dto.HallDTO) Test(org.junit.Test)

Example 4 with Hall

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

the class HallManager method Read.

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

Example 5 with Hall

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

the class HallManager method Update.

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

Aggregations

Hall (com.management.entities.Hall)9 HallDTO (com.management.dto.HallDTO)7 Test (org.junit.Test)5 HallRepository (com.management.repositories.HallRepository)4 Expectations (org.jmock.Expectations)4 Mockery (org.jmock.Mockery)4 ModelMapper (org.modelmapper.ModelMapper)4 ArrayList (java.util.ArrayList)3 HallManager (com.management.managers.HallManager)2 HallRepositoryFake (com.management.fake.HallRepositoryFake)1 List (java.util.List)1