Search in sources :

Example 6 with Props

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

the class PropsManagerTests method AddingNewProps_ReturnsBoolean.

@Test
public void AddingNewProps_ReturnsBoolean() throws IOException {
    // Arrange
    propsRepository = new PropsRepositoryFake();
    PropsDTO dto = new PropsDTO();
    dto.setPropsDeadline(new Date());
    dto.setPropsDesc("Spoderman props description");
    dto.setPropsName("Spoderman props");
    dto.setPropsPrice(300);
    dto.setPropsModified(new Date());
    dto.setPropsUsed(true);
    byte[] byteArray = ((DataBufferByte) ImageIO.read(new File("C:\\Users\\Nikola\\Desktop\\test.png")).getData().getDataBuffer()).getData();
    dto.setPropsImage(byteArray);
    PropsManager manager = new PropsManager(propsRepository);
    // Act and assert
    Assert.assertNotNull(manager);
    Assert.assertTrue(manager.Create(dto));
    Props props = propsRepository.findOne(0);
    Assert.assertEquals(dto.getPropsId(), props.getPropsId());
    Assert.assertEquals(dto.getPropsName(), props.getPropsName());
    Assert.assertEquals(dto.getPropsPrice(), props.getPropsPrice(), 0.1);
    Assert.assertEquals(dto.getPropsDeadline(), props.getPropsDeadline());
    Assert.assertEquals(dto.getPropsModified(), props.getPropsModified());
    Assert.assertEquals(dto.getPropsDesc(), props.getPropsDesc());
    Assert.assertArrayEquals(dto.getPropsImage(), props.getPropsImage());
    Assert.assertEquals(dto.isPropsUsed(), props.isPropsUsed());
}
Also used : PropsDTO(com.management.dto.PropsDTO) PropsRepositoryFake(com.management.fake.PropsRepositoryFake) DataBufferByte(java.awt.image.DataBufferByte) Props(com.management.entities.Props) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 7 with Props

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

the class PropsManagerTests method ReadProps_ReturnsProps.

@Test
public void ReadProps_ReturnsProps() throws IOException {
    // Arrange
    Mockery mock = new Mockery();
    propsRepository = mock.mock(PropsRepository.class);
    final Props props = new Props();
    props.setPropsDeadline(new Date());
    props.setPropsDesc("Spoderman props description");
    props.setPropsName("Spoderman props");
    props.setPropsPrice(300);
    props.setPropsModified(new Date());
    props.setPropsUsed(true);
    String filePath = "C:\\Users\\Nikola\\Desktop\\test.png";
    byte[] byteArray;
    byteArray = ((DataBufferByte) ImageIO.read(new File(filePath)).getData().getDataBuffer()).getData();
    props.setPropsImage(byteArray);
    mock.checking(new Expectations() {

        {
            oneOf(propsRepository).findOne(1);
            will(returnValue(props));
        }
    });
    PropsManager manager = new PropsManager(propsRepository);
    // Act
    PropsDTO dto = manager.Read(1);
    // Assert
    Assert.assertNotNull(dto);
    Assert.assertEquals(dto.getPropsId(), props.getPropsId());
    Assert.assertEquals(dto.getPropsName(), props.getPropsName());
    Assert.assertEquals(dto.getPropsPrice(), props.getPropsPrice(), 0.1);
    Assert.assertEquals(dto.getPropsDeadline(), props.getPropsDeadline());
    Assert.assertEquals(dto.getPropsModified(), props.getPropsModified());
    Assert.assertEquals(dto.getPropsDesc(), props.getPropsDesc());
    Assert.assertArrayEquals(dto.getPropsImage(), props.getPropsImage());
    Assert.assertEquals(dto.isPropsUsed(), props.isPropsUsed());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) PropsDTO(com.management.dto.PropsDTO) PropsRepository(com.management.repositories.PropsRepository) Props(com.management.entities.Props) Mockery(org.jmock.Mockery) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 8 with Props

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

the class PropsManager method Create.

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

Example 9 with Props

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

the class PropsManager method Update.

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

Aggregations

Props (com.management.entities.Props)9 PropsDTO (com.management.dto.PropsDTO)7 File (java.io.File)5 Date (java.util.Date)5 Test (org.junit.Test)5 PropsRepository (com.management.repositories.PropsRepository)4 DataBufferByte (java.awt.image.DataBufferByte)4 Expectations (org.jmock.Expectations)4 Mockery (org.jmock.Mockery)4 ModelMapper (org.modelmapper.ModelMapper)4 ArrayList (java.util.ArrayList)3 PropsManager (com.management.managers.PropsManager)2 PropsRepositoryFake (com.management.fake.PropsRepositoryFake)1 List (java.util.List)1