Search in sources :

Example 1 with ActorDTO

use of com.management.dto.ActorDTO in project Internet-Software-Architectures by zivko11.

the class ActorControllerTests method DeletingActor_ReturnsOK.

@Test
public void DeletingActor_ReturnsOK() {
    Mockery mock = new Mockery();
    actorRepository = mock.mock(ActorRepository.class);
    // expectations
    mock.checking(new Expectations() {

        {
            oneOf(actorRepository).delete(1);
        }
    });
    ActorManager manager = new ActorManager(actorRepository);
    // Act and assert
    ActorController controller = new ActorController(manager);
    Assert.assertNotNull(controller);
    Assert.assertEquals(controller.deleteActor(1), new ResponseEntity<ActorDTO>(HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) ActorDTO(com.management.dto.ActorDTO) Mockery(org.jmock.Mockery) ActorRepository(com.management.repositories.ActorRepository) ActorManager(com.management.managers.ActorManager) Test(org.junit.Test)

Example 2 with ActorDTO

use of com.management.dto.ActorDTO in project Internet-Software-Architectures by zivko11.

the class ActorControllerTests method ReadActor_ReturnsOK.

@Test
public void ReadActor_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    actorRepository = mock.mock(ActorRepository.class);
    final Actor actor = new Actor();
    actor.setAcName("Zivko");
    actor.setAcSurname("Stanisic");
    mock.checking(new Expectations() {

        {
            oneOf(actorRepository).findOne(1);
            will(returnValue(actor));
        }
    });
    ActorManager manager = new ActorManager(actorRepository);
    ActorController controller = new ActorController(manager);
    // Act
    ResponseEntity<ActorDTO> response = controller.getActor(1);
    ActorDTO dto = response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<ActorDTO>(dto, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) ActorDTO(com.management.dto.ActorDTO) Actor(com.management.entities.Actor) Mockery(org.jmock.Mockery) ActorRepository(com.management.repositories.ActorRepository) ActorManager(com.management.managers.ActorManager) Test(org.junit.Test)

Example 3 with ActorDTO

use of com.management.dto.ActorDTO in project Internet-Software-Architectures by zivko11.

the class ActorControllerTests method AddingNewActor_ReturnsOK.

@Test
public void AddingNewActor_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    actorRepository = new ActorRepositoryFake();
    ActorDTO dto = new ActorDTO();
    dto.setAcName("Zivko");
    dto.setAcSurname("Stanisic");
    ActorManager manager = new ActorManager(actorRepository);
    ActorController controller = new ActorController(manager);
    // Act and assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(controller.addActor(dto), new ResponseEntity<ActorDTO>(dto, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : ActorRepositoryFake(com.management.fake.ActorRepositoryFake) ActorDTO(com.management.dto.ActorDTO) Mockery(org.jmock.Mockery) ActorManager(com.management.managers.ActorManager) Test(org.junit.Test)

Example 4 with ActorDTO

use of com.management.dto.ActorDTO in project Internet-Software-Architectures by zivko11.

the class ActorManagerTests method AddingNewActor_ReturnsBoolean.

@Test
public void AddingNewActor_ReturnsBoolean() {
    // Arrange
    Mockery mock = new Mockery();
    actorRepository = new ActorRepositoryFake();
    ActorDTO dto = new ActorDTO();
    dto.setAcName("Zivko");
    dto.setAcSurname("Stanisic");
    ActorManager manager = new ActorManager(actorRepository);
    // Act and assert
    Assert.assertNotNull(manager);
    Assert.assertTrue(manager.Create(dto));
    Actor actor = actorRepository.findOne(0);
    Assert.assertEquals(dto.getAcName(), actor.getAcName());
    Assert.assertEquals(dto.getAcSurname(), actor.getAcSurname());
    mock.assertIsSatisfied();
}
Also used : ActorRepositoryFake(com.management.fake.ActorRepositoryFake) ActorDTO(com.management.dto.ActorDTO) Actor(com.management.entities.Actor) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Example 5 with ActorDTO

use of com.management.dto.ActorDTO in project Internet-Software-Architectures by zivko11.

the class ActorManagerTests method ReadAllActors_ReturnsAllActors.

@Test
public void ReadAllActors_ReturnsAllActors() {
    // Arrange
    Mockery mock = new Mockery();
    actorRepository = mock.mock(ActorRepository.class);
    final ArrayList<Actor> list = new ArrayList<Actor>();
    Actor actor1 = new Actor();
    actor1.setAcName("Zivko");
    actor1.setAcSurname("Stanisic");
    Actor actor2 = new Actor();
    actor2.setAcName("Nikola");
    actor2.setAcSurname("Stojanovic");
    list.add(actor1);
    list.add(actor2);
    mock.checking(new Expectations() {

        {
            oneOf(actorRepository).findAll();
            will(returnValue(list));
        }
    });
    ActorManager manager = new ActorManager(actorRepository);
    // Act
    ArrayList<ActorDTO> listDTO = manager.ReadAll();
    // Assert
    Assert.assertNotNull(listDTO);
    Assert.assertEquals(listDTO.get(0).getAcName(), list.get(0).getAcName());
    Assert.assertEquals(listDTO.get(0).getAcSurname(), list.get(0).getAcSurname());
    Assert.assertEquals(listDTO.get(1).getAcName(), list.get(1).getAcName());
    Assert.assertEquals(listDTO.get(1).getAcSurname(), list.get(1).getAcSurname());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) ActorDTO(com.management.dto.ActorDTO) Actor(com.management.entities.Actor) ArrayList(java.util.ArrayList) Mockery(org.jmock.Mockery) ActorRepository(com.management.repositories.ActorRepository) Test(org.junit.Test)

Aggregations

ActorDTO (com.management.dto.ActorDTO)9 Actor (com.management.entities.Actor)7 Mockery (org.jmock.Mockery)7 Test (org.junit.Test)7 ActorRepository (com.management.repositories.ActorRepository)5 Expectations (org.jmock.Expectations)5 ActorManager (com.management.managers.ActorManager)4 ArrayList (java.util.ArrayList)3 ActorRepositoryFake (com.management.fake.ActorRepositoryFake)2 ModelMapper (org.modelmapper.ModelMapper)2 List (java.util.List)1