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();
}
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;
}
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;
}
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;
}
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;
}
Aggregations