-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
59 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
import static org.mockito.Mockito.when; | ||
import static org.mockito.internal.verification.VerificationModeFactory.times; | ||
|
||
import java.lang.annotation.Target; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
|
@@ -44,13 +43,10 @@ | |
import org.orcid.core.manager.v3.read_only.*; | ||
import org.orcid.core.oauth.OrcidProfileUserDetails; | ||
import org.orcid.core.security.OrcidWebRole; | ||
import org.orcid.jaxb.model.v3.release.common.Source; | ||
import org.orcid.jaxb.model.v3.release.common.*; | ||
import org.orcid.utils.DateUtils; | ||
import org.orcid.core.utils.v3.OrcidIdentifierUtils; | ||
import org.orcid.frontend.email.RecordEmailSender; | ||
import org.orcid.jaxb.model.v3.release.common.CreditName; | ||
import org.orcid.jaxb.model.v3.release.common.OrcidIdentifier; | ||
import org.orcid.jaxb.model.v3.release.common.Visibility; | ||
import org.orcid.jaxb.model.v3.release.record.Biography; | ||
import org.orcid.jaxb.model.v3.release.record.Email; | ||
import org.orcid.jaxb.model.v3.release.record.Emails; | ||
|
@@ -84,6 +80,7 @@ public class ManageProfileControllerTest { | |
private static final String USER_ORCID = "0000-0000-0000-0001"; | ||
private static final String DEPRECATED_USER_ORCID = "0000-0000-0000-0002"; | ||
private static final String DEPRECATED_USER_ORCID_URL = "https://localhost:8443/0000-0000-0000-0002"; | ||
private static final String USER_CREDIT_NAME = "Credit Name"; | ||
|
||
@Mock | ||
private ProfileEntityCacheManager mockProfileEntityCacheManager; | ||
|
@@ -227,8 +224,16 @@ public Emails answer(InvocationOnMock invocation) throws Throwable { | |
Email email2 = new Email(); | ||
email2.setEmail(invocation.getArgument(0) + "[email protected]"); | ||
email2.setSource(new Source()); | ||
email2.getSource().setSourceName(new SourceName(USER_CREDIT_NAME)); | ||
email2.setVisibility(Visibility.PUBLIC); | ||
emails.getEmails().add(email2); | ||
|
||
Email email3 = new Email(); | ||
email3.setEmail(invocation.getArgument(0) + "[email protected]"); | ||
email3.setSource(new Source()); | ||
email3.getSource().setSourceClientId(new SourceClientId(USER_ORCID)); | ||
email3.setVisibility(Visibility.PUBLIC); | ||
emails.getEmails().add(email3); | ||
return emails; | ||
} | ||
|
||
|
@@ -1156,11 +1161,58 @@ public void testEmptyEmailSource() { | |
MockHttpSession mockSession = new MockHttpSession(); | ||
mockRequest.setSession(mockSession); | ||
org.orcid.pojo.ajaxForm.Emails emails = controller.getEmails(mockRequest); | ||
assertEquals(emails.getEmails().get(0).getSource(), USER_ORCID); | ||
assertNull(emails.getEmails().get(0).getSourceName()); | ||
|
||
assertEquals(3, emails.getEmails().size()); | ||
|
||
org.orcid.pojo.ajaxForm.Email email1 = emails.getEmails().get(0); | ||
assertEquals(email1.getValue(), USER_ORCID + "[email protected]"); | ||
assertEquals(email1.getSource(), USER_ORCID); | ||
assertNull(email1.getSourceName()); | ||
|
||
org.orcid.pojo.ajaxForm.Email email2 = emails.getEmails().get(1); | ||
assertEquals(email2.getValue(), USER_ORCID + "[email protected]"); | ||
assertNull(email2.getSource()); | ||
assertEquals(email2.getSourceName(), USER_CREDIT_NAME); | ||
} | ||
|
||
@Test | ||
public void testEmailSourceWithSourceName() { | ||
SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID)); | ||
when(mockProfileEmailDomainManagerReadOnly.getEmailDomains(eq(USER_ORCID))).thenReturn(null); | ||
when(mockEmailManagerReadOnly.getPublicEmails(eq(USER_ORCID))).thenReturn(new Emails()); | ||
MockHttpServletRequest mockRequest = new MockHttpServletRequest(); | ||
MockHttpSession mockSession = new MockHttpSession(); | ||
mockRequest.setSession(mockSession); | ||
org.orcid.pojo.ajaxForm.Emails emails = controller.getEmails(mockRequest); | ||
|
||
assertEquals(3, emails.getEmails().size()); | ||
|
||
org.orcid.pojo.ajaxForm.Email email2 = emails.getEmails().get(1); | ||
assertEquals(email2.getValue(), USER_ORCID + "[email protected]"); | ||
assertNull(email2.getSource()); | ||
assertEquals(email2.getSourceName(), USER_CREDIT_NAME); | ||
} | ||
|
||
@Test | ||
public void testEmailSourceWithSourceId() { | ||
SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID)); | ||
when(mockProfileEmailDomainManagerReadOnly.getEmailDomains(eq(USER_ORCID))).thenReturn(null); | ||
when(mockEmailManagerReadOnly.getPublicEmails(eq(USER_ORCID))).thenReturn(new Emails()); | ||
MockHttpServletRequest mockRequest = new MockHttpServletRequest(); | ||
MockHttpSession mockSession = new MockHttpSession(); | ||
mockRequest.setSession(mockSession); | ||
org.orcid.pojo.ajaxForm.Emails emails = controller.getEmails(mockRequest); | ||
|
||
assertEquals(3, emails.getEmails().size()); | ||
|
||
org.orcid.pojo.ajaxForm.Email email3 = emails.getEmails().get(2); | ||
assertEquals(email3.getValue(), USER_ORCID + "[email protected]"); | ||
assertNull(email3.getSourceName()); | ||
assertEquals(email3.getSource(), USER_ORCID); | ||
} | ||
|
||
|
||
|
||
protected Authentication getAuthentication(String orcid) { | ||
List<OrcidWebRole> roles = Arrays.asList(OrcidWebRole.ROLE_USER); | ||
OrcidProfileUserDetails details = new OrcidProfileUserDetails(orcid, "[email protected]", null, roles); | ||
|