Search in sources :

Example 1 with PerformanceRepository

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

the class PerformanceControllerTests method ReadPerformance_ReturnsOK.

@Test
public void ReadPerformance_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    performanceRepository = mock.mock(PerformanceRepository.class);
    final Performance per = new Performance();
    per.setPerCreationDate(new Date());
    per.setPerDescription("Neki opis.");
    per.setPerDirector("Nikola Stojanovic");
    per.setPerDuration(11);
    per.setPerGenre("Komedija");
    per.setPerPoster(new byte[] { 121 });
    per.setPerPrice(100);
    per.setPerRank(0);
    per.setPerType('M');
    mock.checking(new Expectations() {

        {
            oneOf(performanceRepository).findOne(1);
            will(returnValue(per));
        }
    });
    PerformanceManager manager = new PerformanceManager(performanceRepository);
    PerformanceController controller = new PerformanceController(manager);
    // Act
    ResponseEntity<PerformanceDTO> response = controller.getPerformance(1);
    PerformanceDTO dto = response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<PerformanceDTO>(dto, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : PerformanceRepository(com.management.repositories.PerformanceRepository) Expectations(org.jmock.Expectations) PerformanceManager(com.management.managers.PerformanceManager) Performance(com.management.entities.Performance) Mockery(org.jmock.Mockery) Date(java.util.Date) PerformanceDTO(com.management.dto.PerformanceDTO) Test(org.junit.Test)

Example 2 with PerformanceRepository

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

the class PerformanceManagerTests method DeletingPerformance_ReturnsBoolean.

@Test
public void DeletingPerformance_ReturnsBoolean() {
    // Arrange
    Mockery mock = new Mockery();
    performanceRepository = mock.mock(PerformanceRepository.class);
    // expectations
    mock.checking(new Expectations() {

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

Example 3 with PerformanceRepository

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

the class PerformanceManagerTests method ReadPerformance_ReturnsPerformance.

@Test
public void ReadPerformance_ReturnsPerformance() {
    // Arrange
    Mockery mock = new Mockery();
    performanceRepository = mock.mock(PerformanceRepository.class);
    final Performance per = new Performance();
    per.setPerCreationDate(new Date());
    per.setPerDescription("Neki opis.");
    per.setPerDirector("Nikola Stojanovic");
    per.setPerDuration(11);
    per.setPerGenre("Komedija");
    per.setPerPoster(new byte[] { 121 });
    per.setPerPrice(100);
    per.setPerRank(0);
    per.setPerType('M');
    mock.checking(new Expectations() {

        {
            oneOf(performanceRepository).findOne(1);
            will(returnValue(per));
        }
    });
    PerformanceManager manager = new PerformanceManager(performanceRepository);
    // Act
    PerformanceDTO dto = manager.Read(1);
    // Assert
    Assert.assertNotNull(dto);
    Assert.assertEquals(dto.getPerId(), per.getPerId());
    Assert.assertEquals(per.getPerDescription(), dto.getPerDescription());
    Assert.assertEquals(per.getPerDirector(), dto.getPerDirector());
    Assert.assertEquals(per.getPerDuration(), dto.getPerDuration());
    Assert.assertEquals(per.getPerGenre(), dto.getPerGenre());
    Assert.assertEquals((int) per.getPerPrice(), (int) dto.getPerPrice());
    Assert.assertEquals(per.getPerRank(), dto.getPerRank());
    Assert.assertEquals(per.getPerType(), dto.getPerType());
    mock.assertIsSatisfied();
}
Also used : PerformanceRepository(com.management.repositories.PerformanceRepository) Expectations(org.jmock.Expectations) Performance(com.management.entities.Performance) Mockery(org.jmock.Mockery) Date(java.util.Date) PerformanceDTO(com.management.dto.PerformanceDTO) Test(org.junit.Test)

Example 4 with PerformanceRepository

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

the class PerformanceManagerTests method ReadAllPerformances_ReturnsAllPerformances.

@Test
public void ReadAllPerformances_ReturnsAllPerformances() {
    // Arrange
    Mockery mock = new Mockery();
    performanceRepository = mock.mock(PerformanceRepository.class);
    final ArrayList<Performance> list = new ArrayList<Performance>();
    Performance per1 = new Performance();
    per1.setPerCreationDate(new Date());
    per1.setPerDescription("Neki opis.");
    per1.setPerDirector("Zivko Stanisic");
    per1.setPerDuration(11);
    per1.setPerGenre("Akcija");
    per1.setPerPoster(new byte[] { 121 });
    per1.setPerPrice(100);
    per1.setPerRank(10);
    per1.setPerType('M');
    Performance per2 = new Performance();
    per2.setPerCreationDate(new Date());
    per2.setPerDescription("Opet opis.");
    per2.setPerDirector("Nikola Stojanovic");
    per2.setPerDuration(13);
    per2.setPerGenre("Drama");
    per2.setPerPoster(new byte[] { 121 });
    per2.setPerPrice(0);
    per2.setPerRank(1);
    per2.setPerType('M');
    list.add(per1);
    list.add(per2);
    mock.checking(new Expectations() {

        {
            oneOf(performanceRepository).findAll();
            will(returnValue(list));
        }
    });
    PerformanceManager manager = new PerformanceManager(performanceRepository);
    // Act
    ArrayList<PerformanceDTO> listDTO = manager.ReadAll();
    // Assert
    Assert.assertNotNull(listDTO);
    Assert.assertEquals(listDTO.get(0).getPerId(), list.get(0).getPerId());
    Assert.assertEquals(listDTO.get(0).getPerDescription(), list.get(0).getPerDescription());
    Assert.assertEquals(listDTO.get(0).getPerDirector(), list.get(0).getPerDirector());
    Assert.assertEquals(listDTO.get(0).getPerDuration(), list.get(0).getPerDuration());
    Assert.assertEquals(listDTO.get(0).getPerGenre(), list.get(0).getPerGenre());
    Assert.assertEquals((int) listDTO.get(0).getPerPrice(), (int) list.get(0).getPerPrice());
    Assert.assertEquals(listDTO.get(0).getPerRank(), list.get(0).getPerRank());
    Assert.assertEquals(listDTO.get(0).getPerType(), list.get(0).getPerType());
    Assert.assertEquals(listDTO.get(1).getPerId(), list.get(1).getPerId());
    Assert.assertEquals(listDTO.get(1).getPerDescription(), list.get(1).getPerDescription());
    Assert.assertEquals(listDTO.get(1).getPerDirector(), list.get(1).getPerDirector());
    Assert.assertEquals(listDTO.get(1).getPerDuration(), list.get(1).getPerDuration());
    Assert.assertEquals(listDTO.get(1).getPerGenre(), list.get(1).getPerGenre());
    Assert.assertEquals((int) listDTO.get(1).getPerPrice(), (int) list.get(1).getPerPrice());
    Assert.assertEquals(listDTO.get(1).getPerRank(), list.get(1).getPerRank());
    Assert.assertEquals(listDTO.get(1).getPerType(), list.get(1).getPerType());
    mock.assertIsSatisfied();
}
Also used : PerformanceRepository(com.management.repositories.PerformanceRepository) Expectations(org.jmock.Expectations) ArrayList(java.util.ArrayList) Performance(com.management.entities.Performance) Mockery(org.jmock.Mockery) Date(java.util.Date) PerformanceDTO(com.management.dto.PerformanceDTO) Test(org.junit.Test)

Example 5 with PerformanceRepository

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

the class PerformanceControllerTests method DeletingPerformance_ReturnsOK.

@Test
public void DeletingPerformance_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    performanceRepository = mock.mock(PerformanceRepository.class);
    // expectations
    mock.checking(new Expectations() {

        {
            oneOf(performanceRepository).delete(1);
        }
    });
    // Act and assert
    PerformanceManager manager = new PerformanceManager(performanceRepository);
    PerformanceController controller = new PerformanceController(manager);
    Assert.assertNotNull(controller);
    Assert.assertEquals(controller.deletePerformance(1), new ResponseEntity<PerformanceDTO>(HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : PerformanceRepository(com.management.repositories.PerformanceRepository) Expectations(org.jmock.Expectations) PerformanceManager(com.management.managers.PerformanceManager) Mockery(org.jmock.Mockery) PerformanceDTO(com.management.dto.PerformanceDTO) Test(org.junit.Test)

Aggregations

PerformanceRepository (com.management.repositories.PerformanceRepository)6 Expectations (org.jmock.Expectations)6 Mockery (org.jmock.Mockery)6 Test (org.junit.Test)6 PerformanceDTO (com.management.dto.PerformanceDTO)5 Performance (com.management.entities.Performance)4 Date (java.util.Date)4 PerformanceManager (com.management.managers.PerformanceManager)3 ArrayList (java.util.ArrayList)2 List (java.util.List)1