use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceImplTest method testCreateProfile.
@Test
public void testCreateProfile() throws Exception {
Profile expected = getTenant2Profile();
expected.setTenant(TENANT1_NAME);
expected.setAttributes(getAttributesWithoutPrivateAttribute());
expected.setAttribute(ATTRIB_NAME_GENDER, GENDER);
Profile actual = profileService.createProfile(TENANT1_NAME, USERNAME2, PASSWORD2, EMAIL2, true, ROLES2, getAttributesWithoutPrivateAttribute(), VERIFICATION_URL);
assertEqualProfiles(expected, actual);
assertTrue(CryptoUtils.matchPassword(actual.getPassword(), PASSWORD2));
assertNotNull(actual.getCreatedOn());
assertNotNull(actual.getLastModified());
VerificationToken token = new VerificationToken();
token.setId(VERIFICATION_TOKEN_ID1);
verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
verify(tenantService).getTenant(TENANT1_NAME);
verify(profileRepository).insert(actual);
verify(verificationService).createToken(actual);
verify(verificationService).sendEmail(token, actual, VERIFICATION_URL, VERIFICATION_FROM_ADDRESS, VERIFICATION_SUBJECT, VERIFICATION_TEMPLATE_NAME);
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
when(tenantPermissionEvaluator.isAllowed(anyString(), anyString())).thenReturn(true);
when(attributePermissionEvaluator.isAllowed(any(AttributeDefinition.class), anyString())).thenReturn(true);
when(attributePermissionEvaluator.isAllowed(eq(new AttributeDefinition(ATTRIB_NAME_PRIVATE)), anyString())).thenReturn(false);
when(tenantService.getTenant(TENANT1_NAME)).thenReturn(getTenant1());
when(tenantService.getTenant(TENANT2_NAME)).thenReturn(getTenant2());
when(authenticationService.getTicket(TICKET_ID)).thenReturn(getTicket());
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocation) throws Throwable {
Profile profile = (Profile) invocation.getArguments()[0];
profile.setId(new ObjectId());
return null;
}
}).when(profileRepository).insert(any(Profile.class));
when(profileRepository.findOneByQuery(String.format(ProfileServiceImpl.QUERY_FINAL_FORMAT, TENANT1_NAME, QUERY), new String[0])).thenReturn(getTenant1Profile());
when(profileRepository.findById(PROFILE1_ID.toString(), new String[0])).thenReturn(getTenant1Profile());
when(profileRepository.findById(PROFILE1_ID.toString(), NO_ATTRIBUTE)).thenReturn(getTenant1ProfileNoAttributes());
when(profileRepository.findById(PROFILE1_ID.toString(), ATTRIB_NAME_FIRST_NAME)).thenReturn(getTenant1ProfileNoLastName());
when(profileRepository.findById(PROFILE2_ID.toString(), new String[0])).thenReturn(getTenant2Profile());
when(profileRepository.findByQuery(String.format(ProfileServiceImpl.QUERY_FINAL_FORMAT, TENANT1_NAME, QUERY), SORT_BY, SortOrder.ASC, START, COUNT, new String[0])).thenReturn(getAllTenant1Profiles());
when(profileRepository.findByTenantAndUsername(TENANT1_NAME, USERNAME1, new String[0])).thenReturn(getTenant1Profile());
when(profileRepository.findByIds(TENANT1_PROFILE_IDS, SORT_BY, SortOrder.ASC)).thenReturn(getAllTenant1Profiles());
when(profileRepository.findRange(TENANT1_NAME, SORT_BY, SortOrder.ASC, START, COUNT)).thenReturn(getAllTenant1Profiles());
when(profileRepository.findByTenantAndRole(TENANT1_NAME, ROLE1, SORT_BY, SortOrder.ASC)).thenReturn(getAllTenant1Profiles());
when(profileRepository.findByTenantAndAttributeValue(TENANT1_NAME, ATTRIB_NAME_FIRST_NAME, FIRST_NAME, SORT_BY, SortOrder.ASC)).thenReturn(getAllTenant1Profiles());
when(profileRepository.countByTenant(TENANT1_NAME)).thenReturn(10L);
when(profileRepository.count(String.format(ProfileServiceImpl.QUERY_FINAL_FORMAT, TENANT1_NAME, QUERY))).thenReturn(1L);
when(verificationService.createToken(any(Profile.class))).then(new Answer<VerificationToken>() {
@Override
public VerificationToken answer(final InvocationOnMock invocation) throws Throwable {
Profile profile = (Profile) invocation.getArguments()[0];
VerificationToken token = new VerificationToken();
token.setId(VERIFICATION_TOKEN_ID1);
token.setTenant(profile.getTenant());
token.setProfileId(profile.getId().toString());
token.setTimestamp(new Date());
return token;
}
});
VerificationToken token1 = new VerificationToken();
token1.setId(VERIFICATION_TOKEN_ID1);
token1.setTenant(TENANT1_NAME);
token1.setProfileId(PROFILE1_ID.toString());
token1.setTimestamp(new Date());
VerificationToken token2 = new VerificationToken();
token2.setId(VERIFICATION_TOKEN_ID2);
token2.setTenant(TENANT2_NAME);
token2.setProfileId(PROFILE2_ID.toString());
token2.setTimestamp(new Date());
when(verificationService.getToken(VERIFICATION_TOKEN_ID1)).thenReturn(token1);
when(verificationService.getToken(VERIFICATION_TOKEN_ID2)).thenReturn(token2);
profileService = new ProfileServiceImpl();
profileService.setTenantPermissionEvaluator(tenantPermissionEvaluator);
profileService.setAttributePermissionEvaluator(attributePermissionEvaluator);
profileService.setProfileRepository(profileRepository);
profileService.setTenantService(tenantService);
profileService.setVerificationService(verificationService);
profileService.setNewProfileEmailFromAddress(VERIFICATION_FROM_ADDRESS);
profileService.setNewProfileEmailSubject(VERIFICATION_SUBJECT);
profileService.setNewProfileEmailTemplateName(VERIFICATION_TEMPLATE_NAME);
profileService.setResetPwdEmailFromAddress(RESET_PASSWORD_FROM_ADDRESS);
profileService.setResetPwdEmailSubject(RESET_PASSWORD_SUBJECT);
profileService.setResetPwdEmailTemplateName(RESET_PASSWORD_TEMPLATE_NAME);
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class AuthenticationManagerImplTest method getProfile1.
private Profile getProfile1() {
Profile profile = new Profile();
profile.setId(PROFILE_ID1);
return profile;
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class AuthenticationManagerImplTest method getProfile2.
private Profile getProfile2() {
Profile profile = new Profile();
profile.setId(PROFILE_ID2);
return profile;
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class MellonAutoLoginProcessorTest method getProfile.
private Profile getProfile() {
Profile profile = new Profile();
profile.setId(PROFILE_ID);
profile.setUsername(USERNAME);
profile.setEmail(EMAIL);
profile.setEnabled(true);
profile.setTenant(TENANT_NAME);
profile.setAttributes(getAttributes());
return profile;
}
Aggregations