use of org.craftercms.profile.api.VerificationToken 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.VerificationToken in project profile by craftercms.
the class VerificationServiceImplTest method testGetToken.
@Test
public void testGetToken() throws Exception {
VerificationToken token = verificationService.getToken(TOKEN_ID);
assertNotNull(token);
assertEquals(TOKEN_ID, token.getId());
assertEquals(PROFILE_ID.toString(), token.getProfileId());
assertNotNull(token.getTimestamp());
verify(tokenRepository).findByStringId(TOKEN_ID);
}
use of org.craftercms.profile.api.VerificationToken in project profile by craftercms.
the class ProfileServiceIT method testDeleteVerificationToken.
@Test
public void testDeleteVerificationToken() throws Exception {
Profile profile = profileService.getProfileByUsername(DEFAULT_TENANT, ADMIN_USERNAME);
String profileId = profile.getId().toString();
VerificationToken token = profileService.createVerificationToken(profileId);
assertNotNull(token);
profileService.deleteVerificationToken(token.getId());
token = profileService.getVerificationToken(token.getId());
assertNull(token);
}
use of org.craftercms.profile.api.VerificationToken in project profile by craftercms.
the class ProfileServiceIT method testCreateVerificationToken.
@Test
public void testCreateVerificationToken() throws Exception {
Profile profile = profileService.getProfileByUsername(DEFAULT_TENANT, ADMIN_USERNAME);
String profileId = profile.getId().toString();
VerificationToken token = profileService.createVerificationToken(profileId);
assertNotNull(token);
try {
assertNotNull(token.getId());
assertEquals(profile.getTenant(), token.getTenant());
assertEquals(profileId, token.getProfileId());
assertNotNull(token.getTimestamp());
} finally {
profileService.deleteVerificationToken(token.getId());
}
}
use of org.craftercms.profile.api.VerificationToken in project profile by craftercms.
the class ProfileServiceIT method testGetVerificationToken.
@Test
public void testGetVerificationToken() throws Exception {
Profile profile = profileService.getProfileByUsername(DEFAULT_TENANT, ADMIN_USERNAME);
String profileId = profile.getId().toString();
VerificationToken originalToken = profileService.createVerificationToken(profileId);
assertNotNull(originalToken);
try {
VerificationToken token = profileService.getVerificationToken(originalToken.getId());
assertNotNull(token);
assertEquals(originalToken.getId(), token.getId());
assertEquals(originalToken.getTenant(), token.getTenant());
assertEquals(originalToken.getProfileId(), token.getProfileId());
assertEquals(originalToken.getTimestamp(), token.getTimestamp());
} finally {
profileService.deleteVerificationToken(originalToken.getId());
}
}
Aggregations