use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class ProfileServiceTest method testFindOAuth2ClientApprovalByUsername.
@Test
public void testFindOAuth2ClientApprovalByUsername() throws Exception {
final UserOAuth2ClientApprovalEntity result = new UserOAuth2ClientApprovalEntity().setId("123").setUser(new UserEntity().setUsername("user")).setClient(new OAuth2ClientEntity().setId("123")).setApprovalStatus(Approval.ApprovalStatus.APPROVED).setScope("scope1");
when(approvalRepository.findByUserUsername("user")).thenReturn(Collections.singletonList(result));
List<UserOAuth2ClientApprovalEntity> approvals = profileService.findOAuth2ClientApprovalByUsername("user");
assertThat(approvals).isNotEmpty();
assertThat(approvals).hasSize(1);
assertThat(approvals.get(0)).isEqualTo(result);
verify(approvalRepository).findByUserUsername("user");
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class SocialUserServiceTest method testLoadUserByUserId.
@Test
public void testLoadUserByUserId() {
when(userRepository.findOne("123")).thenReturn(new UserEntity());
socialUserService.loadUserByUserId("123");
verify(userRepository).findOne("123");
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class ProfileRestController method findProfileActiveSessions.
@GetMapping("/sessions")
public List<SessionInformation> findProfileActiveSessions(Authentication authentication) {
if (authentication == null || authentication.getPrincipal() == null)
return Collections.emptyList();
List<SessionInformation> sessions = new ArrayList<>();
for (Object principal : sessionRegistry.getAllPrincipals()) {
UserEntity user = (UserEntity) principal;
if (!user.getUsername().equals(authentication.getName()))
continue;
sessions.addAll(sessionRegistry.getAllSessions(user, true));
}
return sessions.stream().map(i -> new SessionInformation(authentication.getName(), i.getSessionId(), i.getLastRequest())).collect(Collectors.toList());
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class RegistrationControllerTest method testRegisterUser.
@Test
public void testRegisterUser() throws Exception {
UserEntity user = new UserEntity().setId("123");
when(registrationService.registerUser(any())).thenReturn(user);
when(tokenStoreService.sendTokenNotification(any(), any())).thenReturn(any());
MockHttpServletRequestBuilder request = post("/registration").param("username", "testuser").param("password", "securepassword").param("email", "theskeleton-test@codenergic.org");
MockHttpServletResponse response = mockMvc.perform(request).andReturn().getResponse();
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsString()).contains("We have sent");
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class RegistrationServiceTest method testChangePassword.
@Test
public void testChangePassword() {
UserEntity user = new UserEntity().setPassword("1234");
when(tokenStoreService.findAndVerifyToken("TOKEN1234")).thenReturn(ImmutableTokenStoreRestData.builder().from(defaultTokenStoreData).expiryDate(Date.from(defaultTokenStoreData.getExpiryDate().toInstant().plus(Duration.ofHours(1)))).user(user).build());
registrationService.changePassword("TOKEN1234", "notsecurepassword");
assertThat(user.getPassword()).isEqualTo("notsecurepassword");
verify(tokenStoreService).findAndVerifyToken("TOKEN1234");
when(tokenStoreService.findAndVerifyToken("TOKEN1235")).thenReturn(ImmutableTokenStoreRestData.builder().from(defaultTokenStoreData).expiryDate(Date.from(defaultTokenStoreData.getExpiryDate().toInstant().minus(Duration.ofHours(1)))).user(user).build());
// expired token
assertThatThrownBy(() -> registrationService.changePassword("TOKEN1235", "notsecurepassword")).hasMessage("Key is Expired").isInstanceOf(RegistrationException.class);
}
Aggregations