use of com.management.dto.UserDTO 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.dto.UserDTO in project Internet-Software-Architectures by zivko11.
the class UserControllerTests method DeletingUser_ReturnsOK.
@Test
public void DeletingUser_ReturnsOK() {
// Arrange
Mockery mock = new Mockery();
userRepository = mock.mock(UserRepository.class);
// expectations
mock.checking(new Expectations() {
{
oneOf(userRepository).delete(1);
}
});
// Act and assert
UserManager manager = new UserManager(userRepository);
UserController controller = new UserController(manager);
Assert.assertNotNull(controller);
Assert.assertEquals(controller.deleteUser(1), new ResponseEntity<UserDTO>(HttpStatus.OK));
mock.assertIsSatisfied();
}
use of com.management.dto.UserDTO 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.dto.UserDTO 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;
}
use of com.management.dto.UserDTO in project Internet-Software-Architectures by zivko11.
the class UserControllerTests method ReadUser_ReturnsOK.
@Test
public void ReadUser_ReturnsOK() {
// Arrange
Mockery mock = new Mockery();
userRepository = mock.mock(UserRepository.class);
final User user = new User();
user.setUserId(1);
user.setUserActive(true);
user.setUserName("Pero");
user.setUserSurname("Peric");
user.setUserAdmin('O');
user.setUserCity("Novi Sad");
user.setUserCreationDate(new Date());
user.setUserEmail("pero@gmail.com");
user.setUserPassword("123");
user.setUserRank(0);
user.setUserPhone(123456);
user.setUserStateid("381");
mock.checking(new Expectations() {
{
oneOf(userRepository).findOne(1);
will(returnValue(user));
}
});
UserManager manager = new UserManager(userRepository);
UserController controller = new UserController(manager);
// Act
ResponseEntity<UserDTO> response = controller.getUser(1);
UserDTO dto = response.getBody();
// Assert
Assert.assertNotNull(controller);
Assert.assertEquals(response, new ResponseEntity<UserDTO>(dto, HttpStatus.OK));
mock.assertIsSatisfied();
}
Aggregations