Skip to content

Commit

Permalink
Fix more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Dec 11, 2024
1 parent 3224dc4 commit 36550bd
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ public Response viewRecord(String orcid) {
Record record = recordManagerReadOnly.getRecord(orcid, filterVersionOfIdentifiers);
orcidSecurityManager.checkAndFilter(orcid, record);
if (record.getPerson() != null) {
emailDomainManager.processProfessionalEmailsForV3API(record.getPerson().getEmails());
sourceUtils.setSourceName(record.getPerson());
}
if (record.getActivitiesSummary() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -84,7 +85,22 @@ public void testViewPersonReadPublic() {
assertNotNull(element);
assertEquals("/0000-0000-0000-0003/person", element.getPath());
Utils.assertIsPublicOrSource(element, "APP-5555555555555555");
fail("TEST EMAILS");
assertNotNull(element.getEmails());
assertEquals(4, element.getEmails().getEmails().size());
List<String> emails = new ArrayList<>();
emails.add("[email protected]");
emails.add("[email protected]");
emails.add("[email protected]");
emails.add("[email protected]");

for(Email e : element.getEmails().getEmails()) {
if(!emails.contains(e.getEmail())) {
fail(e.getEmail() + " is not in the email list");
}
emails.remove(e.getEmail());
}

assertTrue(emails.isEmpty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -102,7 +103,6 @@ public void testViewRecordWrongScope() {
Utils.assertIsPublicOrSource(record.getActivitiesSummary(), SecurityContextTestUtils.DEFAULT_CLIENT_ID);
assertEquals("/0000-0000-0000-0003/person", record.getPerson().getPath());
Utils.assertIsPublicOrSource(record.getPerson(), SecurityContextTestUtils.DEFAULT_CLIENT_ID);

}

@Test
Expand All @@ -116,7 +116,51 @@ public void testViewRecordReadPublic() {
Utils.assertIsPublicOrSource(record.getActivitiesSummary(), "APP-5555555555555555");
assertEquals("/0000-0000-0000-0003/person", record.getPerson().getPath());
Utils.assertIsPublicOrSource(record.getPerson(), "APP-5555555555555555");
fail("TEST EMAILS");
assertNotNull(record.getPerson());
assertNotNull(record.getPerson().getEmails());
assertEquals(4, record.getPerson().getEmails().getEmails().size());
List<String> emails = new ArrayList<>();
emails.add("[email protected]");
emails.add("[email protected]");
emails.add("[email protected]");
emails.add("[email protected]");

for(Email e : record.getPerson().getEmails().getEmails()) {
if(!emails.contains(e.getEmail())) {
fail(e.getEmail() + " is not in the email list");
}
emails.remove(e.getEmail());
}

assertTrue(emails.isEmpty());
}

@Test
public void testViewRecordReadPublic_clientThatIsNotTheSourceOfEmails() {
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555556", ScopePathType.READ_PUBLIC);
Response r = serviceDelegator.viewRecord(ORCID);
Record record = (Record) r.getEntity();
assertNotNull(record);
assertEquals("/0000-0000-0000-0003", record.getPath());
assertEquals("/0000-0000-0000-0003/activities", record.getActivitiesSummary().getPath());
Utils.assertIsPublicOrSource(record.getActivitiesSummary(), "APP-5555555555555556");
assertEquals("/0000-0000-0000-0003/person", record.getPerson().getPath());
Utils.assertIsPublicOrSource(record.getPerson(), "APP-5555555555555556");
assertNotNull(record.getPerson());
assertNotNull(record.getPerson().getEmails());
assertEquals(2, record.getPerson().getEmails().getEmails().size());
List<String> emails = new ArrayList<>();
emails.add("[email protected]");
emails.add("[email protected]");

for(Email e : record.getPerson().getEmails().getEmails()) {
if(!emails.contains(e.getEmail())) {
fail(e.getEmail() + " is not in the email list");
}
emails.remove(e.getEmail());
}

assertTrue(emails.isEmpty());
}

@Test(expected = OrcidUnauthorizedException.class)
Expand Down Expand Up @@ -229,28 +273,23 @@ public void testViewRecord() {
for (Email email : person.getEmails().getEmails()) {
Utils.verifyLastModified(email.getLastModifiedDate());
if (email.getEmail().equals("[email protected]")) {
assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath());
assertNull(email.getSource().getSourceOrcid());
assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath());
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.value(), email.getVisibility().value());
assertEquals("Source Client 1", email.getSource().getSourceName().getContent());
assertEquals("ORCID email validation", email.getSource().getSourceName().getContent());
} else if (email.getEmail().equals("[email protected]")) {
assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath());
assertNull(email.getSource().getSourceOrcid());
assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath());
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED.value(), email.getVisibility().value());
assertEquals("Source Client 1", email.getSource().getSourceName().getContent());
assertEquals("ORCID email validation", email.getSource().getSourceName().getContent());
} else if (email.getEmail().equals("[email protected]")) {
assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath());
assertNull(email.getSource().getSourceOrcid());
assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath());
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE.value(), email.getVisibility().value());
assertEquals("Source Client 1", email.getSource().getSourceName().getContent());
assertEquals("ORCID email validation", email.getSource().getSourceName().getContent());
} else if (email.getEmail().equals("[email protected]")) {
assertEquals("0000-0000-0000-0003", email.getSource().retrieveSourcePath());
assertNotNull(email.getSource().getSourceOrcid());
assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath());
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED.value(), email.getVisibility().value());
assertEquals("Credit Name", email.getSource().getSourceName().getContent());
assertEquals("ORCID email validation", email.getSource().getSourceName().getContent());
} else if (email.getEmail().equals("[email protected]")) {
assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath());
assertNull(email.getSource().getSourceOrcid());
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.value(), email.getVisibility().value());
assertEquals("ORCID email validation", email.getSource().getSourceName().getContent());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -86,7 +87,41 @@ public void testViewEmailsReadPublic() {
Emails element = (Emails) r.getEntity();
assertNotNull(element);
assertEquals("/0000-0000-0000-0003/email", element.getPath());
Utils.assertIsPublicOrSource(element, "APP-5555555555555555");
assertEquals(4, element.getEmails().size());
List<String> emails = new ArrayList<>();
emails.add("[email protected]");
emails.add("[email protected]");
emails.add("[email protected]");
emails.add("[email protected]");

for(Email e : element.getEmails()) {
if(!emails.contains(e.getEmail())) {
fail(e.getEmail() + " is not in the email list");
}
emails.remove(e.getEmail());
}
assertTrue(emails.isEmpty());
}

@Test
public void testViewEmailsReadPublic_ClientNotSourceOfAnyEmail() {
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555556", ScopePathType.READ_PUBLIC);
Response r = serviceDelegator.viewEmails(ORCID);
Emails element = (Emails) r.getEntity();
assertNotNull(element);
assertEquals("/0000-0000-0000-0003/email", element.getPath());
assertEquals(2, element.getEmails().size());
List<String> emails = new ArrayList<>();
emails.add("[email protected]");
emails.add("[email protected]");

for(Email e : element.getEmails()) {
if(!emails.contains(e.getEmail())) {
fail(e.getEmail() + " is not in the email list");
}
emails.remove(e.getEmail());
}
assertTrue(emails.isEmpty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -90,7 +91,46 @@ public void testViewPersonReadPublic() {
assertNotNull(element);
assertEquals("/0000-0000-0000-0003/person", element.getPath());
Utils.assertIsPublicOrSource(element, "APP-5555555555555555");
fail("Process emails");
assertNotNull(element.getEmails());
assertNotNull(element.getEmails().getEmails());
assertEquals(4, element.getEmails().getEmails().size());
List<String> emails = new ArrayList<>();
emails.add("[email protected]");
emails.add("[email protected]");
emails.add("[email protected]");
emails.add("[email protected]");

for(Email e : element.getEmails().getEmails()) {
if(!emails.contains(e.getEmail())) {
fail(e.getEmail() + " is not in the email list");
}
emails.remove(e.getEmail());
}
assertTrue(emails.isEmpty());
}

@Test
public void testViewPersonReadPublic_ClientNotSourceOfAnyEmail() {
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555556", ScopePathType.READ_PUBLIC);
Response r = serviceDelegator.viewPerson(ORCID);
Person element = (Person) r.getEntity();
assertNotNull(element);
assertEquals("/0000-0000-0000-0003/person", element.getPath());
Utils.assertIsPublicOrSource(element, "APP-5555555555555556");
assertNotNull(element.getEmails());
assertNotNull(element.getEmails().getEmails());
assertEquals(2, element.getEmails().getEmails().size());
List<String> emails = new ArrayList<>();
emails.add("[email protected]");
emails.add("[email protected]");

for(Email e : element.getEmails().getEmails()) {
if(!emails.contains(e.getEmail())) {
fail(e.getEmail() + " is not in the email list");
}
emails.remove(e.getEmail());
}
assertTrue(emails.isEmpty());
}

@Test
Expand Down
Loading

0 comments on commit 36550bd

Please sign in to comment.