Package org.jtalks.jcommune.model.dto

Examples of org.jtalks.jcommune.model.dto.RegisterUserDto


        assertEquals(response.getStatus(), JsonResponseStatus.FAIL, "Connection error should fail registration.");
    }
   
    @Test
    public void testRegisterAjaxFailIfHoneypotCaptchaNotNull() throws Exception {
        RegisterUserDto dto = createRegisterUserDto("anyString");

        JsonResponse response = userController.registerUserAjax(dto, request, Locale.ENGLISH);
       
        assertEquals(response.getStatus(), JsonResponseStatus.FAIL, "HoneypotException should fail registration.");
    }
View Full Code Here


    private RegisterUserDto createRegisterUserDto(String honeypotCaptcha) {
        UserDto userDto = new UserDto();
        userDto.setUsername(USER_NAME);
        userDto.setEmail(EMAIL);
        userDto.setPassword("password");
        RegisterUserDto dto = new RegisterUserDto();
        dto.setPasswordConfirm("password");
        dto.setUserDto(userDto);
        dto.setHoneypotCaptcha(honeypotCaptcha);
        return dto;
    }
View Full Code Here

        authenticator.authenticate(loginUserDto, httpRequest, httpResponse);
    }

    @Test
    public void registerUserWithCorrectDetailsShouldBeSuccessful() throws Exception {
        RegisterUserDto userDto = createRegisterUserDto("username", "password", "email@email.em", null);
        User commonUser = new User("username", "email@email.em", "password", null);
        when(registrationPlugin.getState()).thenReturn(Plugin.State.ENABLED);
        when(registrationPlugin.registerUser(userDto.getUserDto(), null)).thenReturn(Collections.EMPTY_MAP);
        when(pluginLoader.getPlugins(any(TypeFilter.class))).thenReturn(Arrays.asList((Plugin) registrationPlugin));
        when(bindingResult.hasErrors()).thenReturn(false);
        when(userDao.getCommonUserByUsername("username")).thenReturn(commonUser);

        authenticator.register(userDto);
View Full Code Here

        verify(bindingResult, never()).rejectValue(anyString(), anyString(), anyString());
    }

    @Test
    public void registerUserWithIncorrectDetailsShouldFail() throws Exception {
        RegisterUserDto userDto = createRegisterUserDto("", "", "", null);
        Map<String, String> errors = new HashMap<>();
        errors.put("userDto.email", "Invalid email length");
        errors.put("userDto.username", "Invalid username length");
        errors.put("userDto.password", "Invalid password length");

        RegistrationPlugin plugin = mock(RegistrationPlugin.class);
        when(plugin.getState()).thenReturn(Plugin.State.ENABLED);
        when(plugin.registerUser(userDto.getUserDto(), 1L)).thenReturn(errors);

        when(pluginService.getRegistrationPlugins()).thenReturn(
                new ImmutableMap.Builder<Long, RegistrationPlugin>().put(1L, plugin).build());

        when(bindingResult.hasErrors()).thenReturn(true);
View Full Code Here

        assertEquals(result.getFieldErrors().size(), 3);
    }

    @Test(expectedExceptions = NoConnectionException.class)
    public void registerUserShouldFailIfPluginThrowsNoConnectionException() throws Exception {
        RegisterUserDto userDto = createRegisterUserDto("username", "password", "email@email.em", null);
        RegistrationPlugin plugin = mock(RegistrationPlugin.class);
        when(plugin.getState()).thenReturn(Plugin.State.ENABLED);
        when(plugin.registerUser(userDto.getUserDto(), 1L))
                .thenThrow(new NoConnectionException());
        when(pluginService.getRegistrationPlugins()).thenReturn(
                new ImmutableMap.Builder<Long, RegistrationPlugin>().put(1L, plugin).build());

        when(bindingResult.hasErrors()).thenReturn(true);
View Full Code Here

        authenticator.register(userDto);
    }

    @Test(expectedExceptions = UnexpectedErrorException.class)
    public void registerUserShouldFailIfPluginThrowsUnexpectedErrorException() throws Exception {
        RegisterUserDto userDto = createRegisterUserDto("username", "password", "email@email.em", null);
        RegistrationPlugin plugin = mock(RegistrationPlugin.class);
        when(plugin.getState()).thenReturn(Plugin.State.ENABLED);
        when(plugin.registerUser(userDto.getUserDto(), 1L))
                .thenThrow(new UnexpectedErrorException());
        when(pluginService.getRegistrationPlugins()).thenReturn(
                new ImmutableMap.Builder<Long, RegistrationPlugin>().put(1L, plugin).build());

        authenticator.register(userDto);
View Full Code Here

        authenticator.register(userDto);
    }

    @Test
    public void defaultRegistrationShouldFailIfValidationErrorsOccurred() throws Exception {
        RegisterUserDto userDto = createRegisterUserDto("username", "password", "email@email.em", null);
        when(pluginLoader.getPlugins(any(TypeFilter.class))).thenReturn(Collections.EMPTY_LIST);
        when(bindingResult.hasErrors()).thenReturn(true);

        authenticator.register(userDto);
View Full Code Here

        verify(bindingResult, never()).rejectValue(anyString(), anyString(), anyString());
    }

    @Test
    public void defaultRegistrationWithCorrectDetailsShouldBeSuccessful() throws Exception {
        RegisterUserDto userDto = createRegisterUserDto("username", "password", "email@email.em", null);
        when(pluginLoader.getPlugins(any(TypeFilter.class))).thenReturn(Collections.EMPTY_LIST);
        when(bindingResult.hasErrors()).thenReturn(false);

        authenticator.register(userDto);
View Full Code Here

    }

    @Test
    public void userShouldBeRegisteredUsingEncryptedPassword() throws Exception{
        String password = "password";
        RegisterUserDto registerUserDto = createRegisterUserDto("username", password, "email@email.em", null);
        EncryptionService realEncryptionService = new EncryptionService(new Md5PasswordEncoder());
        TransactionalAuthenticator authenticatorSpy = spy(new TransactionalAuthenticator(pluginLoader, userDao, groupDao,
                realEncryptionService, mailService, avatarService, pluginService,
                securityFacade, rememberMeServices, sessionStrategy, validator, authenticationManager));
View Full Code Here

        verify(authenticatorSpy).registerByPlugin(refEq(expected), eq(true), any(BindingResult.class));
        verify(authenticatorSpy).storeRegisteredUser(refEq(expected));
    }

    private RegisterUserDto createRegisterUserDto(String username, String password, String email, String honeypotCaptcha) {
        RegisterUserDto registerUserDto = new RegisterUserDto();
        UserDto userDto = new UserDto();
        userDto.setUsername(username);
        userDto.setEmail(email);
        userDto.setPassword(password);
        registerUserDto.setUserDto(userDto);
        registerUserDto.setHoneypotCaptcha(honeypotCaptcha);
        return registerUserDto;
    }
View Full Code Here

TOP

Related Classes of org.jtalks.jcommune.model.dto.RegisterUserDto

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.