Search in sources :

Example 1 with PerformanceManager

use of com.management.managers.PerformanceManager in project Internet-Software-Architectures by zivko11.

the class PerformanceControllerTests method AddingNewPerformance_ReturnsOK.

@Test
public void AddingNewPerformance_ReturnsOK() {
    // Arrange
    performanceRepository = new PerformanceRepositoryFake();
    PerformanceDTO dto = new PerformanceDTO();
    dto.setPerCreationDate(new Date());
    dto.setPerDescription("Neki opis.");
    dto.setPerDirector("Nikola Stojanovic");
    dto.setPerDuration(11);
    dto.setPerGenre("Komedija");
    dto.setPerPoster(new byte[] { 121 });
    dto.setPerPrice(100);
    dto.setPerRank(0);
    dto.setPerType('M');
    PerformanceManager manager = new PerformanceManager(performanceRepository);
    PerformanceController controller = new PerformanceController(manager);
    // Act and assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(controller.addPerformance(dto), new ResponseEntity<PerformanceDTO>(dto, HttpStatus.OK));
}
Also used : PerformanceRepositoryFake(com.management.fake.PerformanceRepositoryFake) PerformanceManager(com.management.managers.PerformanceManager) Date(java.util.Date) PerformanceDTO(com.management.dto.PerformanceDTO) Test(org.junit.Test)

Example 2 with PerformanceManager

use of com.management.managers.PerformanceManager 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 3 with PerformanceManager

use of com.management.managers.PerformanceManager 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)

Example 4 with PerformanceManager

use of com.management.managers.PerformanceManager in project Internet-Software-Architectures by zivko11.

the class PerformanceControllerTests method ReadAllPerformances_ReturnsOK.

@Test
public void ReadAllPerformances_ReturnsOK() {
    // 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);
    PerformanceController controller = new PerformanceController(manager);
    // Act
    ResponseEntity<List<PerformanceDTO>> response = controller.getPerformances();
    ArrayList<PerformanceDTO> listDTO = (ArrayList<PerformanceDTO>) response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<List<PerformanceDTO>>(listDTO, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) ArrayList(java.util.ArrayList) Mockery(org.jmock.Mockery) Date(java.util.Date) PerformanceDTO(com.management.dto.PerformanceDTO) PerformanceRepository(com.management.repositories.PerformanceRepository) PerformanceManager(com.management.managers.PerformanceManager) ArrayList(java.util.ArrayList) List(java.util.List) Performance(com.management.entities.Performance) Test(org.junit.Test)

Aggregations

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