Search in sources :

Example 6 with FriendslistDTO

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

the class FriendsListManager method Read.

public FriendslistDTO Read(int id) {
    ModelMapper mapper = new ModelMapper();
    FriendslistDTO dto;
    try {
        Friendslist list = friendsListRepository.findOne(id);
        dto = mapper.map(list, FriendslistDTO.class);
    } catch (Exception exc) {
        exc.printStackTrace();
        return null;
    }
    return dto;
}
Also used : FriendslistDTO(com.management.dto.FriendslistDTO) Friendslist(com.management.entities.Friendslist) ModelMapper(org.modelmapper.ModelMapper)

Example 7 with FriendslistDTO

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

the class FriendsListManager method ReadAll.

public ArrayList<FriendslistDTO> ReadAll() {
    ModelMapper mapper = new ModelMapper();
    ArrayList<Friendslist> listEntities = (ArrayList<Friendslist>) friendsListRepository.findAll();
    ArrayList<FriendslistDTO> listDTO = new ArrayList<FriendslistDTO>();
    for (Friendslist tmp : listEntities) {
        try {
            FriendslistDTO dto = mapper.map(tmp, FriendslistDTO.class);
            listDTO.add(dto);
        } catch (Exception exc) {
            exc.printStackTrace();
            return null;
        }
    }
    return listDTO;
}
Also used : FriendslistDTO(com.management.dto.FriendslistDTO) ArrayList(java.util.ArrayList) Friendslist(com.management.entities.Friendslist) ModelMapper(org.modelmapper.ModelMapper)

Example 8 with FriendslistDTO

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

the class FriendsListControllerTests method DeletingFriendsList_ReturnsOK.

@Test
public void DeletingFriendsList_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    friendsListRepository = mock.mock(FriendsListRepository.class);
    // expectations
    mock.checking(new Expectations() {

        {
            oneOf(friendsListRepository).delete(1);
        }
    });
    // Act and assert
    FriendsListManager manager = new FriendsListManager(friendsListRepository);
    FriendsListController controller = new FriendsListController(manager);
    Assert.assertNotNull(controller);
    Assert.assertEquals(controller.deleteFriendsList(1), new ResponseEntity<FriendslistDTO>(HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) FriendslistDTO(com.management.dto.FriendslistDTO) FriendsListRepository(com.management.repositories.FriendsListRepository) FriendsListManager(com.management.managers.FriendsListManager) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Example 9 with FriendslistDTO

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

the class FriendsListControllerTests method ReadFriendsList_ReturnsOK.

@Test
public void ReadFriendsList_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    friendsListRepository = mock.mock(FriendsListRepository.class);
    final Friendslist list = new Friendslist();
    list.setFriendsStatus('P');
    mock.checking(new Expectations() {

        {
            oneOf(friendsListRepository).findOne(1);
            will(returnValue(list));
        }
    });
    FriendsListManager manager = new FriendsListManager(friendsListRepository);
    FriendsListController controller = new FriendsListController(manager);
    // Act
    ResponseEntity<FriendslistDTO> response = controller.getFriendslist(1);
    FriendslistDTO dto = response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<FriendslistDTO>(dto, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) FriendslistDTO(com.management.dto.FriendslistDTO) FriendsListRepository(com.management.repositories.FriendsListRepository) FriendsListManager(com.management.managers.FriendsListManager) Mockery(org.jmock.Mockery) Friendslist(com.management.entities.Friendslist) Test(org.junit.Test)

Aggregations

FriendslistDTO (com.management.dto.FriendslistDTO)9 Friendslist (com.management.entities.Friendslist)7 Test (org.junit.Test)7 FriendsListRepository (com.management.repositories.FriendsListRepository)5 Expectations (org.jmock.Expectations)5 Mockery (org.jmock.Mockery)5 FriendsListManager (com.management.managers.FriendsListManager)4 ArrayList (java.util.ArrayList)3 FriendsListRepositoryFake (com.management.fake.FriendsListRepositoryFake)2 ModelMapper (org.modelmapper.ModelMapper)2 List (java.util.List)1