use of org.orcid.core.manager.ProfileEntityManager in project ORCID-Source by ORCID.
the class AdminControllerTest method testUnreviewAccounts.
@Test
public void testUnreviewAccounts() {
ProfileEntityCacheManager profileEntityCacheManager = Mockito.mock(ProfileEntityCacheManager.class);
ProfileEntityManager profileEntityManager = Mockito.mock(ProfileEntityManager.class);
EmailManager emailManager = Mockito.mock(EmailManager.class);
AdminController adminController = new AdminController();
ReflectionTestUtils.setField(adminController, "profileEntityManager", profileEntityManager);
ReflectionTestUtils.setField(adminController, "emailManager", emailManager);
ReflectionTestUtils.setField(adminController, "profileEntityCacheManager", profileEntityCacheManager);
String commaSeparatedValues = "some,orcid,ids,or,emails,to,test,with";
Mockito.when(emailManager.emailExists(Mockito.anyString())).thenReturn(true);
Mockito.when(emailManager.emailExists(Mockito.eq("some"))).thenReturn(false);
Mockito.when(emailManager.emailExists(Mockito.eq("orcid"))).thenReturn(false);
Map<String, String> map = new HashMap<String, String>();
map.put("ids", "ids");
map.put("or", "or");
map.put("emails", "emails");
map.put("to", "to");
map.put("test", "test");
map.put("with", "with");
Mockito.when(emailManager.findOricdIdsByCommaSeparatedEmails(Mockito.anyString())).thenReturn(map);
Mockito.when(profileEntityManager.orcidExists(Mockito.anyString())).thenReturn(true);
Mockito.when(profileEntityCacheManager.retrieve(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {
@Override
public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
String ar1 = invocation.getArgument(0);
ProfileEntity p = new ProfileEntity();
p.setId(ar1);
if (ar1.equals("ids") || ar1.equals("or")) {
p.setReviewed(false);
} else {
p.setReviewed(true);
}
return p;
}
});
Mockito.when(profileEntityManager.reviewProfile("some")).thenThrow(new RuntimeException("Controller shouldn't try to review null profile"));
Mockito.when(profileEntityManager.reviewProfile("orcid")).thenThrow(new RuntimeException("Controller shouldn't try to review null profile"));
Mockito.when(profileEntityManager.reviewProfile("ids")).thenThrow(new RuntimeException("Controller shouldn't try to review reviewed profile"));
Mockito.when(profileEntityManager.reviewProfile("or")).thenThrow(new RuntimeException("Controller shouldn't try to review reviewed profile"));
Mockito.when(profileEntityManager.reviewProfile("emails")).thenReturn(true);
Mockito.when(profileEntityManager.reviewProfile("to")).thenReturn(true);
Mockito.when(profileEntityManager.reviewProfile("test")).thenReturn(true);
Mockito.when(profileEntityManager.reviewProfile("with")).thenReturn(true);
Map<String, Set<String>> results = adminController.unreviewAccounts(commaSeparatedValues);
assertEquals(2, results.get("notFoundList").size());
assertTrue(results.get("notFoundList").contains("some"));
assertTrue(results.get("notFoundList").contains("orcid"));
assertEquals(2, results.get("alreadyUnreviewedList").size());
assertTrue(results.get("alreadyUnreviewedList").contains("ids"));
assertTrue(results.get("alreadyUnreviewedList").contains("or"));
assertEquals(4, results.get("unreviewSuccessfulList").size());
assertTrue(results.get("unreviewSuccessfulList").contains("emails"));
assertTrue(results.get("unreviewSuccessfulList").contains("to"));
assertTrue(results.get("unreviewSuccessfulList").contains("test"));
assertTrue(results.get("unreviewSuccessfulList").contains("with"));
Mockito.verify(emailManager, Mockito.times(8)).emailExists(Mockito.anyString());
Mockito.verify(profileEntityManager, Mockito.times(4)).unreviewProfile(Mockito.anyString());
}
use of org.orcid.core.manager.ProfileEntityManager in project ORCID-Source by ORCID.
the class ManageProfileControllerTest method initMocks.
@Before
public void initMocks() throws Exception {
controller = new ManageProfileController();
MockitoAnnotations.initMocks(this);
SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
TargetProxyHelper.injectIntoProxy(controller, "profileEntityCacheManager", mockProfileEntityCacheManager);
TargetProxyHelper.injectIntoProxy(controller, "encryptionManager", mockEncryptionManager);
TargetProxyHelper.injectIntoProxy(controller, "emailManager", mockEmailManager);
TargetProxyHelper.injectIntoProxy(controller, "localeManager", mockLocaleManager);
TargetProxyHelper.injectIntoProxy(controller, "profileEntityManager", mockProfileEntityManager);
TargetProxyHelper.injectIntoProxy(controller, "givenPermissionToManager", mockGivenPermissionToManager);
TargetProxyHelper.injectIntoProxy(controller, "orcidSecurityManager", mockOrcidSecurityManager);
when(mockOrcidSecurityManager.isPasswordConfirmationRequired()).thenReturn(true);
when(mockEncryptionManager.hashMatches(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
when(mockEncryptionManager.hashMatches(Mockito.eq("invalid password"), Mockito.anyString())).thenReturn(false);
when(mockProfileEntityManager.deprecateProfile(Mockito.anyString(), Mockito.anyString())).thenReturn(false);
when(mockProfileEntityManager.deprecateProfile(Mockito.eq(DEPRECATED_USER_ORCID), Mockito.eq(USER_ORCID))).thenReturn(true);
when(mockLocaleManager.resolveMessage(Mockito.anyString(), Mockito.any())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgument(0);
}
});
when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).then(new Answer<ProfileEntity>() {
@Override
public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
ProfileEntity entity = new ProfileEntity();
entity.setId(invocation.getArgument(0));
Set<GivenPermissionToEntity> givenPermissionTo = new HashSet<GivenPermissionToEntity>();
IntStream.range(0, 2).forEachOrdered(i -> {
GivenPermissionToEntity e1 = new GivenPermissionToEntity();
e1.setId(Long.valueOf(i));
Date now = new Date();
e1.setApprovalDate(now);
e1.setDateCreated(now);
e1.setGiver(invocation.getArgument(0));
ProfileSummaryEntity ps = new ProfileSummaryEntity();
RecordNameEntity recordName = new RecordNameEntity();
recordName.setVisibility(Visibility.PUBLIC);
if (i == 0) {
ps.setId("0000-0000-0000-0004");
recordName.setCreditName("Credit Name");
} else {
ps.setId("0000-0000-0000-0005");
recordName.setFamilyName("Family Name");
recordName.setGivenNames("Given Names");
}
ps.setRecordNameEntity(recordName);
e1.setReceiver(ps);
givenPermissionTo.add(e1);
});
entity.setGivenPermissionTo(givenPermissionTo);
EmailEntity email1 = new EmailEntity();
email1.setId(invocation.getArgument(0) + "_1@test.orcid.org");
email1.setVerified(true);
email1.setCurrent(true);
email1.setDateCreated(new Date());
email1.setLastModified(new Date());
email1.setPrimary(true);
email1.setVisibility(Visibility.PUBLIC);
EmailEntity email2 = new EmailEntity();
email2.setId(invocation.getArgument(0) + "_2@test.orcid.org");
email2.setVerified(true);
email2.setCurrent(false);
email2.setDateCreated(new Date());
email2.setLastModified(new Date());
email2.setPrimary(false);
email2.setVisibility(Visibility.PUBLIC);
Set<EmailEntity> emails = new HashSet<EmailEntity>();
emails.add(email1);
emails.add(email2);
entity.setEmails(emails);
entity.setRecordNameEntity(getRecordName(invocation.getArgument(0)));
entity.setEncryptedPassword("password");
return entity;
}
});
when(mockEmailManager.getEmails(Mockito.anyString(), Mockito.anyLong())).thenAnswer(new Answer<Emails>() {
@Override
public Emails answer(InvocationOnMock invocation) throws Throwable {
Emails emails = new Emails();
Email email1 = new Email();
email1.setEmail(invocation.getArgument(0) + "_1@test.orcid.org");
email1.setVisibility(Visibility.PUBLIC);
emails.getEmails().add(email1);
Email email2 = new Email();
email2.setEmail(invocation.getArgument(0) + "_2@test.orcid.org");
email2.setVisibility(Visibility.PUBLIC);
emails.getEmails().add(email2);
return emails;
}
});
when(mockEmailManager.findCaseInsensitive(Mockito.anyString())).thenAnswer(new Answer<EmailEntity>() {
@Override
public EmailEntity answer(InvocationOnMock invocation) throws Throwable {
String emailString = invocation.getArgument(0);
String orcidString = emailString.substring(0, (emailString.indexOf("_")));
EmailEntity email = new EmailEntity();
email.setId(emailString);
email.setVisibility(Visibility.PUBLIC);
ProfileEntity entity = new ProfileEntity(orcidString);
entity.setEncryptedPassword("password");
entity.setRecordNameEntity(getRecordName(orcidString));
email.setProfile(entity);
return email;
}
});
}
use of org.orcid.core.manager.ProfileEntityManager in project ORCID-Source by ORCID.
the class AdminControllerTest method testReviewAccounts.
@Test
public void testReviewAccounts() {
ProfileEntityCacheManager profileEntityCacheManager = Mockito.mock(ProfileEntityCacheManager.class);
ProfileEntityManager profileEntityManager = Mockito.mock(ProfileEntityManager.class);
EmailManager emailManager = Mockito.mock(EmailManager.class);
AdminController adminController = new AdminController();
ReflectionTestUtils.setField(adminController, "profileEntityManager", profileEntityManager);
ReflectionTestUtils.setField(adminController, "emailManager", emailManager);
ReflectionTestUtils.setField(adminController, "profileEntityCacheManager", profileEntityCacheManager);
String commaSeparatedValues = "some,orcid,ids,or,emails,to,test,with";
Mockito.when(emailManager.emailExists(Mockito.anyString())).thenReturn(true);
Mockito.when(emailManager.emailExists(Mockito.eq("some"))).thenReturn(false);
Mockito.when(emailManager.emailExists(Mockito.eq("orcid"))).thenReturn(false);
Map<String, String> map = new HashMap<String, String>();
map.put("ids", "ids");
map.put("or", "or");
map.put("emails", "emails");
map.put("to", "to");
map.put("test", "test");
map.put("with", "with");
Mockito.when(emailManager.findOricdIdsByCommaSeparatedEmails(Mockito.anyString())).thenReturn(map);
Mockito.when(profileEntityManager.orcidExists(Mockito.anyString())).thenReturn(true);
Mockito.when(profileEntityCacheManager.retrieve(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {
@Override
public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
String ar1 = invocation.getArgument(0);
ProfileEntity p = new ProfileEntity();
p.setId(ar1);
if (ar1.equals("ids") || ar1.equals("or")) {
p.setReviewed(true);
} else {
p.setReviewed(false);
}
return p;
}
});
Mockito.when(profileEntityManager.reviewProfile("some")).thenThrow(new RuntimeException("Controller shouldn't try to review null profile"));
Mockito.when(profileEntityManager.reviewProfile("orcid")).thenThrow(new RuntimeException("Controller shouldn't try to review null profile"));
Mockito.when(profileEntityManager.reviewProfile("ids")).thenThrow(new RuntimeException("Controller shouldn't try to review reviewed profile"));
Mockito.when(profileEntityManager.reviewProfile("or")).thenThrow(new RuntimeException("Controller shouldn't try to review reviewed profile"));
Mockito.when(profileEntityManager.reviewProfile("emails")).thenReturn(true);
Mockito.when(profileEntityManager.reviewProfile("to")).thenReturn(true);
Mockito.when(profileEntityManager.reviewProfile("test")).thenReturn(true);
Mockito.when(profileEntityManager.reviewProfile("with")).thenReturn(true);
Map<String, Set<String>> results = adminController.reviewAccounts(commaSeparatedValues);
assertEquals(2, results.get("notFoundList").size());
assertTrue(results.get("notFoundList").contains("some"));
assertTrue(results.get("notFoundList").contains("orcid"));
assertEquals(2, results.get("alreadyReviewedList").size());
assertTrue(results.get("alreadyReviewedList").contains("ids"));
assertTrue(results.get("alreadyReviewedList").contains("or"));
assertEquals(4, results.get("reviewSuccessfulList").size());
assertTrue(results.get("reviewSuccessfulList").contains("emails"));
assertTrue(results.get("reviewSuccessfulList").contains("to"));
assertTrue(results.get("reviewSuccessfulList").contains("test"));
assertTrue(results.get("reviewSuccessfulList").contains("with"));
Mockito.verify(emailManager, Mockito.times(8)).emailExists(Mockito.anyString());
Mockito.verify(profileEntityManager, Mockito.times(4)).reviewProfile(Mockito.anyString());
}
use of org.orcid.core.manager.ProfileEntityManager in project ORCID-Source by ORCID.
the class AdminControllerTest method testLockAccounts.
@Test
public void testLockAccounts() {
ProfileEntityCacheManager profileEntityCacheManager = Mockito.mock(ProfileEntityCacheManager.class);
ProfileEntityManager profileEntityManager = Mockito.mock(ProfileEntityManager.class);
EmailManager emailManager = Mockito.mock(EmailManager.class);
AdminController adminController = new AdminController();
ReflectionTestUtils.setField(adminController, "profileEntityManager", profileEntityManager);
ReflectionTestUtils.setField(adminController, "emailManager", emailManager);
ReflectionTestUtils.setField(adminController, "profileEntityCacheManager", profileEntityCacheManager);
String commaSeparatedValues = "some,orcid,ids,or,emails,to,test,with,reviewed";
Mockito.when(emailManager.emailExists(Mockito.anyString())).thenReturn(true);
Mockito.when(emailManager.emailExists(Mockito.eq("some"))).thenReturn(false);
Mockito.when(emailManager.emailExists(Mockito.eq("orcid"))).thenReturn(false);
Map<String, String> map = new HashMap<String, String>();
map.put("ids", "ids");
map.put("or", "or");
map.put("emails", "emails");
map.put("to", "to");
map.put("test", "test");
map.put("with", "with");
map.put("reviewed", "reviewed");
Mockito.when(emailManager.findOricdIdsByCommaSeparatedEmails(Mockito.anyString())).thenReturn(map);
Mockito.when(profileEntityManager.orcidExists(Mockito.anyString())).thenReturn(true);
Mockito.when(profileEntityManager.orcidExists(Mockito.eq("some"))).thenReturn(false);
Mockito.when(profileEntityManager.orcidExists(Mockito.eq("orcid"))).thenReturn(false);
Mockito.when(profileEntityCacheManager.retrieve(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {
@Override
public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
String ar1 = invocation.getArgument(0);
ProfileEntity p = new ProfileEntity();
p.setId(ar1);
if (ar1.equals("ids") || ar1.equals("or")) {
p.setRecordLocked(true);
} else {
p.setRecordLocked(false);
}
if (ar1.contentEquals("reviewed")) {
p.setReviewed(true);
} else {
p.setReviewed(false);
}
return p;
}
});
LockAccounts lockAccounts = new LockAccounts();
lockAccounts.setOrcidsToLock(commaSeparatedValues);
lockAccounts.setLockReason(LockReason.SPAM.getLabel());
Map<String, Set<String>> results = adminController.lockAccounts(lockAccounts);
assertEquals(2, results.get("notFoundList").size());
assertTrue(results.get("notFoundList").contains("some"));
assertTrue(results.get("notFoundList").contains("orcid"));
assertEquals(2, results.get("alreadyLockedList").size());
assertTrue(results.get("alreadyLockedList").contains("ids"));
assertTrue(results.get("alreadyLockedList").contains("or"));
assertEquals(4, results.get("lockSuccessfulList").size());
assertTrue(results.get("lockSuccessfulList").contains("emails"));
assertTrue(results.get("lockSuccessfulList").contains("to"));
assertTrue(results.get("lockSuccessfulList").contains("test"));
assertTrue(results.get("lockSuccessfulList").contains("with"));
assertEquals(1, results.get("reviewedList").size());
assertTrue(results.get("reviewedList").contains("reviewed"));
Mockito.verify(emailManager, Mockito.times(9)).emailExists(Mockito.anyString());
Mockito.verify(profileEntityManager, Mockito.times(4)).lockProfile(Mockito.anyString(), Mockito.anyString(), isNull());
}
use of org.orcid.core.manager.ProfileEntityManager in project ORCID-Source by ORCID.
the class AdminControllerTest method testUnlockAccounts.
@Test
public void testUnlockAccounts() {
ProfileEntityCacheManager profileEntityCacheManager = Mockito.mock(ProfileEntityCacheManager.class);
ProfileEntityManager profileEntityManager = Mockito.mock(ProfileEntityManager.class);
EmailManager emailManager = Mockito.mock(EmailManager.class);
AdminController adminController = new AdminController();
ReflectionTestUtils.setField(adminController, "profileEntityManager", profileEntityManager);
ReflectionTestUtils.setField(adminController, "emailManager", emailManager);
ReflectionTestUtils.setField(adminController, "profileEntityCacheManager", profileEntityCacheManager);
String commaSeparatedValues = "some,orcid,ids,or,emails,to,test,with";
Mockito.when(emailManager.emailExists(Mockito.anyString())).thenReturn(true);
Mockito.when(emailManager.emailExists(Mockito.eq("some"))).thenReturn(false);
Mockito.when(emailManager.emailExists(Mockito.eq("orcid"))).thenReturn(false);
Map<String, String> map = new HashMap<String, String>();
map.put("ids", "ids");
map.put("or", "or");
map.put("emails", "emails");
map.put("to", "to");
map.put("test", "test");
map.put("with", "with");
Mockito.when(emailManager.findOricdIdsByCommaSeparatedEmails(Mockito.anyString())).thenReturn(map);
Mockito.when(profileEntityManager.orcidExists(Mockito.anyString())).thenReturn(true);
Mockito.when(profileEntityManager.orcidExists(Mockito.eq("some"))).thenReturn(false);
Mockito.when(profileEntityManager.orcidExists(Mockito.eq("orcid"))).thenReturn(false);
Mockito.when(profileEntityCacheManager.retrieve(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {
@Override
public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
String ar1 = invocation.getArgument(0);
ProfileEntity p = new ProfileEntity();
p.setId(ar1);
if (ar1.equals("ids") || ar1.equals("or")) {
p.setRecordLocked(false);
} else {
p.setRecordLocked(true);
}
return p;
}
});
Map<String, Set<String>> results = adminController.unlockAccounts(commaSeparatedValues);
assertEquals(2, results.get("notFoundList").size());
assertTrue(results.get("notFoundList").contains("some"));
assertTrue(results.get("notFoundList").contains("orcid"));
assertEquals(2, results.get("alreadyUnlockedList").size());
assertTrue(results.get("alreadyUnlockedList").contains("ids"));
assertTrue(results.get("alreadyUnlockedList").contains("or"));
assertEquals(4, results.get("unlockSuccessfulList").size());
assertTrue(results.get("unlockSuccessfulList").contains("emails"));
assertTrue(results.get("unlockSuccessfulList").contains("to"));
assertTrue(results.get("unlockSuccessfulList").contains("test"));
assertTrue(results.get("unlockSuccessfulList").contains("with"));
Mockito.verify(emailManager, Mockito.times(8)).emailExists(Mockito.anyString());
Mockito.verify(profileEntityManager, Mockito.times(4)).unlockProfile(Mockito.anyString());
}
Aggregations