Search in sources :

Example 1 with PropsRepository

use of com.management.repositories.PropsRepository in project Internet-Software-Architectures by zivko11.

the class PropsControllerTests method ReadAllFanZones_ReturnsOK.

@Test
public void ReadAllFanZones_ReturnsOK() throws IOException {
    // Arrange
    Mockery mock = new Mockery();
    propsRepository = mock.mock(PropsRepository.class);
    final ArrayList<Props> list = new ArrayList<Props>();
    Props props1 = new Props();
    props1.setPropsDeadline(new Date());
    props1.setPropsDesc("Spoderman hat");
    props1.setPropsName("Spoderman");
    props1.setPropsPrice(300);
    props1.setPropsModified(new Date());
    props1.setPropsUsed(true);
    byte[] byteArray = ((DataBufferByte) ImageIO.read(new File("C:\\Users\\Nikola\\Desktop\\test.png")).getData().getDataBuffer()).getData();
    props1.setPropsImage(byteArray);
    Props props2 = new Props();
    props2.setPropsDeadline(new Date());
    props2.setPropsDesc("Captain Murica shield");
    props2.setPropsName("Captain Murica");
    props2.setPropsPrice(500);
    props2.setPropsModified(new Date());
    props2.setPropsUsed(false);
    byteArray = ((DataBufferByte) ImageIO.read(new File("C:\\Users\\Nikola\\Desktop\\9cd.jpg")).getData().getDataBuffer()).getData();
    props2.setPropsImage(byteArray);
    list.add(props1);
    list.add(props2);
    mock.checking(new Expectations() {

        {
            oneOf(propsRepository).findAll();
            will(returnValue(list));
        }
    });
    PropsManager manager = new PropsManager(propsRepository);
    PropsController controller = new PropsController(manager);
    // Act
    ResponseEntity<List<PropsDTO>> response = controller.getProps();
    ArrayList<PropsDTO> dtoList = (ArrayList<PropsDTO>) response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<List<PropsDTO>>(dtoList, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) PropsDTO(com.management.dto.PropsDTO) PropsRepository(com.management.repositories.PropsRepository) ArrayList(java.util.ArrayList) Props(com.management.entities.Props) DataBufferByte(java.awt.image.DataBufferByte) Mockery(org.jmock.Mockery) Date(java.util.Date) PropsManager(com.management.managers.PropsManager) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 2 with PropsRepository

use of com.management.repositories.PropsRepository in project Internet-Software-Architectures by zivko11.

the class PropsControllerTests method DeletingProps_ReturnsOK.

@Test
public void DeletingProps_ReturnsOK() {
    Mockery mock = new Mockery();
    propsRepository = mock.mock(PropsRepository.class);
    // Expectations
    mock.checking(new Expectations() {

        {
            oneOf(propsRepository).delete(1);
        }
    });
    PropsManager manager = new PropsManager(propsRepository);
    // Act and assert
    PropsController controller = new PropsController(manager);
    Assert.assertNotNull(controller);
    Assert.assertEquals(controller.deleteProps(1), new ResponseEntity<PropsDTO>(HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) PropsManager(com.management.managers.PropsManager) PropsDTO(com.management.dto.PropsDTO) PropsRepository(com.management.repositories.PropsRepository) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Example 3 with PropsRepository

use of com.management.repositories.PropsRepository in project Internet-Software-Architectures by zivko11.

the class PropsControllerTests method ReadProps_ReturnsOK.

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

        {
            oneOf(propsRepository).findOne(1);
            will(returnValue(props));
        }
    });
    PropsManager manager = new PropsManager(propsRepository);
    PropsController controller = new PropsController(manager);
    // Act
    ResponseEntity<PropsDTO> response = controller.getProps(1);
    PropsDTO dto = response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<PropsDTO>(dto, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) PropsManager(com.management.managers.PropsManager) PropsDTO(com.management.dto.PropsDTO) PropsRepository(com.management.repositories.PropsRepository) Props(com.management.entities.Props) DataBufferByte(java.awt.image.DataBufferByte) Mockery(org.jmock.Mockery) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 4 with PropsRepository

use of com.management.repositories.PropsRepository in project Internet-Software-Architectures by zivko11.

the class PropsManagerTests method DeletingProps_ReturnsBoolean.

@Test
public void DeletingProps_ReturnsBoolean() {
    // Arrange
    Mockery mock = new Mockery();
    propsRepository = mock.mock(PropsRepository.class);
    // Expectations
    mock.checking(new Expectations() {

        {
            oneOf(propsRepository).delete(1);
        }
    });
    // Act and assert
    PropsManager manager = new PropsManager(propsRepository);
    Assert.assertNotNull(manager);
    Assert.assertTrue(manager.Delete(1));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) PropsRepository(com.management.repositories.PropsRepository) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Example 5 with PropsRepository

use of com.management.repositories.PropsRepository in project Internet-Software-Architectures by zivko11.

the class PropsManagerTests method ReadAllProps_ReturnsAllProps.

@Test
public void ReadAllProps_ReturnsAllProps() throws IOException {
    // Arrange
    Mockery mock = new Mockery();
    propsRepository = mock.mock(PropsRepository.class);
    final ArrayList<Props> list = new ArrayList<Props>();
    Props p1 = new Props();
    p1.setPropsDeadline(new Date());
    p1.setPropsDesc("Spoderman props");
    p1.setPropsName("Spoderman suit");
    p1.setPropsPrice(300);
    p1.setPropsModified(new Date());
    p1.setPropsUsed(true);
    byte[] propsImage = ((DataBufferByte) ImageIO.read(new File("C:\\Users\\Nikola\\Desktop\\test.png")).getData().getDataBuffer()).getData();
    p1.setPropsImage(propsImage);
    Props p2 = new Props();
    p2.setPropsDeadline(new Date());
    p2.setPropsDesc("Captain Murica props");
    p2.setPropsName("Captain Murica suit");
    p2.setPropsPrice(500);
    p2.setPropsModified(new Date());
    p2.setPropsUsed(false);
    byte[] propsImage2 = ((DataBufferByte) ImageIO.read(new File("C:\\Users\\Nikola\\Desktop\\9cd.jpg")).getData().getDataBuffer()).getData();
    p2.setPropsImage(propsImage2);
    list.add(p1);
    list.add(p2);
    mock.checking(new Expectations() {

        {
            oneOf(propsRepository).findAll();
            will(returnValue(list));
        }
    });
    PropsManager manager = new PropsManager(propsRepository);
    // Act
    ArrayList<PropsDTO> dtoList = manager.ReadAll();
    // Assert
    Assert.assertNotNull(dtoList);
    Assert.assertEquals(dtoList.get(0).getPropsId(), list.get(0).getPropsId());
    Assert.assertEquals(dtoList.get(0).getPropsDesc(), list.get(0).getPropsDesc());
    Assert.assertEquals(dtoList.get(0).getPropsName(), list.get(0).getPropsName());
    Assert.assertEquals(dtoList.get(0).getPropsPrice(), list.get(0).getPropsPrice(), 0.1);
    Assert.assertEquals(dtoList.get(0).getPropsDeadline(), list.get(0).getPropsDeadline());
    Assert.assertEquals(dtoList.get(0).getPropsModified(), list.get(0).getPropsModified());
    Assert.assertArrayEquals(dtoList.get(0).getPropsImage(), list.get(0).getPropsImage());
    Assert.assertEquals(dtoList.get(0).isPropsUsed(), list.get(0).isPropsUsed());
    Assert.assertEquals(dtoList.get(1).getPropsId(), list.get(1).getPropsId());
    Assert.assertEquals(dtoList.get(1).getPropsDesc(), list.get(1).getPropsDesc());
    Assert.assertEquals(dtoList.get(1).getPropsName(), list.get(1).getPropsName());
    Assert.assertEquals(dtoList.get(1).getPropsPrice(), list.get(1).getPropsPrice(), 0.1);
    Assert.assertEquals(dtoList.get(1).getPropsDeadline(), list.get(1).getPropsDeadline());
    Assert.assertEquals(dtoList.get(1).getPropsModified(), list.get(1).getPropsModified());
    Assert.assertArrayEquals(dtoList.get(1).getPropsImage(), list.get(1).getPropsImage());
    Assert.assertEquals(dtoList.get(1).isPropsUsed(), list.get(1).isPropsUsed());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) PropsDTO(com.management.dto.PropsDTO) PropsRepository(com.management.repositories.PropsRepository) ArrayList(java.util.ArrayList) Props(com.management.entities.Props) DataBufferByte(java.awt.image.DataBufferByte) Mockery(org.jmock.Mockery) Date(java.util.Date) File(java.io.File) Test(org.junit.Test)

Aggregations

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