Search in sources :

Example 1 with UserManager

use of com.management.managers.UserManager 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();
}
Also used : Expectations(org.jmock.Expectations) UserRepository(com.management.repositories.UserRepository) UserManager(com.management.managers.UserManager) UserDTO(com.management.dto.UserDTO) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Example 2 with UserManager

use of com.management.managers.UserManager 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();
}
Also used : Expectations(org.jmock.Expectations) UserRepository(com.management.repositories.UserRepository) User(com.management.entities.User) UserManager(com.management.managers.UserManager) UserDTO(com.management.dto.UserDTO) Mockery(org.jmock.Mockery) Date(java.util.Date) Test(org.junit.Test)

Example 3 with UserManager

use of com.management.managers.UserManager 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();
}
Also used : Expectations(org.jmock.Expectations) User(com.management.entities.User) UserDTO(com.management.dto.UserDTO) ArrayList(java.util.ArrayList) Mockery(org.jmock.Mockery) Date(java.util.Date) UserRepository(com.management.repositories.UserRepository) UserManager(com.management.managers.UserManager) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 4 with UserManager

use of com.management.managers.UserManager in project Internet-Software-Architectures by zivko11.

the class UserControllerTests method AddingNewUser_ReturnsOK.

@Test
public void AddingNewUser_ReturnsOK() {
    // 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);
    UserController controller = new UserController(manager);
    // Act and assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(controller.addUser(dto), new ResponseEntity<UserDTO>(dto, HttpStatus.OK));
}
Also used : UserRepositoryFake(com.management.fake.UserRepositoryFake) UserManager(com.management.managers.UserManager) UserDTO(com.management.dto.UserDTO) Date(java.util.Date) Test(org.junit.Test)

Aggregations

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