Skip to content

Commit

Permalink
Unit tests done
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Apr 25, 2024
1 parent 423cb84 commit af59781
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public RecordSummaryPojo getRecordSummaryPojo(String orcid) {

if(recordSummary.getFundings() != null) {
pojo.setSelfAssertedFunds(recordSummary.getFundings().getSelfAssertedCount());
pojo.setValidatedFunds(recordSummary.getFundings().getValidatdeCount());
pojo.setValidatedFunds(recordSummary.getFundings().getValidatedCount());
}

if(recordSummary.getPeerReviews() != null) {
Expand All @@ -224,7 +224,7 @@ public RecordSummaryPojo getRecordSummaryPojo(String orcid) {

if(recordSummary.getWorks() != null) {
pojo.setSelfAssertedWorks(recordSummary.getWorks().getSelfAssertedCount());
pojo.setValidatedWorks(recordSummary.getWorks().getValidatdeCount());
pojo.setValidatedWorks(recordSummary.getWorks().getValidatedCount());
}

return pojo;
Expand Down Expand Up @@ -264,6 +264,7 @@ public void generateAffiliationsSummary(RecordSummary recordSummary, String orci
if(!employmentsTop3.isEmpty()) {
e.setEmployments(employmentsTop3);
}
recordSummary.setEmployments(e);

// PROFESIONAL ACTIVITIES
List<AffiliationGroup<org.orcid.jaxb.model.v3.release.record.summary.AffiliationSummary>> profesionalActivitesGroups = new ArrayList<>();
Expand Down Expand Up @@ -312,6 +313,7 @@ public void generateAffiliationsSummary(RecordSummary recordSummary, String orci
if(!professionalActivitiesTop3.isEmpty()) {
pa.setProfessionalActivities(professionalActivitiesTop3);
}
recordSummary.setProfessionalActivities(pa);
}

public void generateExternalIdentifiersSummary(RecordSummary recordSummary, String orcid) {
Expand Down Expand Up @@ -354,6 +356,7 @@ public void generateWorksSummary(RecordSummary recordSummary, String orcid) {
Works worksModel = new Works();
worksModel.setSelfAssertedCount(validAndSelfAssertedStats.getRight());
worksModel.setValidatedCount(validAndSelfAssertedStats.getLeft());
recordSummary.setWorks(worksModel);
}

public void generateFundingSummary(RecordSummary recordSummary, String orcid) {
Expand All @@ -362,7 +365,8 @@ public void generateFundingSummary(RecordSummary recordSummary, String orcid) {

Fundings fundingsModel = new Fundings();
fundingsModel.setSelfAssertedCount(validAndSelfAssertedStats.getRight());
fundingsModel.setValidatedCount(validAndSelfAssertedStats.getLeft());
fundingsModel.setValidatedCount(validAndSelfAssertedStats.getLeft());
recordSummary.setFundings(fundingsModel);
}

public void generatePeerReviewSummary(RecordSummary recordSummary, String orcid) {
Expand All @@ -383,7 +387,8 @@ public void generatePeerReviewSummary(RecordSummary recordSummary, String orcid)
PeerReviews pr = new PeerReviews();
pr.setPeerReviewPublicationGrants(peerReviewMinimizedSummaryList.size());
pr.setSelfAssertedCount(selfAssertedPeerReviews);
pr.setTotal(totalReviewsCount);
pr.setTotal(totalReviewsCount);
recordSummary.setPeerReviews(pr);
}

private Pair<Integer, Integer> calculateSelfAssertedAndValidated(GroupsContainer c, String orcid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void setSelfAssertedCount(Integer selfAssertedCount) {
this.selfAssertedCount = selfAssertedCount;
}

public Integer getValidatdeCount() {
public Integer getValidatedCount() {
return validatedCount;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.orcid.core.common.manager;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

Expand All @@ -27,6 +28,7 @@
import org.orcid.core.manager.v3.read_only.ProfileFundingManagerReadOnly;
import org.orcid.core.manager.v3.read_only.RecordManagerReadOnly;
import org.orcid.core.manager.v3.read_only.RecordNameManagerReadOnly;
import org.orcid.core.model.ProfessionalActivity;
import org.orcid.core.model.RecordSummary;
import org.orcid.jaxb.model.v3.release.common.CreatedDate;
import org.orcid.jaxb.model.v3.release.common.CreditName;
Expand Down Expand Up @@ -145,6 +147,7 @@ public void setUp() {
// Set metadata
OrcidIdentifier oi = new OrcidIdentifier();
oi.setUri("https://test.orcid.org/0000-0000-0000-0000");
oi.setHost("test.orcid.org");
Mockito.when(recordManagerReadOnlyMock.getOrcidIdentifier(Mockito.eq(ORCID))).thenReturn(oi);
ReflectionTestUtils.setField(manager, "recordManagerReadOnly", recordManagerReadOnlyMock);

Expand All @@ -157,6 +160,9 @@ public void setUp() {
@Test
public void generateAffiliationsSummaryTest() {
RecordSummary rs = new RecordSummary();
Map<AffiliationType, List<AffiliationGroup<AffiliationSummary>>> affiliations = generateAffiliations();
Mockito.when(affiliationsManagerReadOnlyMock.getGroupedAffiliations(Mockito.eq(ORCID), Mockito.eq(true))).thenReturn(affiliations);

manager.generateAffiliationsSummary(rs, ORCID);
assertNotNull(rs.getEmployments());
assertEquals(Integer.valueOf(3), rs.getEmployments().getCount());
Expand Down Expand Up @@ -203,7 +209,6 @@ public void generateAffiliationsSummary_EmploymentOnlyTest() {
manager.generateAffiliationsSummary(rs, ORCID);
assertEquals(Integer.valueOf(3), rs.getEmployments().getCount());
assertEquals(3, rs.getEmployments().getEmployments().size());

assertEquals(Integer.valueOf(0), rs.getProfessionalActivities().getCount());
assertNull(rs.getProfessionalActivities().getProfessionalActivities());
}
Expand Down Expand Up @@ -243,6 +248,9 @@ public void generateAffiliationsSummary_InvitedPositionOnlyTest() {
assertNull(rs.getEmployments().getEmployments());
assertEquals(Integer.valueOf(3), rs.getProfessionalActivities().getCount());
assertEquals(3, rs.getProfessionalActivities().getProfessionalActivities().size());
for(ProfessionalActivity pa : rs.getProfessionalActivities().getProfessionalActivities()) {
assertEquals(AffiliationType.INVITED_POSITION.name(), pa.getType());
}
}

@Test
Expand All @@ -256,15 +264,18 @@ public void generateAffiliationsSummary_ProfessionalActivitiesOnlyTest() {
assertEquals(Integer.valueOf(0), rs.getEmployments().getCount());
assertNull(rs.getEmployments().getEmployments());
assertEquals(Integer.valueOf(12), rs.getProfessionalActivities().getCount());
assertEquals(12, rs.getProfessionalActivities().getProfessionalActivities().size());
assertEquals(3, rs.getProfessionalActivities().getProfessionalActivities().size());
for(ProfessionalActivity pa : rs.getProfessionalActivities().getProfessionalActivities()) {
assertNotEquals(AffiliationType.EMPLOYMENT, pa.getType());
}
}

@Test
public void generateExternalIdentifiersSummaryTest() {
RecordSummary rs = new RecordSummary();
manager.generateExternalIdentifiersSummary(rs, ORCID);
assertEquals(1, rs.getExternalIdentifiers().getExternalIdentifiers().size());
assertEquals("0", rs.getExternalIdentifiers().getExternalIdentifiers().get(0).getPutCode());
assertEquals(Long.valueOf(0), rs.getExternalIdentifiers().getExternalIdentifiers().get(0).getPutCode());
assertEquals("0000", rs.getExternalIdentifiers().getExternalIdentifiers().get(0).getExternalIdValue());
}

Expand All @@ -291,7 +302,7 @@ public void generateWorksSummaryTest() {
RecordSummary rs = new RecordSummary();
manager.generateWorksSummary(rs, ORCID);
assertEquals(Integer.valueOf(0), rs.getWorks().getSelfAssertedCount());
assertEquals(Integer.valueOf(3), rs.getWorks().getValidatdeCount());
assertEquals(Integer.valueOf(3), rs.getWorks().getValidatedCount());
}

@Test
Expand All @@ -310,7 +321,7 @@ public void generateWorksSummary_OboValidatedTest() {

manager.generateWorksSummary(rs, ORCID);
assertEquals(Integer.valueOf(0), rs.getWorks().getSelfAssertedCount());
assertEquals(Integer.valueOf(3), rs.getWorks().getValidatdeCount());
assertEquals(Integer.valueOf(3), rs.getWorks().getValidatedCount());
}

@Test
Expand All @@ -328,7 +339,7 @@ public void generateWorksSummary_SelfAssertedOnlyTest() {

manager.generateWorksSummary(rs, ORCID);
assertEquals(Integer.valueOf(3), rs.getWorks().getSelfAssertedCount());
assertEquals(Integer.valueOf(0), rs.getWorks().getValidatdeCount());
assertEquals(Integer.valueOf(0), rs.getWorks().getValidatedCount());
}

@Test
Expand All @@ -347,15 +358,15 @@ public void generateWorksSummary_OboSelfAssertedOnlyTest() {

manager.generateWorksSummary(rs, ORCID);
assertEquals(Integer.valueOf(3), rs.getWorks().getSelfAssertedCount());
assertEquals(Integer.valueOf(0), rs.getWorks().getValidatdeCount());
assertEquals(Integer.valueOf(0), rs.getWorks().getValidatedCount());
}

@Test
public void generateFundingSummaryTest() {
RecordSummary rs = new RecordSummary();
manager.generateFundingSummary(rs, ORCID);
assertEquals(Integer.valueOf(0), rs.getFundings().getSelfAssertedCount());
assertEquals(Integer.valueOf(3), rs.getFundings().getValidatdeCount());
assertEquals(Integer.valueOf(3), rs.getFundings().getValidatedCount());
}

@Test
Expand All @@ -374,7 +385,7 @@ public void generateFundingSummary_OboValidatedTest() {

manager.generateFundingSummary(rs, ORCID);
assertEquals(Integer.valueOf(0), rs.getFundings().getSelfAssertedCount());
assertEquals(Integer.valueOf(3), rs.getFundings().getValidatdeCount());
assertEquals(Integer.valueOf(3), rs.getFundings().getValidatedCount());
}

@Test
Expand All @@ -392,7 +403,7 @@ public void generateFundingSummary_SelfAssertedTest() {

manager.generateFundingSummary(rs, ORCID);
assertEquals(Integer.valueOf(3), rs.getFundings().getSelfAssertedCount());
assertEquals(Integer.valueOf(0), rs.getFundings().getValidatdeCount());;
assertEquals(Integer.valueOf(0), rs.getFundings().getValidatedCount());;
}

@Test
Expand All @@ -411,7 +422,7 @@ public void generateFundingSummary_OboSelfAssertedTest() {

manager.generateFundingSummary(rs, ORCID);
assertEquals(Integer.valueOf(3), rs.getFundings().getSelfAssertedCount());
assertEquals(Integer.valueOf(0), rs.getFundings().getValidatdeCount());
assertEquals(Integer.valueOf(0), rs.getFundings().getValidatedCount());
}

@Test
Expand Down Expand Up @@ -439,9 +450,9 @@ public void generatePeerReviewSummary_OboValidatedTest() {
manager.generatePeerReviewSummary(rs, ORCID);
// Each peer review group have 1 self asserted peer review and 1 user obo asserted peer review
// So, we have 3 groups = 6 self asserted peer reviews in total
assertEquals(0, rs.getSelfAssertedPeerReviews());
assertEquals(4, rs.getPeerReviewPublicationGrants());
assertEquals(16, rs.getPeerReviewsTotal());
assertEquals(Integer.valueOf(0), rs.getPeerReviews().getSelfAssertedCount());
assertEquals(Integer.valueOf(4), rs.getPeerReviews().getPeerReviewPublicationGrants());
assertEquals(Integer.valueOf(16), rs.getPeerReviews().getTotal());
}

@Test
Expand All @@ -458,9 +469,9 @@ public void generatePeerReviewSummary_SelfAssertedTest() {
manager.generatePeerReviewSummary(rs, ORCID);
// Each peer review group have 1 self asserted peer review and 1 user obo asserted peer review
// So, we have 3 groups = 6 self asserted peer reviews in total
assertEquals(4, rs.getSelfAssertedPeerReviews());
assertEquals(4, rs.getPeerReviewPublicationGrants());
assertEquals(16, rs.getPeerReviewsTotal());
assertEquals(Integer.valueOf(4), rs.getPeerReviews().getSelfAssertedCount());
assertEquals(Integer.valueOf(4), rs.getPeerReviews().getPeerReviewPublicationGrants());
assertEquals(Integer.valueOf(16), rs.getPeerReviews().getTotal());
}

@Test
Expand All @@ -477,9 +488,9 @@ public void generatePeerReviewSummary_Test() {
manager.generatePeerReviewSummary(rs, ORCID);
// Each peer review group have 1 self asserted peer review and 1 user obo asserted peer review
// So, we have 3 groups = 6 self asserted peer reviews in total
assertEquals(4, rs.getSelfAssertedPeerReviews());
assertEquals(4, rs.getPeerReviewPublicationGrants());
assertEquals(16, rs.getPeerReviewsTotal());
assertEquals(Integer.valueOf(4), rs.getPeerReviews().getSelfAssertedCount());
assertEquals(Integer.valueOf(4), rs.getPeerReviews().getPeerReviewPublicationGrants());
assertEquals(Integer.valueOf(16), rs.getPeerReviews().getTotal());
}

/**
Expand All @@ -490,26 +501,37 @@ public void generatePeerReviewSummary_Test() {
@Test
public void getSummaryTest() {
RecordSummary rs = manager.getRecordSummary(ORCID);
assertEquals("https://test.orcid.org/" + ORCID, rs.getOrcid());
assertEquals("2024-01-01", rs.getCreation());
assertEquals("2024-12-31", rs.getLastModified());
assertEquals("test.orcid.org", rs.getOrcidIdentifier().getHost());
assertEquals("https://test.orcid.org/" + ORCID, rs.getOrcidIdentifier().getUri());
assertEquals(2024, rs.getCreatedDate().getValue().getYear());
assertEquals(1, rs.getCreatedDate().getValue().getMonth());
assertEquals(1, rs.getCreatedDate().getValue().getDay());


assertEquals(2024, rs.getLastModifiedDate().getValue().getYear());
assertEquals(12, rs.getLastModifiedDate().getValue().getMonth());
assertEquals(31, rs.getLastModifiedDate().getValue().getDay());

// Affiliations
assertEquals(3, rs.getEmploymentAffiliations().size());
assertEquals(3, rs.getEmploymentAffiliationsCount());
assertEquals(3, rs.getProfessionalActivities().size());
assertEquals(12, rs.getProfessionalActivitiesCount());
assertEquals(Integer.valueOf(3), rs.getEmployments().getCount());
assertEquals(3, rs.getEmployments().getEmployments().size());
assertEquals(Integer.valueOf(12), rs.getProfessionalActivities().getCount());
assertEquals(3, rs.getProfessionalActivities().getProfessionalActivities().size());

// External identifiers
assertEquals(1, rs.getExternalIdentifiers().size());
assertEquals(1, rs.getExternalIdentifiers().getExternalIdentifiers().size());
// Works
assertEquals(0, rs.getSelfAssertedWorks());
assertEquals(3, rs.getValidatedWorks());
assertEquals(Integer.valueOf(0), rs.getWorks().getSelfAssertedCount());
assertEquals(Integer.valueOf(3), rs.getWorks().getValidatedCount());

// Funding
assertEquals(0, rs.getSelfAssertedFunds());
assertEquals(3, rs.getValidatedFunds());
assertEquals(Integer.valueOf(0), rs.getFundings().getSelfAssertedCount());
assertEquals(Integer.valueOf(3), rs.getFundings().getValidatedCount());

// Peer review
assertEquals(2, rs.getSelfAssertedPeerReviews());
assertEquals(4, rs.getPeerReviewPublicationGrants());
assertEquals(16, rs.getPeerReviewsTotal());
assertEquals(Integer.valueOf(2), rs.getPeerReviews().getSelfAssertedCount());
assertEquals(Integer.valueOf(4), rs.getPeerReviews().getPeerReviewPublicationGrants());
assertEquals(Integer.valueOf(16), rs.getPeerReviews().getTotal());
}

/**
Expand Down Expand Up @@ -559,7 +581,7 @@ private List<AffiliationGroup<AffiliationSummary>> getAffiliations(AffiliationTy
AffiliationGroup<AffiliationSummary> group = new AffiliationGroup<AffiliationSummary>();

for(int j = 0; j < 3; j++) {
AffiliationSummary summary = getAffiliationSummary(affiliationType, CLIENT1, Long.valueOf(j));
AffiliationSummary summary = getAffiliationSummary(affiliationType, affiliationType.name() + "-" + j, CLIENT1, Long.valueOf(j));
group.getActivities().add(summary);
}

Expand All @@ -568,7 +590,7 @@ private List<AffiliationGroup<AffiliationSummary>> getAffiliations(AffiliationTy
return affiliationGroups;
}

private AffiliationSummary getAffiliationSummary(AffiliationType affiliationType, String affiliationName, Long putCode) {
private AffiliationSummary getAffiliationSummary(AffiliationType affiliationType, String affiliationName, String sourceId, Long putCode) {
AffiliationSummary summary = null;
switch(affiliationType) {
case DISTINCTION:
Expand Down Expand Up @@ -600,6 +622,9 @@ private AffiliationSummary getAffiliationSummary(AffiliationType affiliationType
summary.setPutCode(putCode);
summary.setDisplayIndex(String.valueOf(putCode));
summary.setEndDate(new FuzzyDate(new Year(2012), null, null));
Source source = new Source();
source.setSourceClientId(new SourceClientId(sourceId));
summary.setSource(source);
return summary;
}

Expand Down

0 comments on commit af59781

Please sign in to comment.