Skip to content

Commit

Permalink
More unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Dec 12, 2024
1 parent 7d111db commit c6f9f0f
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 120 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package org.orcid.api.memberV2.server.delegator;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -40,6 +35,8 @@
import org.orcid.test.helper.Utils;
import org.springframework.test.context.ContextConfiguration;

import static org.junit.Assert.*;

@RunWith(OrcidJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:test-orcid-api-web-context.xml" })
public class MemberV2ApiServiceDelegator_EmailsTest extends DBUnitTest {
Expand Down Expand Up @@ -195,15 +192,30 @@ public void testViewEmails() {
}

@Test
public void viewNonProfessionalEmailsOnEmail() {
public void checkSourceOnEmail_EmailEndpointTest() {
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());
Emails emails = (Emails) r.getEntity();
checkEmails(emails);
}

private void checkEmails(Emails emails) {
assertEquals(2, emails.getEmails().size());
for(Email e : emails.getEmails()) {
if(e.getEmail().equals("[email protected]")) {
assertFalse(e.isVerified());
// The source and name on non verified professional email addresses should not change
assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath());
assertEquals("Source Client 1", e.getSource().getSourceName().getContent());
} else if(e.getEmail().equals("[email protected]")) {
assertTrue(e.isVerified());
// The source and name on non professional email addresses should not change
assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath());
assertEquals("Source Client 1", e.getSource().getSourceName().getContent());
} else {
fail("Unexpected email " + e.getEmail());

Check failure on line 217 in orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_EmailsTest.java

View workflow job for this annotation

GitHub Actions / Unit test report for orcid-api-web

org.orcid.api.memberV2.server.delegator.MemberV2ApiServiceDelegator_EmailsTest ► checkSourceOnEmail_EmailEndpointTest

Failed test found in: orcid-api-web/target/surefire-reports/TEST-org.orcid.api.memberV2.server.delegator.MemberV2ApiServiceDelegator_EmailsTest.xml Error: java.lang.AssertionError: Unexpected email [email protected]
Raw output
java.lang.AssertionError: Unexpected email [email protected]
	at org.orcid.api.memberV2.server.delegator.MemberV2ApiServiceDelegator_EmailsTest.checkEmails(MemberV2ApiServiceDelegator_EmailsTest.java:217)
	at org.orcid.api.memberV2.server.delegator.MemberV2ApiServiceDelegator_EmailsTest.checkSourceOnEmail_EmailEndpointTest(MemberV2ApiServiceDelegator_EmailsTest.java:200)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package org.orcid.api.memberV2.server.delegator;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -47,6 +42,8 @@
import org.orcid.test.helper.Utils;
import org.springframework.test.context.ContextConfiguration;

import static org.junit.Assert.*;

@RunWith(OrcidJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:test-orcid-api-web-context.xml" })
public class MemberV2ApiServiceDelegator_ReadPersonTest extends DBUnitTest {
Expand Down Expand Up @@ -636,17 +633,31 @@ private void assertAllPublicButEmails(Person p) {
}

@Test
public void viewNonProfessionalEmailsOnPerson() {
public void checkSourceOnEmail_EmailEndpointTest() {
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());
checkEmails(p.getEmails());
}

private void checkEmails(Emails emails) {
assertEquals(2, emails.getEmails().size());
for(Email e : emails.getEmails()) {
if(e.getEmail().equals("[email protected]")) {
assertFalse(e.isVerified());
// The source and name on non verified professional email addresses should not change
assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath());
assertEquals("Source Client 1", e.getSource().getSourceName().getContent());
} else if(e.getEmail().equals("[email protected]")) {
assertTrue(e.isVerified());
// The source and name on non professional email addresses should not change
assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath());
assertEquals("Source Client 1", e.getSource().getSourceName().getContent());
} else {
fail("Unexpected email " + e.getEmail());

Check failure on line 659 in orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java

View workflow job for this annotation

GitHub Actions / Unit test report for orcid-api-web

org.orcid.api.memberV2.server.delegator.MemberV2ApiServiceDelegator_ReadPersonTest ► checkSourceOnEmail_EmailEndpointTest

Failed test found in: orcid-api-web/target/surefire-reports/TEST-org.orcid.api.memberV2.server.delegator.MemberV2ApiServiceDelegator_ReadPersonTest.xml Error: java.lang.AssertionError: Unexpected email [email protected]
Raw output
java.lang.AssertionError: Unexpected email [email protected]
	at org.orcid.api.memberV2.server.delegator.MemberV2ApiServiceDelegator_ReadPersonTest.checkEmails(MemberV2ApiServiceDelegator_ReadPersonTest.java:659)
	at org.orcid.api.memberV2.server.delegator.MemberV2ApiServiceDelegator_ReadPersonTest.checkSourceOnEmail_EmailEndpointTest(MemberV2ApiServiceDelegator_ReadPersonTest.java:642)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package org.orcid.api.memberV2.server.delegator;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -66,6 +60,8 @@
import org.orcid.test.helper.Utils;
import org.springframework.test.context.ContextConfiguration;

import static org.junit.Assert.*;

@RunWith(OrcidJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:test-orcid-api-web-context.xml" })
public class MemberV2ApiServiceDelegator_ReadRecordTest extends DBUnitTest {
Expand Down Expand Up @@ -1161,18 +1157,32 @@ private void assertAllPublicButEmails(Person p) {
}

@Test
public void viewNonProfessionalEmailsOnRecord() {
public void checkSourceOnEmail_EmailEndpointTest() {
String orcid = "0000-0000-0000-0001";
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED);
Response r = serviceDelegator.viewRecord(orcid);
Record record = (Record) r.getEntity();
assertNotNull(record);
assertNotNull(record.getPerson());
assertNotNull(record.getPerson().getEmails());
assertEquals(1, record.getPerson().getEmails().getEmails().size());
Email e = record.getPerson().getEmails().getEmails().get(0);
assertTrue(e.isVerified());
assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath());
assertEquals("Source Client 1", e.getSource().getSourceName().getContent());
checkEmails(record.getPerson().getEmails());
}

private void checkEmails(Emails emails) {
assertEquals(2, emails.getEmails().size());
for(Email e : emails.getEmails()) {
if(e.getEmail().equals("[email protected]")) {
assertFalse(e.isVerified());
// The source and name on non verified professional email addresses should not change
assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath());
assertEquals("Source Client 1", e.getSource().getSourceName().getContent());
} else if(e.getEmail().equals("[email protected]")) {
assertTrue(e.isVerified());
// The source and name on non professional email addresses should not change
assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath());
assertEquals("Source Client 1", e.getSource().getSourceName().getContent());
} else {
fail("Unexpected email " + e.getEmail());

Check failure on line 1184 in orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java

View workflow job for this annotation

GitHub Actions / Unit test report for orcid-api-web

org.orcid.api.memberV2.server.delegator.MemberV2ApiServiceDelegator_ReadRecordTest ► checkSourceOnEmail_EmailEndpointTest

Failed test found in: orcid-api-web/target/surefire-reports/TEST-org.orcid.api.memberV2.server.delegator.MemberV2ApiServiceDelegator_ReadRecordTest.xml Error: java.lang.AssertionError: Unexpected email [email protected]
Raw output
java.lang.AssertionError: Unexpected email [email protected]
	at org.orcid.api.memberV2.server.delegator.MemberV2ApiServiceDelegator_ReadRecordTest.checkEmails(MemberV2ApiServiceDelegator_ReadRecordTest.java:1184)
	at org.orcid.api.memberV2.server.delegator.MemberV2ApiServiceDelegator_ReadRecordTest.checkSourceOnEmail_EmailEndpointTest(MemberV2ApiServiceDelegator_ReadRecordTest.java:1167)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -199,15 +195,30 @@ public void testViewEmails() {
}

@Test
public void viewNonProfessionalEmailsOnEmail() {
public void checkSourceOnEmail_EmailEndpointTest() {
String orcid = "0000-0000-0000-0001";
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED);
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.EMAIL_READ_PRIVATE);
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());
Emails emails = (Emails) r.getEntity();
checkEmails(emails);
}

private void checkEmails(Emails emails) {
assertEquals(2, emails.getEmails().size());
for(Email e : emails.getEmails()) {
if(e.getEmail().equals("[email protected]")) {
assertTrue(e.isVerified());
// The source and name on non verified professional email addresses should not change
assertEquals("0000-0000-0000-0000", e.getSource().retrieveSourcePath());
assertEquals("ORCID email validation", e.getSource().getSourceName().getContent());
} else if(e.getEmail().equals("[email protected]")) {
assertTrue(e.isVerified());
// The source and name on non professional email addresses should not change
assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath());
assertEquals("Source Client 1", e.getSource().getSourceName().getContent());
} else {
fail("Unexpected email " + e.getEmail());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package org.orcid.api.memberV3.server.delegator;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -28,6 +23,8 @@
import org.orcid.test.helper.v3.Utils;
import org.springframework.test.context.ContextConfiguration;

import static org.junit.Assert.*;

@RunWith(OrcidJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:test-orcid-api-web-context.xml" })
public class MemberV3ApiServiceDelegator_ReadPersonTest extends DBUnitTest {
Expand Down Expand Up @@ -643,17 +640,31 @@ private void assertAllPublicButEmails(Person p) {
}

@Test
public void viewNonProfessionalEmailsOnPerson() {
public void checkSourceOnEmail_PersonEndpointTest() {
String orcid = "0000-0000-0000-0001";
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED);
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.EMAIL_READ_PRIVATE);
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());
checkEmails(p.getEmails());
}

private void checkEmails(Emails emails) {
assertEquals(2, emails.getEmails().size());
for(Email e : emails.getEmails()) {
if(e.getEmail().equals("[email protected]")) {
assertTrue(e.isVerified());
// The source and name on non verified professional email addresses should not change
assertEquals("0000-0000-0000-0000", e.getSource().retrieveSourcePath());

Check failure on line 658 in orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java

View workflow job for this annotation

GitHub Actions / Unit test report for orcid-api-web

org.orcid.api.memberV3.server.delegator.MemberV3ApiServiceDelegator_ReadPersonTest ► checkSourceOnEmail_PersonEndpointTest

Failed test found in: orcid-api-web/target/surefire-reports/TEST-org.orcid.api.memberV3.server.delegator.MemberV3ApiServiceDelegator_ReadPersonTest.xml Error: org.junit.ComparisonFailure: expected:<[0000-0000-0000-0000]> but was:<[APP-5555555555555555]>
Raw output
org.junit.ComparisonFailure: expected:<[0000-0000-0000-0000]> but was:<[APP-5555555555555555]>
	at org.orcid.api.memberV3.server.delegator.MemberV3ApiServiceDelegator_ReadPersonTest.checkEmails(MemberV3ApiServiceDelegator_ReadPersonTest.java:658)
	at org.orcid.api.memberV3.server.delegator.MemberV3ApiServiceDelegator_ReadPersonTest.checkSourceOnEmail_PersonEndpointTest(MemberV3ApiServiceDelegator_ReadPersonTest.java:649)
assertEquals("ORCID email validation", e.getSource().getSourceName().getContent());
} else if(e.getEmail().equals("[email protected]")) {
assertTrue(e.isVerified());
// The source and name on non professional email addresses should not change
assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath());
assertEquals("Source Client 1", e.getSource().getSourceName().getContent());
} else {
fail("Unexpected email " + e.getEmail());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1348,18 +1348,32 @@ private void assertAllPublicButEmails(Person p) {
}

@Test
public void viewNonProfessionalEmailsOnRecord() {
public void checkSourceOnEmail_RecordEndpointTest() {
String orcid = "0000-0000-0000-0001";
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED);
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.EMAIL_READ_PRIVATE);
Response r = serviceDelegator.viewRecord(orcid);
Record record = (Record) r.getEntity();
assertNotNull(record);
assertNotNull(record.getPerson());
assertNotNull(record.getPerson().getEmails());
assertEquals(1, record.getPerson().getEmails().getEmails().size());
Email e = record.getPerson().getEmails().getEmails().get(0);
assertTrue(e.isVerified());
assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath());
assertEquals("Source Client 1", e.getSource().getSourceName().getContent());
checkEmails(record.getPerson().getEmails());
}

private void checkEmails(Emails emails) {
assertEquals(2, emails.getEmails().size());
for(Email e : emails.getEmails()) {
if(e.getEmail().equals("[email protected]")) {
assertTrue(e.isVerified());
// The source and name on non verified professional email addresses should not change
assertEquals("0000-0000-0000-0000", e.getSource().retrieveSourcePath());
assertEquals("ORCID email validation", e.getSource().getSourceName().getContent());
} else if(e.getEmail().equals("[email protected]")) {
assertTrue(e.isVerified());
// The source and name on non professional email addresses should not change
assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath());
assertEquals("Source Client 1", e.getSource().getSourceName().getContent());
} else {
fail("Unexpected email " + e.getEmail());
}
}
}
}
Loading

0 comments on commit c6f9f0f

Please sign in to comment.