Package com.porterhead.rest.user

Examples of com.porterhead.rest.user.UserServiceImpl


        when(applicationConfig.getAuthorizationExpiryTimeInSeconds()).thenReturn(60 * 60);
    }

    @Test
    public void firstTimeConnected() {
        UserService userService = new UserServiceImpl(usersConnectionRepository, validator, applicationConfig);
        ((UserServiceImpl)userService).setUserRepository(userRepository);
        List<String> userIds = usersConnectionRepository.findUserIdsWithConnection(connection);
        assertThat(userIds.size(), is(1));
        assertThat(userIds.get(0), is(user.getUuid().toString()));
        verify(userRepository, times(2)).save(any(User.class));
View Full Code Here


    }

    @Test
    public void validSocialLogin() {
        UserService userService = new UserServiceImpl(usersConnectionRepository, validator, applicationConfig);
        ((UserServiceImpl)userService).setUserRepository(userRepository);
        UserProfileBuilder builder = new UserProfileBuilder();
        UserProfile profile = builder.setFirstName("Tom").setLastName("Tucker").setEmail("tt@example.com").setUsername("ttucker").build();
        when(connection.fetchUserProfile()).thenReturn(profile);
        AuthenticatedUserToken token = userService.socialLogin(connection);
        ExternalUser user = userService.getUser(new ExternalUser(token.getUserId()), token.getUserId());
        assertThat(user, is(notNullValue()));
        assertThat(user.getEmailAddress(), is("tt@example.com"));
        assertThat(user.getFirstName(), is("Tom"));
        assertThat(user.getLastName(), is("Tucker"));
        assertThat(user.isVerified(), is(true));
View Full Code Here

        assertThat(user.getRole().equalsIgnoreCase(Role.authenticated.toString()), is(true));
    }

     @Test
    public void updateFromSocialLogin() {
        UserService userService = new UserServiceImpl(usersConnectionRepository, validator, applicationConfig);
        ((UserServiceImpl)userService).setUserRepository(userRepository);
        UserProfileBuilder builder = new UserProfileBuilder();
        UserProfile profile = builder.setFirstName("Tom").setLastName("Tucker").setEmail("tt@example.com").setUsername("ttucker").build();
        when(connection.fetchUserProfile()).thenReturn(profile);
        userService.socialLogin(connection);
        //login again and update
        profile = builder.setFirstName("Foo").setLastName("Bar").setEmail("foobar@example.com").setUsername("foobar").build();
        when(connection.fetchUserProfile()).thenReturn(profile);
        AuthenticatedUserToken token = userService.socialLogin(connection);
        ExternalUser user = userService.getUser(new ExternalUser(token.getUserId()), token.getUserId());
        assertThat(user, is(notNullValue()));
        assertThat(user.getEmailAddress(), is("foobar@example.com"));
        assertThat(user.getFirstName(), is("Foo"));
        assertThat(user.getLastName(), is("Bar"));
        assertThat(user.isVerified(), is(true));
View Full Code Here

     *
     */
    @Test
    public void loginWithEmailAddressThenSocialLogin() {
        //set up services
        UserService userService = new UserServiceImpl(usersConnectionRepository, validator, applicationConfig);
        ((UserServiceImpl) userService).setUserRepository(userRepository);
        //create email account
        CreateUserRequest request = getCreateUserRequest(RandomStringUtils.randomAlphabetic(8) + "@example.com");
        AuthenticatedUserToken token = userService.createUser(request, Role.authenticated);

        UserProfileBuilder builder = new UserProfileBuilder();
        UserProfile profile = builder.setFirstName(user.getFirstName()).setLastName(user.getLastName()).setEmail(user.getEmailAddress()).setUsername("jsmith.12").build();
        when(connection.fetchUserProfile()).thenReturn(profile);
        when(userRepository.findByEmailAddress(any(String.class))).thenReturn(new User(UUID.fromString(token.getUserId())));
        when(userRepository.findByUuid(any(String.class))).thenReturn(new User(UUID.fromString(token.getUserId())));
        AuthenticatedUserToken loginToken = userService.socialLogin(connection);
        ExternalUser user = userService.getUser(new ExternalUser(token.getUserId()), token.getUserId());
        assertThat(token.getUserId(), is(loginToken.getUserId()));
    }
View Full Code Here

TOP

Related Classes of com.porterhead.rest.user.UserServiceImpl

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.