Search in sources :

Example 6 with FanZone

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

the class FanZoneManager method ReadAll.

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

Example 7 with FanZone

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

the class FanZoneManager method Create.

public boolean Create(FanZoneDTO dto) {
    ModelMapper mapper = new ModelMapper();
    FanZone fanzone = new FanZone();
    try {
        fanzone = mapper.map(dto, FanZone.class);
        fanZoneRepository.save(fanzone);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : FanZone(com.management.entities.FanZone) ModelMapper(org.modelmapper.ModelMapper)

Example 8 with FanZone

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

the class FanZoneManager method Update.

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

Example 9 with FanZone

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

the class FanZoneControllerTests method ReadAllFanZones_ReturnsOK.

@Test
public void ReadAllFanZones_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    fanZoneRepository = mock.mock(FanZoneRepository.class);
    final ArrayList<FanZone> list = new ArrayList<FanZone>();
    FanZone fz1 = new FanZone();
    fz1.setFanZoneName("Spoderman fan zone");
    FanZone fz2 = new FanZone();
    fz2.setFanZoneName("Captain Murica fan zone");
    list.add(fz1);
    list.add(fz2);
    mock.checking(new Expectations() {

        {
            oneOf(fanZoneRepository).findAll();
            will(returnValue(list));
        }
    });
    FanZoneManager manager = new FanZoneManager(fanZoneRepository);
    FanZoneController controller = new FanZoneController(manager);
    // Act
    ResponseEntity<List<FanZoneDTO>> response = controller.getFanZones();
    ArrayList<FanZoneDTO> dtoList = (ArrayList<FanZoneDTO>) response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<List<FanZoneDTO>>(dtoList, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) FanZoneManager(com.management.managers.FanZoneManager) ArrayList(java.util.ArrayList) FanZoneRepository(com.management.repositories.FanZoneRepository) ArrayList(java.util.ArrayList) List(java.util.List) FanZoneDTO(com.management.dto.FanZoneDTO) Mockery(org.jmock.Mockery) FanZone(com.management.entities.FanZone) Test(org.junit.Test)

Aggregations

FanZone (com.management.entities.FanZone)9 FanZoneDTO (com.management.dto.FanZoneDTO)7 Test (org.junit.Test)5 FanZoneRepository (com.management.repositories.FanZoneRepository)4 Expectations (org.jmock.Expectations)4 Mockery (org.jmock.Mockery)4 ModelMapper (org.modelmapper.ModelMapper)4 ArrayList (java.util.ArrayList)3 FanZoneManager (com.management.managers.FanZoneManager)2 FanZoneRepositoryFake (com.management.fake.FanZoneRepositoryFake)1 List (java.util.List)1