Search in sources :

Example 6 with PerformanceRepository

use of com.management.repositories.PerformanceRepository 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

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