Search in sources :

Example 1 with User

use of com.management.entities.User in project Internet-Software-Architectures by zivko11.

the class UserManagerTest method ReadAllUsers_ReturnsAllUsers.

@Test
public void ReadAllUsers_ReturnsAllUsers() {
    // Arrange
    Mockery mock = new Mockery();
    userRepository = mock.mock(UserRepository.class);
    final ArrayList<User> list = new ArrayList<User>();
    User user1 = new User();
    user1.setUserId(1);
    user1.setUserActive(true);
    user1.setUserName("Pero");
    user1.setUserSurname("Peric");
    user1.setUserAdmin('O');
    user1.setUserCity("Novi Sad");
    user1.setUserCreationDate(new Date());
    user1.setUserEmail("pero@gmail.com");
    user1.setUserPassword("123");
    user1.setUserRank(0);
    user1.setUserPhone(123456);
    user1.setUserStateid("381");
    User user2 = new User();
    user2.setUserId(2);
    user2.setUserActive(false);
    user2.setUserName("Djuro");
    user2.setUserSurname("Djuric");
    user2.setUserAdmin('O');
    user2.setUserCity("Sombor");
    user2.setUserCreationDate(new Date());
    user2.setUserEmail("djuro@gmail.com");
    user2.setUserPassword("321");
    user2.setUserRank(1);
    user2.setUserPhone(654321);
    user2.setUserStateid("386");
    list.add(user1);
    list.add(user2);
    mock.checking(new Expectations() {

        {
            oneOf(userRepository).findAll();
            will(returnValue(list));
        }
    });
    UserManager manager = new UserManager(userRepository);
    // Act
    ArrayList<UserDTO> listDTO = manager.ReadAll();
    // Assert
    Assert.assertNotNull(listDTO);
    Assert.assertEquals(listDTO.get(0).getUserCity(), list.get(0).getUserCity());
    Assert.assertEquals(listDTO.get(0).getUserAdmin(), list.get(0).getUserAdmin());
    Assert.assertEquals(listDTO.get(0).getUserRank(), list.get(0).getUserRank());
    Assert.assertEquals(listDTO.get(0).getUserCity(), list.get(0).getUserCity());
    Assert.assertEquals(listDTO.get(0).getUserEmail(), list.get(0).getUserEmail());
    Assert.assertEquals(listDTO.get(0).getUserName(), list.get(0).getUserName());
    Assert.assertEquals(listDTO.get(0).getUserPassword(), list.get(0).getUserPassword());
    Assert.assertEquals(listDTO.get(0).getUserSurname(), list.get(0).getUserSurname());
    Assert.assertEquals(listDTO.get(0).getUserAdmin(), list.get(0).getUserAdmin());
    Assert.assertEquals(listDTO.get(0).getUserCreationDate(), list.get(0).getUserCreationDate());
    Assert.assertEquals(listDTO.get(0).getUserPhone(), list.get(0).getUserPhone());
    Assert.assertEquals(listDTO.get(0).getUserStateid(), list.get(0).getUserStateid());
    Assert.assertEquals(listDTO.get(1).getUserCity(), list.get(1).getUserCity());
    Assert.assertEquals(listDTO.get(1).getUserAdmin(), list.get(1).getUserAdmin());
    Assert.assertEquals(listDTO.get(1).getUserRank(), list.get(1).getUserRank());
    Assert.assertEquals(listDTO.get(1).getUserCity(), list.get(1).getUserCity());
    Assert.assertEquals(listDTO.get(1).getUserEmail(), list.get(1).getUserEmail());
    Assert.assertEquals(listDTO.get(1).getUserName(), list.get(1).getUserName());
    Assert.assertEquals(listDTO.get(1).getUserPassword(), list.get(1).getUserPassword());
    Assert.assertEquals(listDTO.get(1).getUserSurname(), list.get(1).getUserSurname());
    Assert.assertEquals(listDTO.get(1).getUserAdmin(), list.get(1).getUserAdmin());
    Assert.assertEquals(listDTO.get(1).getUserCreationDate(), list.get(1).getUserCreationDate());
    Assert.assertEquals(listDTO.get(1).getUserPhone(), list.get(1).getUserPhone());
    Assert.assertEquals(listDTO.get(1).getUserStateid(), list.get(1).getUserStateid());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) UserRepository(com.management.repositories.UserRepository) User(com.management.entities.User) UserDTO(com.management.dto.UserDTO) ArrayList(java.util.ArrayList) Mockery(org.jmock.Mockery) Date(java.util.Date) Test(org.junit.Test)

Example 2 with User

use of com.management.entities.User in project Internet-Software-Architectures by zivko11.

the class UserManager method ReadAll.

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

Example 3 with User

use of com.management.entities.User in project Internet-Software-Architectures by zivko11.

the class UserManager method Create.

public boolean Create(UserDTO dto) {
    ModelMapper mapper = new ModelMapper();
    User user;
    try {
        user = mapper.map(dto, User.class);
    } catch (Exception exc) {
        exc.printStackTrace();
        return false;
    }
    if (token == null) {
        return false;
    }
    Date expiration = new Date();
    expiration.setTime(expiration.getTime() + (24 * 60 * 60 * 1000));
    user.setToken(token);
    user.setExpiration(expiration);
    userRepository.save(user);
    return true;
}
Also used : User(com.management.entities.User) Date(java.util.Date) ModelMapper(org.modelmapper.ModelMapper)

Example 4 with User

use of com.management.entities.User in project Internet-Software-Architectures by zivko11.

the class UserManager method Update.

public boolean Update(UserDTO dto) {
    ModelMapper mapper = new ModelMapper();
    User tmp;
    try {
        tmp = mapper.map(dto, User.class);
    } catch (Exception exc) {
        exc.printStackTrace();
        return false;
    }
    userRepository.save(tmp);
    return true;
}
Also used : User(com.management.entities.User) ModelMapper(org.modelmapper.ModelMapper)

Example 5 with User

use of com.management.entities.User in project Internet-Software-Architectures by zivko11.

the class UserManager method Read.

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

Aggregations

User (com.management.entities.User)9 UserDTO (com.management.dto.UserDTO)7 Date (java.util.Date)6 Test (org.junit.Test)5 UserRepository (com.management.repositories.UserRepository)4 Expectations (org.jmock.Expectations)4 Mockery (org.jmock.Mockery)4 ModelMapper (org.modelmapper.ModelMapper)4 ArrayList (java.util.ArrayList)3 UserManager (com.management.managers.UserManager)2 UserRepositoryFake (com.management.fake.UserRepositoryFake)1 List (java.util.List)1