Search in sources :

Example 1 with FanZone

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

the class FanZoneControllerTests method ReadFanZone_ReturnsOK.

@Test
public void ReadFanZone_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    fanZoneRepository = mock.mock(FanZoneRepository.class);
    final FanZone fz = new FanZone();
    fz.setFanZoneName("Spoderman fan zone");
    mock.checking(new Expectations() {

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

Example 2 with FanZone

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

the class FanZoneManagerTests method AddingNewFanZone_ReturnsBoolean.

@Test
public void AddingNewFanZone_ReturnsBoolean() {
    // Arrange
    fanZoneRepository = new FanZoneRepositoryFake();
    FanZoneDTO dto = new FanZoneDTO();
    dto.setFanZoneName("Spoderman Fan Zone");
    FanZoneManager manager = new FanZoneManager(fanZoneRepository);
    // Act and assert
    Assert.assertNotNull(manager);
    Assert.assertTrue(manager.Create(dto));
    FanZone fz = fanZoneRepository.findOne(0);
    Assert.assertEquals(dto.getFanZoneId(), fz.getFanZoneId());
    Assert.assertEquals(dto.getFanZoneName(), dto.getFanZoneName());
}
Also used : FanZoneRepositoryFake(com.management.fake.FanZoneRepositoryFake) FanZoneDTO(com.management.dto.FanZoneDTO) FanZone(com.management.entities.FanZone) Test(org.junit.Test)

Example 3 with FanZone

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

the class FanZoneManagerTests method ReadAllFanZones_ReturnsAllFanZones.

@Test
public void ReadAllFanZones_ReturnsAllFanZones() {
    // 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 Amurica fan zone");
    list.add(fz1);
    list.add(fz2);
    mock.checking(new Expectations() {

        {
            oneOf(fanZoneRepository).findAll();
            will(returnValue(list));
        }
    });
    FanZoneManager manager = new FanZoneManager(fanZoneRepository);
    // Act
    ArrayList<FanZoneDTO> dtoList = manager.ReadAll();
    // Assert
    Assert.assertNotNull(dtoList);
    Assert.assertEquals(dtoList.get(0).getFanZoneId(), list.get(0).getFanZoneId());
    Assert.assertEquals(dtoList.get(0).getFanZoneName(), list.get(0).getFanZoneName());
    Assert.assertEquals(dtoList.get(1).getFanZoneId(), list.get(1).getFanZoneId());
    Assert.assertEquals(dtoList.get(1).getFanZoneName(), list.get(1).getFanZoneName());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) ArrayList(java.util.ArrayList) FanZoneRepository(com.management.repositories.FanZoneRepository) FanZoneDTO(com.management.dto.FanZoneDTO) Mockery(org.jmock.Mockery) FanZone(com.management.entities.FanZone) Test(org.junit.Test)

Example 4 with FanZone

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

the class FanZoneManager method Read.

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

Example 5 with FanZone

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

the class FanZoneManagerTests method ReadFanZone_ReturnsFanZone.

@Test
public void ReadFanZone_ReturnsFanZone() {
    // Arrange
    Mockery mock = new Mockery();
    fanZoneRepository = mock.mock(FanZoneRepository.class);
    final FanZone fz = new FanZone();
    fz.setFanZoneName("Spoderman Fan Zone");
    mock.checking(new Expectations() {

        {
            oneOf(fanZoneRepository).findOne(1);
            will(returnValue(fz));
        }
    });
    FanZoneManager manager = new FanZoneManager(fanZoneRepository);
    // Act
    FanZoneDTO dto = manager.Read(1);
    // Assert
    Assert.assertNotNull(dto);
    Assert.assertEquals(dto.getFanZoneName(), fz.getFanZoneName());
}
Also used : Expectations(org.jmock.Expectations) FanZoneRepository(com.management.repositories.FanZoneRepository) 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