diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_EmailsTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_EmailsTest.java index f97c2b1db6..9018163ff8 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_EmailsTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_EmailsTest.java @@ -193,4 +193,17 @@ public void testViewEmails() { assertEquals(true, email.isVerified()); assertEquals(false, email.isPrimary()); } + + @Test + public void viewNonProfessionalEmailsOnEmail() { + String orcid = "0000-0000-0000-0001"; + SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED); + Response r = serviceDelegator.viewEmails(orcid); + Emails p = (Emails) r.getEntity(); + assertEquals(1, p.getEmails().size()); + Email e = p.getEmails().get(0); + assertTrue(e.isVerified()); + assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath()); + assertEquals("Source Client 1", e.getSource().getSourceName().getContent()); + } } diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java index 4db7a22551..3f933958ba 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java @@ -634,4 +634,19 @@ private void assertAllPublicButEmails(Person p) { assertEquals(Long.valueOf(13), ru.getResearcherUrls().get(0).getPutCode()); assertEquals(Visibility.PUBLIC, ru.getResearcherUrls().get(0).getVisibility()); } + + @Test + public void viewNonProfessionalEmailsOnPerson() { + String orcid = "0000-0000-0000-0001"; + SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED); + Response r = serviceDelegator.viewPerson(orcid); + Person p = (Person) r.getEntity(); + assertNotNull(p); + assertNotNull(p.getEmails()); + assertEquals(1, p.getEmails().getEmails().size()); + Email e = p.getEmails().getEmails().get(0); + assertTrue(e.isVerified()); + assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath()); + assertEquals("Source Client 1", e.getSource().getSourceName().getContent()); + } } diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java index b58dc4ddf2..9450dd0ddf 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java @@ -197,4 +197,17 @@ public void testViewEmails() { assertEquals(true, email.isVerified()); assertEquals(false, email.isPrimary()); } + + @Test + public void viewNonProfessionalEmailsOnEmail() { + String orcid = "0000-0000-0000-0001"; + SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED); + Response r = serviceDelegator.viewEmails(orcid); + Emails p = (Emails) r.getEntity(); + assertEquals(1, p.getEmails().size()); + Email e = p.getEmails().get(0); + assertTrue(e.isVerified()); + assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath()); + assertEquals("Source Client 1", e.getSource().getSourceName().getContent()); + } } diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java index 91cbb44db9..bf30ef59d2 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java @@ -22,32 +22,7 @@ import org.orcid.jaxb.model.groupid_v2.GroupIdRecord; import org.orcid.jaxb.model.message.ScopePathType; import org.orcid.jaxb.model.v3.release.common.Visibility; -import org.orcid.jaxb.model.v3.release.record.Address; -import org.orcid.jaxb.model.v3.release.record.Addresses; -import org.orcid.jaxb.model.v3.release.record.Biography; -import org.orcid.jaxb.model.v3.release.record.Distinction; -import org.orcid.jaxb.model.v3.release.record.Education; -import org.orcid.jaxb.model.v3.release.record.Email; -import org.orcid.jaxb.model.v3.release.record.Emails; -import org.orcid.jaxb.model.v3.release.record.Employment; -import org.orcid.jaxb.model.v3.release.record.Funding; -import org.orcid.jaxb.model.v3.release.record.InvitedPosition; -import org.orcid.jaxb.model.v3.release.record.Keyword; -import org.orcid.jaxb.model.v3.release.record.Keywords; -import org.orcid.jaxb.model.v3.release.record.Membership; -import org.orcid.jaxb.model.v3.release.record.OtherName; -import org.orcid.jaxb.model.v3.release.record.OtherNames; -import org.orcid.jaxb.model.v3.release.record.PeerReview; -import org.orcid.jaxb.model.v3.release.record.Person; -import org.orcid.jaxb.model.v3.release.record.PersonExternalIdentifier; -import org.orcid.jaxb.model.v3.release.record.PersonExternalIdentifiers; -import org.orcid.jaxb.model.v3.release.record.Qualification; -import org.orcid.jaxb.model.v3.release.record.ResearchResource; -import org.orcid.jaxb.model.v3.release.record.ResearcherUrl; -import org.orcid.jaxb.model.v3.release.record.ResearcherUrls; -import org.orcid.jaxb.model.v3.release.record.Service; -import org.orcid.jaxb.model.v3.release.record.Work; -import org.orcid.jaxb.model.v3.release.record.WorkBulk; +import org.orcid.jaxb.model.v3.release.record.*; import org.orcid.test.DBUnitTest; import org.orcid.test.OrcidJUnit4ClassRunner; import org.orcid.test.helper.v3.Utils; @@ -666,4 +641,19 @@ private void assertAllPublicButEmails(Person p) { assertEquals(Long.valueOf(13), ru.getResearcherUrls().get(0).getPutCode()); assertEquals(Visibility.PUBLIC, ru.getResearcherUrls().get(0).getVisibility()); } + + @Test + public void viewNonProfessionalEmailsOnPerson() { + String orcid = "0000-0000-0000-0001"; + SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED); + Response r = serviceDelegator.viewPerson(orcid); + Person p = (Person) r.getEntity(); + assertNotNull(p); + assertNotNull(p.getEmails()); + assertEquals(1, p.getEmails().getEmails().size()); + Email e = p.getEmails().getEmails().get(0); + assertTrue(e.isVerified()); + assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath()); + assertEquals("Source Client 1", e.getSource().getSourceName().getContent()); + } } diff --git a/orcid-pub-web/src/test/java/org/orcid/api/publicV2/server/PublicV2ApiServiceDelegatorTest.java b/orcid-pub-web/src/test/java/org/orcid/api/publicV2/server/PublicV2ApiServiceDelegatorTest.java index c05f202e3f..dddcab36ae 100644 --- a/orcid-pub-web/src/test/java/org/orcid/api/publicV2/server/PublicV2ApiServiceDelegatorTest.java +++ b/orcid-pub-web/src/test/java/org/orcid/api/publicV2/server/PublicV2ApiServiceDelegatorTest.java @@ -107,13 +107,13 @@ public class PublicV2ApiServiceDelegatorTest extends DBUnitTest { private final String ORCID = "0000-0000-0000-0003"; private String deactivatedUserOrcid = "0000-0000-0000-0007"; - + @Resource(name = "publicV2ApiServiceDelegator") PublicV2ApiServiceDelegator serviceDelegator; @Resource SchemaOrgMBWriterV2 writerV2; - + @BeforeClass public static void initDBUnitData() throws Exception { initDBUnitData(DATA_FILES); @@ -184,7 +184,7 @@ public void testViewBulkWorks() { assertNotNull(workBulk); assertNotNull(workBulk.getBulk()); assertEquals(3, workBulk.getBulk().size()); - assertTrue(workBulk.getBulk().get(0) instanceof Work); + assertTrue(workBulk.getBulk().get(0) instanceof Work); assertTrue(workBulk.getBulk().get(1) instanceof OrcidError); assertTrue(workBulk.getBulk().get(2) instanceof OrcidError); Work work = (Work) workBulk.getBulk().get(0); @@ -223,7 +223,7 @@ public void testViewFunding() { assertEquals("APP-5555555555555555", funding.getSource().retrieveSourcePath()); assertNotNull(funding.getContributors().getContributor().get(0).getContributorOrcid()); assertEquals("0000-0000-0000-0000", funding.getContributors().getContributor().get(0).getContributorOrcid().getPath()); - assertNull(funding.getContributors().getContributor().get(0).getCreditName()); + assertNull(funding.getContributors().getContributor().get(0).getCreditName()); } @Test @@ -466,7 +466,7 @@ public void testViewExternalIdentifiers() { assertNotNull(extIds.getLastModifiedDate().getValue()); assertEquals("/0000-0000-0000-0003/external-identifiers", extIds.getPath()); assertEquals(3, extIds.getExternalIdentifiers().size()); - + PersonExternalIdentifier extId = extIds.getExternalIdentifiers().get(0); assertNotNull(extId); assertNotNull(extId.getLastModifiedDate()); @@ -478,7 +478,7 @@ public void testViewExternalIdentifiers() { assertEquals(Visibility.PUBLIC.value(), extId.getVisibility().value()); assertEquals("/0000-0000-0000-0003/external-identifiers/19", extId.getPath()); assertEquals("APP-5555555555555558", extId.getSource().retrieveSourcePath()); - + extId = extIds.getExternalIdentifiers().get(1); assertNotNull(extId); assertNotNull(extId.getLastModifiedDate()); @@ -490,7 +490,7 @@ public void testViewExternalIdentifiers() { assertEquals(Visibility.PUBLIC.value(), extId.getVisibility().value()); assertEquals("/0000-0000-0000-0003/external-identifiers/18", extId.getPath()); assertEquals("0000-0000-0000-0003", extId.getSource().retrieveSourcePath()); - + extId = extIds.getExternalIdentifiers().get(2); assertNotNull(extId); assertNotNull(extId.getLastModifiedDate()); @@ -1184,11 +1184,11 @@ public void testSearchByQuery() { result.setOrcidIdentifier(new OrcidIdentifier("some-orcid-id")); search.getResults().add(result); OrcidSearchManager orcidSearchManager = Mockito.mock(OrcidSearchManagerImpl.class); - Mockito.when(orcidSearchManager.findOrcidIds(Matchers.>> any())).thenReturn(search); + Mockito.when(orcidSearchManager.findOrcidIds(Matchers.>>any())).thenReturn(search); PublicV2ApiServiceDelegatorImpl delegator = new PublicV2ApiServiceDelegatorImpl(); ReflectionTestUtils.setField(delegator, "orcidSearchManager", orcidSearchManager); - + OrcidSecurityManager orcidSecurityManager = Mockito.mock(OrcidSecurityManagerImpl.class); Mockito.when(orcidSecurityManager.getClientIdFromAPIRequest()).thenReturn(null); ReflectionTestUtils.setField(delegator, "orcidSecurityManager", orcidSecurityManager); @@ -1222,7 +1222,7 @@ public void testSearchByQueryIllegalStart() { LocaleManager localeManager = Mockito.mock(LocaleManagerImpl.class); Mockito.when(localeManager.resolveMessage(Mockito.anyString())).thenReturn("a message"); - + OrcidSecurityManager orcidSecurityManager = Mockito.mock(OrcidSecurityManagerImpl.class); Mockito.when(orcidSecurityManager.getClientIdFromAPIRequest()).thenReturn(null); @@ -1242,7 +1242,7 @@ public void testSearchByQueryLegalStart() { OrcidSearchManager orcidSearchManager = Mockito.mock(OrcidSearchManagerImpl.class); Mockito.when(orcidSearchManager.findOrcidIds(Mockito.anyMap())).thenReturn(new Search()); - + OrcidSecurityManager orcidSecurityManager = Mockito.mock(OrcidSecurityManagerImpl.class); Mockito.when(orcidSecurityManager.getClientIdFromAPIRequest()).thenReturn(null); @@ -1317,9 +1317,9 @@ private void validatePerson(Person person) { assertNotNull(person.getExternalIdentifiers().getLastModifiedDate().getValue()); assertEquals("/0000-0000-0000-0003/external-identifiers", person.getExternalIdentifiers().getPath()); assertEquals(3, person.getExternalIdentifiers().getExternalIdentifiers().size()); - + PersonExternalIdentifiers extIds = person.getExternalIdentifiers(); - + assertNotNull(extIds); PersonExternalIdentifier extId = extIds.getExternalIdentifiers().get(0); assertNotNull(extId); @@ -1332,7 +1332,7 @@ private void validatePerson(Person person) { assertEquals(Visibility.PUBLIC.value(), extId.getVisibility().value()); assertEquals("/0000-0000-0000-0003/external-identifiers/19", extId.getPath()); assertEquals("APP-5555555555555558", extId.getSource().retrieveSourcePath()); - + extId = extIds.getExternalIdentifiers().get(1); assertNotNull(extId); assertNotNull(extId.getLastModifiedDate()); @@ -1344,7 +1344,7 @@ private void validatePerson(Person person) { assertEquals(Visibility.PUBLIC.value(), extId.getVisibility().value()); assertEquals("/0000-0000-0000-0003/external-identifiers/18", extId.getPath()); assertEquals("0000-0000-0000-0003", extId.getSource().retrieveSourcePath()); - + extId = extIds.getExternalIdentifiers().get(2); assertNotNull(extId); assertNotNull(extId.getLastModifiedDate()); @@ -1356,7 +1356,7 @@ private void validatePerson(Person person) { assertEquals(Visibility.PUBLIC.value(), extId.getVisibility().value()); assertEquals("/0000-0000-0000-0003/external-identifiers/13", extId.getPath()); assertEquals("APP-5555555555555555", extId.getSource().retrieveSourcePath()); - + assertNotNull(person.getKeywords()); assertNotNull(person.getKeywords().getLastModifiedDate()); assertNotNull(person.getKeywords().getLastModifiedDate().getValue()); @@ -1506,9 +1506,9 @@ private void validateRecord(Record record) { OrcidIdentifier id = record.getOrcidIdentifier(); assertEquals("0000-0000-0000-0003", id.getPath()); } - + @Test - public void testSchemaOrgMBWriterV2() throws WebApplicationException, IOException{ + public void testSchemaOrgMBWriterV2() throws WebApplicationException, IOException { Response response = serviceDelegator.viewRecord(ORCID); Record record = (Record) response.getEntity(); ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -1517,22 +1517,22 @@ public void testSchemaOrgMBWriterV2() throws WebApplicationException, IOExceptio objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); SchemaOrgDocument doc = objectMapper.readerFor(SchemaOrgDocument.class).readValue(out.toString()); assertTrue(doc.id.endsWith(ORCID)); - assertEquals("Person",doc.type); - assertEquals("http://schema.org",doc.context); - assertEquals("Credit Name",doc.name); - assertEquals("Given Names",doc.givenName); - assertEquals("Family Name",doc.familyName); - assertEquals("Other Name PUBLIC",doc.alternateName.get(0)); - assertEquals("WDB",doc.alumniOf.iterator().next().identifier.iterator().next().propertyID); - assertEquals("WDB",doc.affiliation.iterator().next().identifier.iterator().next().propertyID); + assertEquals("Person", doc.type); + assertEquals("http://schema.org", doc.context); + assertEquals("Credit Name", doc.name); + assertEquals("Given Names", doc.givenName); + assertEquals("Family Name", doc.familyName); + assertEquals("Other Name PUBLIC", doc.alternateName.get(0)); + assertEquals("WDB", doc.alumniOf.iterator().next().identifier.iterator().next().propertyID); + assertEquals("WDB", doc.affiliation.iterator().next().identifier.iterator().next().propertyID); Set fundingIds = Sets.newHashSet(); - for (SchemaOrgExternalID i: doc.worksAndFunding.funder.iterator().next().identifier) + for (SchemaOrgExternalID i : doc.worksAndFunding.funder.iterator().next().identifier) fundingIds.add(i.propertyID); - assertEquals(Sets.newHashSet("WDB","grant_number"),fundingIds); - assertEquals("PUBLIC",doc.worksAndFunding.creator.iterator().next().name); - assertEquals("http://www.researcherurl.com?id=13",doc.url.get(0)); - assertEquals("self_public_user_obo_type",doc.identifier.get(0).propertyID); - assertEquals( "self_public_user_obo_ref",doc.identifier.get(0).value); + assertEquals(Sets.newHashSet("WDB", "grant_number"), fundingIds); + assertEquals("PUBLIC", doc.worksAndFunding.creator.iterator().next().name); + assertEquals("http://www.researcherurl.com?id=13", doc.url.get(0)); + assertEquals("self_public_user_obo_type", doc.identifier.get(0).propertyID); + assertEquals("self_public_user_obo_ref", doc.identifier.get(0).value); } @Test @@ -1550,4 +1550,32 @@ public void viewNonProfessionalEmailsOnRecord() { assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath()); assertEquals("Source Client 1", e.getSource().getSourceName().getContent()); } -} + + @Test + public void viewNonProfessionalEmailsOnPerson() { + String orcid = "0000-0000-0000-0001"; + SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED); + Response r = serviceDelegator.viewPerson(orcid); + Person p = (Person) r.getEntity(); + assertNotNull(p); + assertNotNull(p.getEmails()); + assertEquals(1, p.getEmails().getEmails().size()); + Email e = p.getEmails().getEmails().get(0); + assertTrue(e.isVerified()); + assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath()); + assertEquals("Source Client 1", e.getSource().getSourceName().getContent()); + } + + @Test + public void viewNonProfessionalEmailsOnEmail() { + String orcid = "0000-0000-0000-0001"; + SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED); + Response r = serviceDelegator.viewEmails(orcid); + Emails p = (Emails) r.getEntity(); + assertEquals(1, p.getEmails().size()); + Email e = p.getEmails().get(0); + assertTrue(e.isVerified()); + assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath()); + assertEquals("Source Client 1", e.getSource().getSourceName().getContent()); + } +} \ No newline at end of file diff --git a/orcid-pub-web/src/test/java/org/orcid/api/publicV3/server/PublicV3ApiServiceDelegatorTest.java b/orcid-pub-web/src/test/java/org/orcid/api/publicV3/server/PublicV3ApiServiceDelegatorTest.java index 7d38cc1633..1180079b75 100644 --- a/orcid-pub-web/src/test/java/org/orcid/api/publicV3/server/PublicV3ApiServiceDelegatorTest.java +++ b/orcid-pub-web/src/test/java/org/orcid/api/publicV3/server/PublicV3ApiServiceDelegatorTest.java @@ -2203,4 +2203,32 @@ public void viewNonProfessionalEmailsOnRecord() { assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath()); assertEquals("Source Client 1", e.getSource().getSourceName().getContent()); } + + @Test + public void viewNonProfessionalEmailsOnPerson() { + String orcid = "0000-0000-0000-0001"; + SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED); + Response r = serviceDelegator.viewPerson(orcid); + Person p = (Person) r.getEntity(); + assertNotNull(p); + assertNotNull(p.getEmails()); + assertEquals(1, p.getEmails().getEmails().size()); + Email e = p.getEmails().getEmails().get(0); + assertTrue(e.isVerified()); + assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath()); + assertEquals("Source Client 1", e.getSource().getSourceName().getContent()); + } + + @Test + public void viewNonProfessionalEmailsOnEmail() { + String orcid = "0000-0000-0000-0001"; + SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED); + Response r = serviceDelegator.viewEmails(orcid); + Emails p = (Emails) r.getEntity(); + assertEquals(1, p.getEmails().size()); + Email e = p.getEmails().get(0); + assertTrue(e.isVerified()); + assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath()); + assertEquals("Source Client 1", e.getSource().getSourceName().getContent()); + } } diff --git a/orcid-test/src/main/resources/data/ProfileEntityData.xml b/orcid-test/src/main/resources/data/ProfileEntityData.xml index 11c74d195b..8c17e3ac1c 100644 --- a/orcid-test/src/main/resources/data/ProfileEntityData.xml +++ b/orcid-test/src/main/resources/data/ProfileEntityData.xml @@ -1813,7 +1813,20 @@ client_source_id="APP-5555555555555555" date_created="2016-01-01 00:00:00.00" last_modified="2016-01-01 00:00:00.00" - /> + /> + + - + /> +