use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class TenantControllerTest method getProfile.
private Profile getProfile(String tenantName, String role) {
Profile profile = new Profile();
profile.setTenant(tenantName);
profile.getRoles().add(role);
return profile;
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceImplTest method testUpdateProfile.
@Test
public void testUpdateProfile() throws Exception {
final Profile expected = new Profile();
expected.setId(PROFILE1_ID);
expected.setTenant(TENANT1_NAME);
expected.setUsername(USERNAME2);
expected.setPassword(CryptoUtils.hashPassword(PASSWORD2));
expected.setEmail(EMAIL2);
expected.setRoles(ROLES2);
expected.setVerified(true);
expected.setEnabled(false);
expected.setAttributes(getAttributesWithoutPrivateAttribute());
expected.getAttributes().put(ATTRIB_NAME_GENDER, GENDER);
final Map<String, Object> newAttributes = Collections.<String, Object>singletonMap(ATTRIB_NAME_GENDER, GENDER);
Profile actual = profileService.updateProfile(PROFILE1_ID.toString(), USERNAME2, PASSWORD2, EMAIL2, false, ROLES2, newAttributes);
assertEqualProfiles(expected, actual);
ArgumentMatcher<Object> setParamMatcher = new ArgumentMatcher<Object>() {
@Override
public boolean matches(Object argument) {
Map<String, Object> param = (Map<String, Object>) argument;
return param.size() == 7 && param.get("username").equals(USERNAME2) && param.containsKey("password") && param.get("email").equals(EMAIL2) && param.get("roles").equals(ROLES2) && param.get("enabled").equals(false) && param.containsKey("lastModified") && param.get("attributes." + ATTRIB_NAME_GENDER).equals(GENDER);
}
};
verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
verify(profileRepository).findById(PROFILE1_ID.toString(), new String[0]);
verify(profileRepository).update(eq(PROFILE1_ID.toString()), eq("{$set: #}"), eq(false), eq(false), argThat(setParamMatcher));
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceImplTest method testResetPassword.
@Test
public void testResetPassword() throws Exception {
Profile expected = getTenant1Profile();
expected.setAttributes(getAttributesWithoutPrivateAttribute());
Profile actual = profileService.resetPassword(PROFILE1_ID.toString(), RESET_PASSWORD_URL);
assertEqualProfiles(expected, actual);
VerificationToken token = new VerificationToken();
token.setId(VERIFICATION_TOKEN_ID1);
verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
verify(profileRepository).findById(PROFILE1_ID.toString(), new String[0]);
verify(verificationService).createToken(actual);
verify(verificationService).sendEmail(token, actual, RESET_PASSWORD_URL, RESET_PASSWORD_FROM_ADDRESS, RESET_PASSWORD_SUBJECT, RESET_PASSWORD_TEMPLATE_NAME);
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceImplTest method testCreateProfileNotVerify.
@Test
public void testCreateProfileNotVerify() throws Exception {
Profile expected = getTenant2Profile();
expected.setEnabled(true);
expected.setAttributes(getAttributesWithoutPrivateAttribute());
expected.setAttribute(ATTRIB_NAME_GENDER, GENDER);
Profile actual = profileService.createProfile(TENANT2_NAME, USERNAME2, PASSWORD2, EMAIL2, true, ROLES2, getAttributesWithoutPrivateAttribute(), VERIFICATION_URL);
assertEqualProfiles(expected, actual);
assertTrue(CryptoUtils.matchPassword(actual.getPassword(), PASSWORD2));
assertNotNull(actual.getCreatedOn());
assertNotNull(actual.getLastModified());
verify(tenantPermissionEvaluator).isAllowed(TENANT2_NAME, TenantAction.MANAGE_PROFILES.toString());
verify(tenantService).getTenant(TENANT2_NAME);
verify(profileRepository).insert(actual);
verify(verificationService, never()).createToken(any(Profile.class));
verify(verificationService, never()).sendEmail(any(VerificationToken.class), any(Profile.class), anyString(), anyString(), anyString(), anyString());
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceImplTest method testUpdateAttributes.
@Test
public void testUpdateAttributes() throws Exception {
Profile expected = getTenant1Profile();
expected.setAttributes(getAttributesWithoutPrivateAttribute());
expected.getAttributes().put(ATTRIB_NAME_GENDER, GENDER);
Map<String, Object> newAttributes = Collections.<String, Object>singletonMap(ATTRIB_NAME_GENDER, GENDER);
Profile actual = profileService.updateAttributes(PROFILE1_ID.toString(), newAttributes);
assertEqualProfiles(expected, actual);
ArgumentMatcher<Object> setParamMatcher = new ArgumentMatcher<Object>() {
@Override
public boolean matches(Object argument) {
Map<String, Object> param = (Map<String, Object>) argument;
return param.size() == 2 && param.containsKey("lastModified") && param.get("attributes." + ATTRIB_NAME_GENDER).equals(GENDER);
}
};
verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
verify(profileRepository).findById(PROFILE1_ID.toString(), new String[0]);
verify(profileRepository).update(eq(PROFILE1_ID.toString()), eq("{$set: #}"), eq(false), eq(false), argThat(setParamMatcher));
}
Aggregations