use of com.management.entities.User 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();
}
use of com.management.entities.User in project Internet-Software-Architectures by zivko11.
the class UserControllerTests method ReadAllUsers_ReturnsOK.
@Test
public void ReadAllUsers_ReturnsOK() {
// 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);
UserController controller = new UserController(manager);
// Act
ResponseEntity<List<UserDTO>> response = controller.getUsers();
ArrayList<UserDTO> listDTO = (ArrayList<UserDTO>) response.getBody();
// Assert
Assert.assertNotNull(controller);
Assert.assertEquals(response, new ResponseEntity<List<UserDTO>>(listDTO, HttpStatus.OK));
mock.assertIsSatisfied();
}
use of com.management.entities.User in project Internet-Software-Architectures by zivko11.
the class UserManagerTest method ReadUser_ReturnsUser.
@Test
public void ReadUser_ReturnsUser() {
// 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);
// Act
UserDTO dto = manager.Read(1);
// Assert
Assert.assertNotNull(dto);
Assert.assertEquals(dto.getUserCity(), user.getUserCity());
Assert.assertEquals(dto.getUserAdmin(), user.getUserAdmin());
Assert.assertEquals(dto.getUserRank(), user.getUserRank());
Assert.assertEquals(dto.getUserCity(), user.getUserCity());
Assert.assertEquals(dto.getUserEmail(), user.getUserEmail());
Assert.assertEquals(dto.getUserName(), user.getUserName());
Assert.assertEquals(dto.getUserPassword(), user.getUserPassword());
Assert.assertEquals(dto.getUserSurname(), user.getUserSurname());
Assert.assertEquals(dto.getUserAdmin(), user.getUserAdmin());
Assert.assertEquals(dto.getUserCreationDate(), user.getUserCreationDate());
Assert.assertEquals(dto.getUserPhone(), user.getUserPhone());
Assert.assertEquals(dto.getUserStateid(), user.getUserStateid());
mock.assertIsSatisfied();
}
use of com.management.entities.User in project Internet-Software-Architectures by zivko11.
the class UserManagerTest method AddingNewUser_ReturnsBoolean.
@Test
public void AddingNewUser_ReturnsBoolean() {
// Arrange
userRepository = new UserRepositoryFake();
UserDTO dto = new UserDTO();
dto.setUserActive(true);
dto.setUserName("Pero");
dto.setUserSurname("Peric");
dto.setUserAdmin('O');
dto.setUserCity("Novi Sad");
dto.setUserCreationDate(new Date());
dto.setUserEmail("pero@gmail.com");
dto.setUserPassword("123");
dto.setUserRank(0);
dto.setUserPhone(123456);
dto.setUserStateid("381");
UserManager manager = new UserManager(userRepository);
// Act and assert
Assert.assertNotNull(manager);
Assert.assertTrue(manager.Create(dto));
User user = userRepository.findOne(0);
Assert.assertEquals(dto.getUserCity(), user.getUserCity());
Assert.assertEquals(dto.getUserAdmin(), user.getUserAdmin());
Assert.assertEquals(dto.getUserRank(), user.getUserRank());
Assert.assertEquals(dto.getUserCity(), user.getUserCity());
Assert.assertEquals(dto.getUserEmail(), user.getUserEmail());
Assert.assertEquals(dto.getUserName(), user.getUserName());
Assert.assertEquals(dto.getUserPassword(), user.getUserPassword());
Assert.assertEquals(dto.getUserSurname(), user.getUserSurname());
Assert.assertEquals(dto.getUserAdmin(), user.getUserAdmin());
Assert.assertEquals(dto.getUserCreationDate(), user.getUserCreationDate());
Assert.assertEquals(dto.getUserPhone(), user.getUserPhone());
Assert.assertEquals(dto.getUserStateid(), user.getUserStateid());
}
Aggregations