diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegatorMockTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegatorMockTest.java new file mode 100644 index 00000000000..ae666717cfe --- /dev/null +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegatorMockTest.java @@ -0,0 +1,173 @@ +package org.orcid.api.memberV3.server.delegator; + +import org.junit.Before; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.orcid.api.common.util.ApiUtils; +import org.orcid.api.memberV3.server.delegator.impl.MemberV3ApiServiceDelegatorImpl; +import org.orcid.core.common.manager.EmailDomainManager; +import org.orcid.core.common.manager.SummaryManager; +import org.orcid.core.exception.OrcidCoreExceptionMapper; +import org.orcid.core.locale.LocaleManager; +import org.orcid.core.manager.StatusManager; +import org.orcid.core.manager.impl.OrcidUrlManager; +import org.orcid.core.manager.read_only.ClientDetailsManagerReadOnly; +import org.orcid.core.manager.v3.*; +import org.orcid.core.manager.v3.read_only.*; +import org.orcid.core.utils.SourceEntityUtils; +import org.orcid.core.utils.v3.ContributorUtils; +import org.orcid.core.utils.v3.SourceUtils; +import org.orcid.jaxb.model.groupid_v2.GroupIdRecord; +import org.orcid.jaxb.model.v3.release.record.*; +import org.springframework.context.MessageSource; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public abstract class MemberV3ApiServiceDelegatorMockTest { + + @Mock + protected WorkManager workManager; + + @Mock + protected ProfileFundingManager profileFundingManager; + + @Mock + protected ProfileEntityManager profileEntityManager; + + @Mock + protected AffiliationsManager affiliationsManager; + + @Mock + protected PeerReviewManager peerReviewManager; + + @Mock + protected OrcidSecurityManager orcidSecurityManager; + + @Mock + protected GroupIdRecordManager groupIdRecordManager; + + @Mock + protected LocaleManager localeManager; + + @Mock + protected ResearcherUrlManager researcherUrlManager; + + @Mock + protected OtherNameManager otherNameManager; + + @Mock + protected ExternalIdentifierManager externalIdentifierManager; + + @Mock + protected ProfileKeywordManager profileKeywordManager; + + @Mock + protected AddressManager addressManager; + + @Mock + protected SourceUtils sourceUtils; + + @Mock + protected ContributorUtils contributorUtils; + + @Mock + protected OrcidSearchManager orcidSearchManager; + + @Mock + protected OrcidCoreExceptionMapper orcidCoreExceptionMapper; + + @Mock + protected WorkManagerReadOnly workManagerReadOnly; + + @Mock + protected ProfileFundingManagerReadOnly profileFundingManagerReadOnly; + + @Mock + protected AffiliationsManagerReadOnly affiliationsManagerReadOnly; + + @Mock + protected PeerReviewManagerReadOnly peerReviewManagerReadOnly; + + @Mock + protected ActivitiesSummaryManagerReadOnly activitiesSummaryManagerReadOnly; + + @Mock + protected ResearchResourceManager researchResourceManager; + + @Mock + protected ResearchResourceManagerReadOnly researchResourceManagerReadOnly; + + @Mock + protected ResearcherUrlManagerReadOnly researcherUrlManagerReadOnly; + + @Mock + protected OtherNameManagerReadOnly otherNameManagerReadOnly; + + @Mock + protected EmailManagerReadOnly emailManagerReadOnly; + + @Mock + protected ExternalIdentifierManagerReadOnly externalIdentifierManagerReadOnly; + + @Mock + protected PersonalDetailsManagerReadOnly personalDetailsManagerReadOnly; + + @Mock + protected ProfileKeywordManagerReadOnly profileKeywordManagerReadOnly; + + @Mock + protected AddressManagerReadOnly addressManagerReadOnly; + + @Mock + protected BiographyManagerReadOnly biographyManagerReadOnly; + + @Mock + protected PersonDetailsManagerReadOnly personDetailsManagerReadOnly; + + @Mock + protected RecordManagerReadOnly recordManagerReadOnly; + + @Mock + protected GroupIdRecordManagerReadOnly groupIdRecordManagerReadOnly; + + @Mock + protected ClientDetailsManagerReadOnly clientDetailsManagerReadOnly; + + @Mock + protected ClientManagerReadOnly clientManagerReadOnly; + + @Mock + protected MessageSource messageSource; + + @Mock + protected StatusManager statusManager; + + @Mock + protected SourceManager sourceManager; + + @Mock + protected ApiUtils apiUtils; + + @Mock + protected OrcidUrlManager orcidUrlManager; + + @Mock + protected SummaryManager summaryManager; + + @Mock + protected EmailDomainManager emailDomainManager; + + @Mock + protected SourceEntityUtils sourceEntityUtils; + + @InjectMocks + protected MemberV3ApiServiceDelegatorImpl serviceDelegator; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } +} diff --git a/orcid-core/src/test/java/org/orcid/core/manager/impl/BibtexManagerTest.java b/orcid-core/src/test/java/org/orcid/core/manager/impl/BibtexManagerTest.java index fdf786defef..abb7a62eef7 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/impl/BibtexManagerTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/impl/BibtexManagerTest.java @@ -1,92 +1,151 @@ package org.orcid.core.manager.impl; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; -import javax.annotation.Resource; - import org.junit.Assert; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; import org.mockito.Mock; -import org.orcid.core.BaseTest; -import org.orcid.core.manager.BibtexManager; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +import org.orcid.core.manager.ActivitiesSummaryManager; import org.orcid.core.manager.DOIManager; +import org.orcid.core.manager.WorkManager; +import org.orcid.core.manager.read_only.RecordNameManagerReadOnly; +import org.orcid.jaxb.model.common_v2.PublicationDate; import org.orcid.jaxb.model.common_v2.Title; +import org.orcid.jaxb.model.common_v2.Year; +import org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary; +import org.orcid.jaxb.model.record.summary_v2.WorkGroup; +import org.orcid.jaxb.model.record.summary_v2.WorkSummary; +import org.orcid.jaxb.model.record.summary_v2.Works; import org.orcid.jaxb.model.record_v2.Citation; import org.orcid.jaxb.model.record_v2.CitationType; import org.orcid.jaxb.model.record_v2.ExternalID; import org.orcid.jaxb.model.record_v2.ExternalIDs; +import org.orcid.jaxb.model.record_v2.Relationship; import org.orcid.jaxb.model.record_v2.Work; import org.orcid.jaxb.model.record_v2.WorkTitle; import org.orcid.jaxb.model.record_v2.WorkType; -import org.orcid.test.OrcidJUnit4ClassRunner; -import org.orcid.test.TargetProxyHelper; -import org.springframework.test.context.ContextConfiguration; -@RunWith(OrcidJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "classpath:test-orcid-core-context.xml" }) -public class BibtexManagerTest extends BaseTest { - private static final List DATA_FILES = Arrays.asList("/data/SourceClientDetailsEntityData.xml", - "/data/ProfileEntityData.xml", "/data/ClientDetailsEntityData.xml", "/data/WorksEntityData.xml", "/data/RecordNameEntityData.xml"); +@RunWith(MockitoJUnitRunner.class) +public class BibtexManagerTest { private static final String ORCID = "0000-0000-0000-0003"; - - @Resource - private BibtexManager bibtexManager; - + + @InjectMocks + private BibtexManagerImpl bibtexManager; + + @Mock + private ActivitiesSummaryManager activitiesManager; + + @Mock + private WorkManager workManager; + @Mock private DOIManager doiManager; - - @BeforeClass - public static void initDBUnitData() throws Exception { - initDBUnitData(DATA_FILES); - - } - + + @Mock + private RecordNameManagerReadOnly recordNameManagerReadOnly; + @Before - public void before(){ - TargetProxyHelper.injectIntoProxy(bibtexManager, "doiManager", doiManager); + public void before() { + MockitoAnnotations.initMocks(this); + when(recordNameManagerReadOnly.fetchDisplayableCreditName(eq(ORCID))).thenReturn("Credit Name"); } - + @Test - public void testGenerateBibtex(){ + public void testGenerateBibtex() { + ActivitiesSummary summary = new ActivitiesSummary(); + Works works = new Works(); + List groups = new ArrayList<>(); + + // Work 15: SELF PRIVATE + WorkGroup group15 = new WorkGroup(); + WorkSummary summary15 = new WorkSummary(); + summary15.setPutCode(15L); + group15.getWorkSummary().add(summary15); + groups.add(group15); + + // Work 14: SELF LIMITED + WorkGroup group14 = new WorkGroup(); + WorkSummary summary14 = new WorkSummary(); + summary14.setPutCode(14L); + group14.getWorkSummary().add(summary14); + groups.add(group14); + + works.getWorkGroup().addAll(groups); + summary.setWorks(works); + + when(activitiesManager.getActivitiesSummary(eq(ORCID))).thenReturn(summary); + + Work work15 = createWork(15L, "SELF PRIVATE", "5"); + Work work14 = createWork(14L, "SELF LIMITED", "4"); + + when(workManager.getWork(eq(ORCID), eq(15L))).thenReturn(work15); + when(workManager.getWork(eq(ORCID), eq(14L))).thenReturn(work14); + String bib = bibtexManager.generateBibtexReferenceList(ORCID); Assert.assertTrue(bib.startsWith("@article{Credit_Name")); Assert.assertTrue(bib.contains(",\ntitle={SELF PRIVATE},\nauthor={Credit Name},\ndoi={5},\nurl={http://doi.org/5},\nyear={2016}\n}")); Assert.assertTrue(bib.contains(",\ntitle={SELF LIMITED},\nauthor={Credit Name},\ndoi={4},\nurl={http://doi.org/4},\nyear={2016}\n}")); Assert.assertTrue(bib.endsWith("year={2016}\n}")); } - + + private Work createWork(Long putCode, String titleStr, String doiValue) { + Work w = new Work(); + w.setPutCode(putCode); + WorkTitle title = new WorkTitle(); + title.setTitle(new Title(titleStr)); + w.setWorkTitle(title); + w.setWorkType(WorkType.JOURNAL_ARTICLE); + + ExternalIDs ids = new ExternalIDs(); + ExternalID id = new ExternalID(); + id.setType("doi"); + id.setValue(doiValue); + id.setRelationship(Relationship.SELF); + ids.getExternalIdentifier().add(id); + w.setWorkExternalIdentifiers(ids); + + PublicationDate date = new PublicationDate(); + date.setYear(new Year(2016)); + w.setPublicationDate(date); + + return w; + } + @Test - public void testGenerateBibtexForSingleWorkFromCitationField(){ + public void testGenerateBibtexForSingleWorkFromCitationField() { Work w = new Work(); Citation c = new Citation(); c.setWorkCitationType(CitationType.BIBTEX); c.setCitation("HELLO"); w.setWorkCitation(c); String bib = bibtexManager.generateBibtex(ORCID, w); - Assert.assertEquals("HELLO",bib); + Assert.assertEquals("HELLO", bib); } - + @Test - public void testGenerateBibtexForSingleWorkEsaped(){ + public void testGenerateBibtexForSingleWorkEsaped() { Work w = new Work(); WorkTitle title = new WorkTitle(); title.setTitle(new Title("Escapes θ à À È © ë Ö ì")); w.setWorkTitle(title); w.setWorkType(WorkType.JOURNAL_ARTICLE); - w.setPutCode(100l); + w.setPutCode(100L); String bib = bibtexManager.generateBibtex(ORCID, w); - Assert.assertEquals("@article{Credit_Name100,\ntitle={Escapes \\texttheta {\\`a} \\`{A} \\`{E} \\textcopyright {\\\"e} {\\\"O} {\\`i}},\nauthor={Credit Name}\n}",bib); + Assert.assertEquals("@article{Credit_Name100,\ntitle={Escapes \\texttheta {\\`a} \\`{A} \\`{E} \\textcopyright {\\\"e} {\\\"O} {\\`i}},\nauthor={Credit Name}\n}", bib); } - + @Test - public void testDOIManagerIsInvoked(){ + public void testDOIManagerIsInvoked() { when(doiManager.fetchDOIBibtex("111")).thenReturn("OK"); Work w = new Work(); w.setWorkExternalIdentifiers(new ExternalIDs()); @@ -95,6 +154,6 @@ public void testDOIManagerIsInvoked(){ id.setValue("111"); w.getExternalIdentifiers().getExternalIdentifier().add(id); String bib = bibtexManager.generateBibtex(ORCID, w); - Assert.assertEquals("OK",bib); + Assert.assertEquals("OK", bib); } } diff --git a/orcid-core/src/test/java/org/orcid/core/manager/impl/ProfileEntityManagerImplTest.java b/orcid-core/src/test/java/org/orcid/core/manager/impl/ProfileEntityManagerImplTest.java index 90065a85469..e2f9123a971 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/impl/ProfileEntityManagerImplTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/impl/ProfileEntityManagerImplTest.java @@ -3,81 +3,60 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; -import java.util.Arrays; - -import javax.annotation.Resource; - -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.orcid.core.manager.BiographyManager; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.orcid.core.manager.ProfileEntityCacheManager; -import org.orcid.core.manager.ProfileEntityManager; -import org.orcid.core.manager.RecordNameManager; -import org.orcid.core.manager.read_only.EmailManagerReadOnly; -import org.orcid.core.oauth.OrcidOauth2TokenDetailService; -import org.orcid.persistence.dao.UserConnectionDao; +import org.orcid.persistence.dao.ProfileDao; import org.orcid.persistence.jpa.entities.ProfileEntity; -import org.orcid.test.DBUnitTest; -import org.orcid.test.OrcidJUnit4ClassRunner; -import org.springframework.test.context.ContextConfiguration; -/** - * @author: Declan Newman (declan) Date: 10/02/2012 - */ -@RunWith(OrcidJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "classpath:test-orcid-core-context.xml" }) -public class ProfileEntityManagerImplTest extends DBUnitTest { - private static final String CLIENT_ID_1 = "APP-5555555555555555"; - private static final String USER_ORCID = "0000-0000-0000-0001"; - - @Resource - private OrcidOauth2TokenDetailService orcidOauth2TokenDetailService; - - @Resource - private ProfileEntityManager profileEntityManager; - - @Resource(name = "profileEntityCacheManager") +@RunWith(MockitoJUnitRunner.class) +public class ProfileEntityManagerImplTest { + + @InjectMocks + private ProfileEntityManagerImpl profileEntityManager; + + @Mock + private ProfileDao profileDao; + + @Mock private ProfileEntityCacheManager profileEntityCacheManager; - - @Resource - private EmailManagerReadOnly emailManager; - - @Resource - private RecordNameManager recordNameManager; - - @Resource - private BiographyManager biographyManager; - - @Resource - private UserConnectionDao userConnectionDao; - - @BeforeClass - public static void initDBUnitData() throws Exception { - initDBUnitData(Arrays.asList("/data/SourceClientDetailsEntityData.xml", "/data/ProfileEntityData.xml", "/data/RecordNameEntityData.xml", "/data/BiographyEntityData.xml", "/data/ClientDetailsEntityData.xml")); - } - @AfterClass - public static void removeDBUnitData() throws Exception { - removeDBUnitData(Arrays.asList("/data/ClientDetailsEntityData.xml", "/data/RecordNameEntityData.xml", "/data/BiographyEntityData.xml", "/data/ProfileEntityData.xml", "/data/SourceClientDetailsEntityData.xml")); + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + profileEntityManager.setProfileDao(profileDao); } @Test public void testFindByOrcid() throws Exception { String harrysOrcid = "4444-4444-4444-4444"; - ProfileEntity profileEntity = profileEntityCacheManager.retrieve(harrysOrcid); - assertNotNull(profileEntity); - assertEquals(harrysOrcid, profileEntity.getId()); + ProfileEntity profileEntity = new ProfileEntity(harrysOrcid); + when(profileEntityCacheManager.retrieve(harrysOrcid)).thenReturn(profileEntity); + + ProfileEntity result = profileEntityCacheManager.retrieve(harrysOrcid); + assertNotNull(result); + assertEquals(harrysOrcid, result.getId()); } - @Test + @Test public void testReviewProfile() throws Exception { - boolean result = profileEntityManager.reviewProfile("4444-4444-4444-4441"); + String orcid1 = "4444-4444-4444-4441"; + String orcid2 = "4444-4444-4444-4442"; + + when(profileDao.reviewProfile(orcid1)).thenReturn(true); + when(profileDao.unreviewProfile(orcid2)).thenReturn(true); + + boolean result = profileEntityManager.reviewProfile(orcid1); assertTrue(result); - - result = profileEntityManager.unreviewProfile("4444-4444-4444-4442"); - assertTrue(result); - } + + result = profileEntityManager.unreviewProfile(orcid2); + assertTrue(result); + } } diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/AddressEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/AddressEntityMocks.java new file mode 100644 index 00000000000..4429713ba8f --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/AddressEntityMocks.java @@ -0,0 +1,206 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.AddressEntity; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class AddressEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + AddressEntity a1 = new AddressEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), a1); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), a1); + a1.setId(1L); + a1.setIso2Country("US"); + a1.setVisibility("PUBLIC"); + a1.setOrcid("4444-4444-4444-4442"); + a1.setDisplayIndex(0L); + a1.setClientSourceId("APP-5555555555555555"); + MOCKS.put(1L, a1); + + AddressEntity a2 = new AddressEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), a2); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), a2); + a2.setId(2L); + a2.setIso2Country("US"); + a2.setVisibility("PUBLIC"); + a2.setOrcid("4444-4444-4444-4447"); + a2.setDisplayIndex(0L); + a2.setSourceId("4444-4444-4444-4447"); + MOCKS.put(2L, a2); + + AddressEntity a3 = new AddressEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), a3); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), a3); + a3.setId(3L); + a3.setIso2Country("CR"); + a3.setVisibility("LIMITED"); + a3.setOrcid("4444-4444-4444-4447"); + a3.setDisplayIndex(0L); + a3.setClientSourceId("APP-5555555555555555"); + MOCKS.put(3L, a3); + + AddressEntity a4 = new AddressEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), a4); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), a4); + a4.setId(4L); + a4.setIso2Country("CR"); + a4.setVisibility("PRIVATE"); + a4.setOrcid("4444-4444-4444-4447"); + a4.setDisplayIndex(0L); + a4.setClientSourceId("APP-5555555555555555"); + MOCKS.put(4L, a4); + + AddressEntity a5 = new AddressEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), a5); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), a5); + a5.setId(5L); + a5.setIso2Country("GB"); + a5.setVisibility("PRIVATE"); + a5.setOrcid("4444-4444-4444-4447"); + a5.setDisplayIndex(0L); + a5.setSourceId("4444-4444-4444-4447"); + MOCKS.put(5L, a5); + + AddressEntity a6 = new AddressEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), a6); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), a6); + a6.setId(6L); + a6.setIso2Country("GB"); + a6.setVisibility("PRIVATE"); + a6.setOrcid("4444-4444-4444-4499"); + a6.setDisplayIndex(0L); + a6.setClientSourceId("APP-5555555555555555"); + MOCKS.put(6L, a6); + + AddressEntity a7 = new AddressEntity(); + injectDateCreated(parseDate("2016-01-02 15:31:00.00"), a7); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), a7); + a7.setId(7L); + a7.setIso2Country("US"); + a7.setVisibility("PUBLIC"); + a7.setOrcid("4444-4444-4444-4441"); + a7.setDisplayIndex(0L); + a7.setClientSourceId("APP-5555555555555555"); + MOCKS.put(7L, a7); + + AddressEntity a8 = new AddressEntity(); + injectDateCreated(parseDate("2016-01-02 15:31:00.00"), a8); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), a8); + a8.setId(8L); + a8.setIso2Country("US"); + a8.setVisibility("LIMITED"); + a8.setOrcid("4444-4444-4444-4443"); + a8.setDisplayIndex(0L); + a8.setSourceId("4444-4444-4444-4443"); + a8.setClientSourceId("APP-5555555555555555"); + MOCKS.put(8L, a8); + + AddressEntity a9 = new AddressEntity(); + injectDateCreated(parseDate("2016-01-02 15:31:00.00"), a9); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), a9); + a9.setId(9L); + a9.setIso2Country("US"); + a9.setVisibility("PUBLIC"); + a9.setOrcid("0000-0000-0000-0003"); + a9.setDisplayIndex(0L); + a9.setClientSourceId("APP-5555555555555555"); + MOCKS.put(9L, a9); + + AddressEntity a10 = new AddressEntity(); + injectDateCreated(parseDate("2016-01-02 15:31:00.00"), a10); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), a10); + a10.setId(10L); + a10.setIso2Country("CR"); + a10.setVisibility("LIMITED"); + a10.setOrcid("0000-0000-0000-0003"); + a10.setDisplayIndex(1L); + a10.setClientSourceId("APP-5555555555555555"); + MOCKS.put(10L, a10); + + AddressEntity a11 = new AddressEntity(); + injectDateCreated(parseDate("2016-01-02 15:31:00.00"), a11); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), a11); + a11.setId(11L); + a11.setIso2Country("GB"); + a11.setVisibility("PRIVATE"); + a11.setOrcid("0000-0000-0000-0003"); + a11.setDisplayIndex(2L); + a11.setClientSourceId("APP-5555555555555555"); + MOCKS.put(11L, a11); + + AddressEntity a12 = new AddressEntity(); + injectDateCreated(parseDate("2016-01-02 15:31:00.00"), a12); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), a12); + a12.setId(12L); + a12.setIso2Country("MX"); + a12.setVisibility("LIMITED"); + a12.setOrcid("0000-0000-0000-0003"); + a12.setDisplayIndex(3L); + a12.setSourceId("0000-0000-0000-0003"); + MOCKS.put(12L, a12); + + AddressEntity a13 = new AddressEntity(); + injectDateCreated(parseDate("2016-01-02 15:31:00.00"), a13); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), a13); + a13.setId(13L); + a13.setIso2Country("PE"); + a13.setVisibility("PRIVATE"); + a13.setOrcid("0000-0000-0000-0003"); + a13.setDisplayIndex(4L); + a13.setSourceId("0000-0000-0000-0003"); + MOCKS.put(13L, a13); + + AddressEntity a14 = new AddressEntity(); + injectDateCreated(parseDate("2016-01-02 15:31:00.00"), a14); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), a14); + a14.setId(14L); + a14.setIso2Country("US"); + a14.setVisibility("PUBLIC"); + a14.setOrcid("0000-0000-0000-0001"); + a14.setDisplayIndex(4L); + a14.setClientSourceId("APP-5555555555555555"); + MOCKS.put(14L, a14); + + AddressEntity a15 = new AddressEntity(); + injectDateCreated(parseDate("2016-01-02 15:31:00.00"), a15); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), a15); + a15.setId(15L); + a15.setIso2Country("CR"); + a15.setVisibility("LIMITED"); + a15.setOrcid("0000-0000-0000-0001"); + a15.setDisplayIndex(4L); + a15.setClientSourceId("APP-5555555555555555"); + MOCKS.put(15L, a15); + + AddressEntity a16 = new AddressEntity(); + injectDateCreated(parseDate("2016-01-02 15:31:00.00"), a16); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), a16); + a16.setId(16L); + a16.setIso2Country("PE"); + a16.setVisibility("PRIVATE"); + a16.setOrcid("0000-0000-0000-0001"); + a16.setDisplayIndex(4L); + a16.setClientSourceId("APP-5555555555555555"); + MOCKS.put(16L, a16); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static AddressEntity getAddress(Long id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientAuthorisedGrantTypeEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientAuthorisedGrantTypeEntityMocks.java new file mode 100644 index 00000000000..1ed83ce5844 --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientAuthorisedGrantTypeEntityMocks.java @@ -0,0 +1,92 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity; +import org.orcid.persistence.jpa.entities.keys.ClientAuthorisedGrantTypePk; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.text.SimpleDateFormat; +import java.text.ParseException; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class ClientAuthorisedGrantTypeEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + ClientAuthorisedGrantTypeEntity e0 = new ClientAuthorisedGrantTypeEntity(); + injectDateCreated(new Date(), e0); + injectLastModified(new Date(), e0); + ClientAuthorisedGrantTypePk pke0 = new ClientAuthorisedGrantTypePk("APP-5555555555555555", "authorization_code"); + MOCKS.put(pke0, e0); + ClientAuthorisedGrantTypeEntity e1 = new ClientAuthorisedGrantTypeEntity(); + injectDateCreated(new Date(), e1); + injectLastModified(new Date(), e1); + ClientAuthorisedGrantTypePk pke1 = new ClientAuthorisedGrantTypePk("APP-5555555555555555", "client_credentials"); + MOCKS.put(pke1, e1); + ClientAuthorisedGrantTypeEntity e2 = new ClientAuthorisedGrantTypeEntity(); + injectDateCreated(new Date(), e2); + injectLastModified(new Date(), e2); + ClientAuthorisedGrantTypePk pke2 = new ClientAuthorisedGrantTypePk("APP-5555555555555555", "refresh_token"); + MOCKS.put(pke2, e2); + ClientAuthorisedGrantTypeEntity e3 = new ClientAuthorisedGrantTypeEntity(); + injectDateCreated(new Date(), e3); + injectLastModified(new Date(), e3); + ClientAuthorisedGrantTypePk pke3 = new ClientAuthorisedGrantTypePk("APP-5555555555555556", "authorization_code"); + MOCKS.put(pke3, e3); + ClientAuthorisedGrantTypeEntity e4 = new ClientAuthorisedGrantTypeEntity(); + injectDateCreated(new Date(), e4); + injectLastModified(new Date(), e4); + ClientAuthorisedGrantTypePk pke4 = new ClientAuthorisedGrantTypePk("APP-5555555555555556", "client_credentials"); + MOCKS.put(pke4, e4); + ClientAuthorisedGrantTypeEntity e5 = new ClientAuthorisedGrantTypeEntity(); + injectDateCreated(new Date(), e5); + injectLastModified(new Date(), e5); + ClientAuthorisedGrantTypePk pke5 = new ClientAuthorisedGrantTypePk("APP-5555555555555556", "refresh_token"); + MOCKS.put(pke5, e5); + ClientAuthorisedGrantTypeEntity e6 = new ClientAuthorisedGrantTypeEntity(); + injectDateCreated(new Date(), e6); + injectLastModified(new Date(), e6); + ClientAuthorisedGrantTypePk pke6 = new ClientAuthorisedGrantTypePk("APP-5555555555555557", "authorization_code"); + MOCKS.put(pke6, e6); + ClientAuthorisedGrantTypeEntity e7 = new ClientAuthorisedGrantTypeEntity(); + injectDateCreated(new Date(), e7); + injectLastModified(new Date(), e7); + ClientAuthorisedGrantTypePk pke7 = new ClientAuthorisedGrantTypePk("APP-5555555555555557", "client_credentials"); + MOCKS.put(pke7, e7); + ClientAuthorisedGrantTypeEntity e8 = new ClientAuthorisedGrantTypeEntity(); + injectDateCreated(new Date(), e8); + injectLastModified(new Date(), e8); + ClientAuthorisedGrantTypePk pke8 = new ClientAuthorisedGrantTypePk("APP-5555555555555557", "refresh_token"); + MOCKS.put(pke8, e8); + ClientAuthorisedGrantTypeEntity e9 = new ClientAuthorisedGrantTypeEntity(); + injectDateCreated(new Date(), e9); + injectLastModified(new Date(), e9); + ClientAuthorisedGrantTypePk pke9 = new ClientAuthorisedGrantTypePk("APP-5555555555555558", "authorization_code"); + MOCKS.put(pke9, e9); + ClientAuthorisedGrantTypeEntity e10 = new ClientAuthorisedGrantTypeEntity(); + injectDateCreated(new Date(), e10); + injectLastModified(new Date(), e10); + ClientAuthorisedGrantTypePk pke10 = new ClientAuthorisedGrantTypePk("APP-5555555555555558", "client_credentials"); + MOCKS.put(pke10, e10); + ClientAuthorisedGrantTypeEntity e11 = new ClientAuthorisedGrantTypeEntity(); + injectDateCreated(new Date(), e11); + injectLastModified(new Date(), e11); + ClientAuthorisedGrantTypePk pke11 = new ClientAuthorisedGrantTypePk("APP-5555555555555558", "refresh_token"); + MOCKS.put(pke11, e11); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static ClientAuthorisedGrantTypeEntity getClientAuthorisedGrantType(ClientAuthorisedGrantTypePk id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientDetailsEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientDetailsEntityMocks.java new file mode 100644 index 00000000000..46b4e0f6215 --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientDetailsEntityMocks.java @@ -0,0 +1,82 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.ClientDetailsEntity; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.text.SimpleDateFormat; +import java.text.ParseException; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class ClientDetailsEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + ClientDetailsEntity e0 = new ClientDetailsEntity(); + injectDateCreated(parseDate("2012-04-25"), e0); + injectLastModified(parseDate("2012-04-25"), e0); + e0.setId("APP-5555555555555555"); + e0.setClientType("PREMIUM_CREATOR"); + e0.setClientName("Source Client 1"); + e0.setClientDescription("A test source client"); + e0.setClientWebsite("www.5555555555555555.com"); + e0.setGroupProfileId("5555-5555-5555-5558"); + e0.setPersistentTokensEnabled(true); + e0.setAllowAutoDeprecate(true); + e0.setUserOBOEnabled(false); + MOCKS.put("APP-5555555555555555", e0); + ClientDetailsEntity e1 = new ClientDetailsEntity(); + injectDateCreated(parseDate("2012-04-25"), e1); + injectLastModified(parseDate("2012-04-25"), e1); + e1.setId("APP-5555555555555556"); + e1.setClientType("PREMIUM_CREATOR"); + e1.setClientName("Source Client 2"); + e1.setClientDescription("A test source client"); + e1.setClientWebsite("www.5555555555555556.com"); + e1.setGroupProfileId("5555-5555-5555-5558"); + e1.setPersistentTokensEnabled(true); + e1.setAllowAutoDeprecate(false); + e1.setUserOBOEnabled(false); + MOCKS.put("APP-5555555555555556", e1); + ClientDetailsEntity e2 = new ClientDetailsEntity(); + injectDateCreated(parseDate("2012-04-25"), e2); + injectLastModified(parseDate("2012-04-25"), e2); + e2.setId("APP-5555555555555557"); + e2.setClientType("PREMIUM_CREATOR"); + e2.setClientName("Source Client 3"); + e2.setClientDescription("A test source client"); + e2.setClientWebsite("www.5555555555555557.com"); + e2.setGroupProfileId("5555-5555-5555-5558"); + e2.setPersistentTokensEnabled(true); + e2.setAllowAutoDeprecate(true); + e2.setUserOBOEnabled(false); + MOCKS.put("APP-5555555555555557", e2); + ClientDetailsEntity e3 = new ClientDetailsEntity(); + injectDateCreated(parseDate("2012-04-25"), e3); + injectLastModified(parseDate("2012-04-25"), e3); + e3.setId("APP-5555555555555558"); + e3.setClientType("PREMIUM_CREATOR"); + e3.setClientName("Source Client 4"); + e3.setClientDescription("A test source client"); + e3.setClientWebsite("www.5555555555555558.com"); + e3.setGroupProfileId("5555-5555-5555-5558"); + e3.setPersistentTokensEnabled(true); + e3.setAllowAutoDeprecate(true); + e3.setUserOBOEnabled(true); + MOCKS.put("APP-5555555555555558", e3); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static ClientDetailsEntity getClientDetails(String id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientGrantedAuthorityEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientGrantedAuthorityEntityMocks.java new file mode 100644 index 00000000000..c1d2ae2e243 --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientGrantedAuthorityEntityMocks.java @@ -0,0 +1,52 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.ClientGrantedAuthorityEntity; +import org.orcid.persistence.jpa.entities.keys.ClientGrantedAuthorityPk; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.text.SimpleDateFormat; +import java.text.ParseException; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class ClientGrantedAuthorityEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + ClientGrantedAuthorityEntity e0 = new ClientGrantedAuthorityEntity(); + injectDateCreated(new Date(), e0); + injectLastModified(new Date(), e0); + ClientGrantedAuthorityPk pke0 = new ClientGrantedAuthorityPk("APP-5555555555555555", "ROLE_CLIENT"); + MOCKS.put(pke0, e0); + ClientGrantedAuthorityEntity e1 = new ClientGrantedAuthorityEntity(); + injectDateCreated(new Date(), e1); + injectLastModified(new Date(), e1); + ClientGrantedAuthorityPk pke1 = new ClientGrantedAuthorityPk("APP-5555555555555556", "ROLE_CLIENT"); + MOCKS.put(pke1, e1); + ClientGrantedAuthorityEntity e2 = new ClientGrantedAuthorityEntity(); + injectDateCreated(new Date(), e2); + injectLastModified(new Date(), e2); + ClientGrantedAuthorityPk pke2 = new ClientGrantedAuthorityPk("APP-5555555555555557", "ROLE_CLIENT"); + MOCKS.put(pke2, e2); + ClientGrantedAuthorityEntity e3 = new ClientGrantedAuthorityEntity(); + injectDateCreated(new Date(), e3); + injectLastModified(new Date(), e3); + ClientGrantedAuthorityPk pke3 = new ClientGrantedAuthorityPk("APP-5555555555555558", "ROLE_CLIENT"); + MOCKS.put(pke3, e3); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static ClientGrantedAuthorityEntity getClientGrantedAuthority(ClientGrantedAuthorityPk id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientRedirectUriEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientRedirectUriEntityMocks.java new file mode 100644 index 00000000000..c7caca4d768 --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientRedirectUriEntityMocks.java @@ -0,0 +1,57 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.ClientRedirectUriEntity; +import org.orcid.persistence.jpa.entities.keys.ClientRedirectUriPk; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.text.SimpleDateFormat; +import java.text.ParseException; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class ClientRedirectUriEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + ClientRedirectUriEntity e0 = new ClientRedirectUriEntity(); + injectDateCreated(new Date(), e0); + injectLastModified(new Date(), e0); + ClientRedirectUriPk pke0 = new ClientRedirectUriPk("APP-5555555555555555", "http://www.APP-5555555555555555.com/redirect/oauth", "default"); + e0.setPredefinedClientScope("None"); + MOCKS.put(pke0, e0); + ClientRedirectUriEntity e1 = new ClientRedirectUriEntity(); + injectDateCreated(new Date(), e1); + injectLastModified(new Date(), e1); + ClientRedirectUriPk pke1 = new ClientRedirectUriPk("APP-5555555555555555", "http://www.APP-5555555555555555.com/redirect/oauth/institutional_sign_in", "institutional-sign-in"); + e1.setPredefinedClientScope("/authenticate"); + MOCKS.put(pke1, e1); + ClientRedirectUriEntity e2 = new ClientRedirectUriEntity(); + injectDateCreated(new Date(), e2); + injectLastModified(new Date(), e2); + ClientRedirectUriPk pke2 = new ClientRedirectUriPk("APP-5555555555555557", "http://www.APP-5555555555555557.com/redirect/oauth", "default"); + e2.setPredefinedClientScope("None"); + MOCKS.put(pke2, e2); + ClientRedirectUriEntity e3 = new ClientRedirectUriEntity(); + injectDateCreated(new Date(), e3); + injectLastModified(new Date(), e3); + ClientRedirectUriPk pke3 = new ClientRedirectUriPk("APP-5555555555555558", "http://www.APP-5555555555555558.com/redirect/oauth", "default"); + e3.setPredefinedClientScope("None"); + MOCKS.put(pke3, e3); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static ClientRedirectUriEntity getClientRedirectUri(ClientRedirectUriPk id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } + +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientResourceIdEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientResourceIdEntityMocks.java new file mode 100644 index 00000000000..764789c26a1 --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientResourceIdEntityMocks.java @@ -0,0 +1,53 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.ClientResourceIdEntity; +import org.orcid.persistence.jpa.entities.keys.ClientResourceIdPk; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.text.SimpleDateFormat; +import java.text.ParseException; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class ClientResourceIdEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + ClientResourceIdEntity e0 = new ClientResourceIdEntity(); + injectDateCreated(new Date(), e0); + injectLastModified(new Date(), e0); + ClientResourceIdPk pke0 = new ClientResourceIdPk("APP-5555555555555555", "orcid"); + MOCKS.put(pke0, e0); + ClientResourceIdEntity e1 = new ClientResourceIdEntity(); + injectDateCreated(new Date(), e1); + injectLastModified(new Date(), e1); + ClientResourceIdPk pke1 = new ClientResourceIdPk("APP-5555555555555556", "orcid"); + MOCKS.put(pke1, e1); + ClientResourceIdEntity e2 = new ClientResourceIdEntity(); + injectDateCreated(new Date(), e2); + injectLastModified(new Date(), e2); + ClientResourceIdPk pke2 = new ClientResourceIdPk("APP-5555555555555557", "orcid"); + MOCKS.put(pke2, e2); + ClientResourceIdEntity e3 = new ClientResourceIdEntity(); + injectDateCreated(new Date(), e3); + injectLastModified(new Date(), e3); + ClientResourceIdPk pke3 = new ClientResourceIdPk("APP-5555555555555558", "orcid"); + MOCKS.put(pke3, e3); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static ClientResourceIdEntity getClientResourceId(ClientResourceIdPk id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } + +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientScopeEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientScopeEntityMocks.java new file mode 100644 index 00000000000..bb66c0ed266 --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientScopeEntityMocks.java @@ -0,0 +1,398 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.ClientScopeEntity; +import org.orcid.persistence.jpa.entities.keys.ClientScopePk; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.text.SimpleDateFormat; +import java.text.ParseException; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class ClientScopeEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + ClientScopeEntity e0 = new ClientScopeEntity(); + injectDateCreated(new Date(), e0); + injectLastModified(new Date(), e0); + ClientScopePk pke0 = new ClientScopePk("APP-5555555555555555", "/webhook"); + MOCKS.put(pke0, e0); + ClientScopeEntity e1 = new ClientScopeEntity(); + injectDateCreated(new Date(), e1); + injectLastModified(new Date(), e1); + ClientScopePk pke1 = new ClientScopePk("APP-5555555555555555", "/read-public"); + MOCKS.put(pke1, e1); + ClientScopeEntity e2 = new ClientScopeEntity(); + injectDateCreated(new Date(), e2); + injectLastModified(new Date(), e2); + ClientScopePk pke2 = new ClientScopePk("APP-5555555555555555", "/orcid-profile/create"); + MOCKS.put(pke2, e2); + ClientScopeEntity e3 = new ClientScopeEntity(); + injectDateCreated(new Date(), e3); + injectLastModified(new Date(), e3); + ClientScopePk pke3 = new ClientScopePk("APP-5555555555555555", "/orcid-bio/read-limited"); + MOCKS.put(pke3, e3); + ClientScopeEntity e4 = new ClientScopeEntity(); + injectDateCreated(new Date(), e4); + injectLastModified(new Date(), e4); + ClientScopePk pke4 = new ClientScopePk("APP-5555555555555555", "/orcid-bio/update"); + MOCKS.put(pke4, e4); + ClientScopeEntity e5 = new ClientScopeEntity(); + injectDateCreated(new Date(), e5); + injectLastModified(new Date(), e5); + ClientScopePk pke5 = new ClientScopePk("APP-5555555555555555", "/orcid-works/update"); + MOCKS.put(pke5, e5); + ClientScopeEntity e6 = new ClientScopeEntity(); + injectDateCreated(new Date(), e6); + injectLastModified(new Date(), e6); + ClientScopePk pke6 = new ClientScopePk("APP-5555555555555555", "/orcid-works/create"); + MOCKS.put(pke6, e6); + ClientScopeEntity e7 = new ClientScopeEntity(); + injectDateCreated(new Date(), e7); + injectLastModified(new Date(), e7); + ClientScopePk pke7 = new ClientScopePk("APP-5555555555555555", "/funding/create"); + MOCKS.put(pke7, e7); + ClientScopeEntity e8 = new ClientScopeEntity(); + injectDateCreated(new Date(), e8); + injectLastModified(new Date(), e8); + ClientScopePk pke8 = new ClientScopePk("APP-5555555555555555", "/funding/update"); + MOCKS.put(pke8, e8); + ClientScopeEntity e9 = new ClientScopeEntity(); + injectDateCreated(new Date(), e9); + injectLastModified(new Date(), e9); + ClientScopePk pke9 = new ClientScopePk("APP-5555555555555555", "/affiliations/create"); + MOCKS.put(pke9, e9); + ClientScopeEntity e10 = new ClientScopeEntity(); + injectDateCreated(new Date(), e10); + injectLastModified(new Date(), e10); + ClientScopePk pke10 = new ClientScopePk("APP-5555555555555555", "/authenticate"); + MOCKS.put(pke10, e10); + ClientScopeEntity e11 = new ClientScopeEntity(); + injectDateCreated(new Date(), e11); + injectLastModified(new Date(), e11); + ClientScopePk pke11 = new ClientScopePk("APP-5555555555555555", "/funding/read-limited"); + MOCKS.put(pke11, e11); + ClientScopeEntity e12 = new ClientScopeEntity(); + injectDateCreated(new Date(), e12); + injectLastModified(new Date(), e12); + ClientScopePk pke12 = new ClientScopePk("APP-5555555555555555", "/affiliations/read-limited"); + MOCKS.put(pke12, e12); + ClientScopeEntity e13 = new ClientScopeEntity(); + injectDateCreated(new Date(), e13); + injectLastModified(new Date(), e13); + ClientScopePk pke13 = new ClientScopePk("APP-5555555555555555", "/premium-notification"); + MOCKS.put(pke13, e13); + ClientScopeEntity e14 = new ClientScopeEntity(); + injectDateCreated(new Date(), e14); + injectLastModified(new Date(), e14); + ClientScopePk pke14 = new ClientScopePk("APP-5555555555555555", "/activities/update"); + MOCKS.put(pke14, e14); + ClientScopeEntity e15 = new ClientScopeEntity(); + injectDateCreated(new Date(), e15); + injectLastModified(new Date(), e15); + ClientScopePk pke15 = new ClientScopePk("APP-5555555555555555", "/activities/read-limited"); + MOCKS.put(pke15, e15); + ClientScopeEntity e16 = new ClientScopeEntity(); + injectDateCreated(new Date(), e16); + injectLastModified(new Date(), e16); + ClientScopePk pke16 = new ClientScopePk("APP-5555555555555555", "/read-limited"); + MOCKS.put(pke16, e16); + ClientScopeEntity e17 = new ClientScopeEntity(); + injectDateCreated(new Date(), e17); + injectLastModified(new Date(), e17); + ClientScopePk pke17 = new ClientScopePk("APP-5555555555555555", "/peer-review/create"); + MOCKS.put(pke17, e17); + ClientScopeEntity e18 = new ClientScopeEntity(); + injectDateCreated(new Date(), e18); + injectLastModified(new Date(), e18); + ClientScopePk pke18 = new ClientScopePk("APP-5555555555555555", "/orcid-internal/person/read"); + MOCKS.put(pke18, e18); + ClientScopeEntity e19 = new ClientScopeEntity(); + injectDateCreated(new Date(), e19); + injectLastModified(new Date(), e19); + ClientScopePk pke19 = new ClientScopePk("APP-5555555555555555", "/person/read-limited"); + MOCKS.put(pke19, e19); + ClientScopeEntity e20 = new ClientScopeEntity(); + injectDateCreated(new Date(), e20); + injectLastModified(new Date(), e20); + ClientScopePk pke20 = new ClientScopePk("APP-5555555555555555", "/person/update"); + MOCKS.put(pke20, e20); + ClientScopeEntity e21 = new ClientScopeEntity(); + injectDateCreated(new Date(), e21); + injectLastModified(new Date(), e21); + ClientScopePk pke21 = new ClientScopePk("APP-5555555555555556", "/orcid-bio/read-limited"); + MOCKS.put(pke21, e21); + ClientScopeEntity e22 = new ClientScopeEntity(); + injectDateCreated(new Date(), e22); + injectLastModified(new Date(), e22); + ClientScopePk pke22 = new ClientScopePk("APP-5555555555555556", "/orcid-works/create"); + MOCKS.put(pke22, e22); + ClientScopeEntity e23 = new ClientScopeEntity(); + injectDateCreated(new Date(), e23); + injectLastModified(new Date(), e23); + ClientScopePk pke23 = new ClientScopePk("APP-5555555555555556", "/funding/create"); + MOCKS.put(pke23, e23); + ClientScopeEntity e24 = new ClientScopeEntity(); + injectDateCreated(new Date(), e24); + injectLastModified(new Date(), e24); + ClientScopePk pke24 = new ClientScopePk("APP-5555555555555556", "/funding/read-limited"); + MOCKS.put(pke24, e24); + ClientScopeEntity e25 = new ClientScopeEntity(); + injectDateCreated(new Date(), e25); + injectLastModified(new Date(), e25); + ClientScopePk pke25 = new ClientScopePk("APP-5555555555555556", "/affiliations/create"); + MOCKS.put(pke25, e25); + ClientScopeEntity e26 = new ClientScopeEntity(); + injectDateCreated(new Date(), e26); + injectLastModified(new Date(), e26); + ClientScopePk pke26 = new ClientScopePk("APP-5555555555555556", "/affiliations/read-limited"); + MOCKS.put(pke26, e26); + ClientScopeEntity e27 = new ClientScopeEntity(); + injectDateCreated(new Date(), e27); + injectLastModified(new Date(), e27); + ClientScopePk pke27 = new ClientScopePk("APP-5555555555555556", "/authenticate"); + MOCKS.put(pke27, e27); + ClientScopeEntity e28 = new ClientScopeEntity(); + injectDateCreated(new Date(), e28); + injectLastModified(new Date(), e28); + ClientScopePk pke28 = new ClientScopePk("APP-5555555555555556", "/webhook"); + MOCKS.put(pke28, e28); + ClientScopeEntity e29 = new ClientScopeEntity(); + injectDateCreated(new Date(), e29); + injectLastModified(new Date(), e29); + ClientScopePk pke29 = new ClientScopePk("APP-5555555555555556", "/read-public"); + MOCKS.put(pke29, e29); + ClientScopeEntity e30 = new ClientScopeEntity(); + injectDateCreated(new Date(), e30); + injectLastModified(new Date(), e30); + ClientScopePk pke30 = new ClientScopePk("APP-5555555555555556", "/orcid-profile/create"); + MOCKS.put(pke30, e30); + ClientScopeEntity e31 = new ClientScopeEntity(); + injectDateCreated(new Date(), e31); + injectLastModified(new Date(), e31); + ClientScopePk pke31 = new ClientScopePk("APP-5555555555555557", "/webhook"); + MOCKS.put(pke31, e31); + ClientScopeEntity e32 = new ClientScopeEntity(); + injectDateCreated(new Date(), e32); + injectLastModified(new Date(), e32); + ClientScopePk pke32 = new ClientScopePk("APP-5555555555555557", "/read-public"); + MOCKS.put(pke32, e32); + ClientScopeEntity e33 = new ClientScopeEntity(); + injectDateCreated(new Date(), e33); + injectLastModified(new Date(), e33); + ClientScopePk pke33 = new ClientScopePk("APP-5555555555555557", "/orcid-profile/create"); + MOCKS.put(pke33, e33); + ClientScopeEntity e34 = new ClientScopeEntity(); + injectDateCreated(new Date(), e34); + injectLastModified(new Date(), e34); + ClientScopePk pke34 = new ClientScopePk("APP-5555555555555557", "/orcid-bio/read-limited"); + MOCKS.put(pke34, e34); + ClientScopeEntity e35 = new ClientScopeEntity(); + injectDateCreated(new Date(), e35); + injectLastModified(new Date(), e35); + ClientScopePk pke35 = new ClientScopePk("APP-5555555555555557", "/orcid-bio/update"); + MOCKS.put(pke35, e35); + ClientScopeEntity e36 = new ClientScopeEntity(); + injectDateCreated(new Date(), e36); + injectLastModified(new Date(), e36); + ClientScopePk pke36 = new ClientScopePk("APP-5555555555555557", "/orcid-works/update"); + MOCKS.put(pke36, e36); + ClientScopeEntity e37 = new ClientScopeEntity(); + injectDateCreated(new Date(), e37); + injectLastModified(new Date(), e37); + ClientScopePk pke37 = new ClientScopePk("APP-5555555555555557", "/orcid-works/create"); + MOCKS.put(pke37, e37); + ClientScopeEntity e38 = new ClientScopeEntity(); + injectDateCreated(new Date(), e38); + injectLastModified(new Date(), e38); + ClientScopePk pke38 = new ClientScopePk("APP-5555555555555557", "/funding/create"); + MOCKS.put(pke38, e38); + ClientScopeEntity e39 = new ClientScopeEntity(); + injectDateCreated(new Date(), e39); + injectLastModified(new Date(), e39); + ClientScopePk pke39 = new ClientScopePk("APP-5555555555555557", "/funding/update"); + MOCKS.put(pke39, e39); + ClientScopeEntity e40 = new ClientScopeEntity(); + injectDateCreated(new Date(), e40); + injectLastModified(new Date(), e40); + ClientScopePk pke40 = new ClientScopePk("APP-5555555555555557", "/affiliations/create"); + MOCKS.put(pke40, e40); + ClientScopeEntity e41 = new ClientScopeEntity(); + injectDateCreated(new Date(), e41); + injectLastModified(new Date(), e41); + ClientScopePk pke41 = new ClientScopePk("APP-5555555555555557", "/authenticate"); + MOCKS.put(pke41, e41); + ClientScopeEntity e42 = new ClientScopeEntity(); + injectDateCreated(new Date(), e42); + injectLastModified(new Date(), e42); + ClientScopePk pke42 = new ClientScopePk("APP-5555555555555557", "/funding/read-limited"); + MOCKS.put(pke42, e42); + ClientScopeEntity e43 = new ClientScopeEntity(); + injectDateCreated(new Date(), e43); + injectLastModified(new Date(), e43); + ClientScopePk pke43 = new ClientScopePk("APP-5555555555555557", "/affiliations/read-limited"); + MOCKS.put(pke43, e43); + ClientScopeEntity e44 = new ClientScopeEntity(); + injectDateCreated(new Date(), e44); + injectLastModified(new Date(), e44); + ClientScopePk pke44 = new ClientScopePk("APP-5555555555555557", "/premium-notification"); + MOCKS.put(pke44, e44); + ClientScopeEntity e45 = new ClientScopeEntity(); + injectDateCreated(new Date(), e45); + injectLastModified(new Date(), e45); + ClientScopePk pke45 = new ClientScopePk("APP-5555555555555557", "/activities/update"); + MOCKS.put(pke45, e45); + ClientScopeEntity e46 = new ClientScopeEntity(); + injectDateCreated(new Date(), e46); + injectLastModified(new Date(), e46); + ClientScopePk pke46 = new ClientScopePk("APP-5555555555555557", "/activities/read-limited"); + MOCKS.put(pke46, e46); + ClientScopeEntity e47 = new ClientScopeEntity(); + injectDateCreated(new Date(), e47); + injectLastModified(new Date(), e47); + ClientScopePk pke47 = new ClientScopePk("APP-5555555555555557", "/read-limited"); + MOCKS.put(pke47, e47); + ClientScopeEntity e48 = new ClientScopeEntity(); + injectDateCreated(new Date(), e48); + injectLastModified(new Date(), e48); + ClientScopePk pke48 = new ClientScopePk("APP-5555555555555557", "/peer-review/create"); + MOCKS.put(pke48, e48); + ClientScopeEntity e49 = new ClientScopeEntity(); + injectDateCreated(new Date(), e49); + injectLastModified(new Date(), e49); + ClientScopePk pke49 = new ClientScopePk("APP-5555555555555557", "/orcid-internal/person/read"); + MOCKS.put(pke49, e49); + ClientScopeEntity e50 = new ClientScopeEntity(); + injectDateCreated(new Date(), e50); + injectLastModified(new Date(), e50); + ClientScopePk pke50 = new ClientScopePk("APP-5555555555555557", "/person/read-limited"); + MOCKS.put(pke50, e50); + ClientScopeEntity e51 = new ClientScopeEntity(); + injectDateCreated(new Date(), e51); + injectLastModified(new Date(), e51); + ClientScopePk pke51 = new ClientScopePk("APP-5555555555555557", "/person/update"); + MOCKS.put(pke51, e51); + ClientScopeEntity e52 = new ClientScopeEntity(); + injectDateCreated(new Date(), e52); + injectLastModified(new Date(), e52); + ClientScopePk pke52 = new ClientScopePk("APP-5555555555555558", "/webhook"); + MOCKS.put(pke52, e52); + ClientScopeEntity e53 = new ClientScopeEntity(); + injectDateCreated(new Date(), e53); + injectLastModified(new Date(), e53); + ClientScopePk pke53 = new ClientScopePk("APP-5555555555555558", "/read-public"); + MOCKS.put(pke53, e53); + ClientScopeEntity e54 = new ClientScopeEntity(); + injectDateCreated(new Date(), e54); + injectLastModified(new Date(), e54); + ClientScopePk pke54 = new ClientScopePk("APP-5555555555555558", "/orcid-profile/create"); + MOCKS.put(pke54, e54); + ClientScopeEntity e55 = new ClientScopeEntity(); + injectDateCreated(new Date(), e55); + injectLastModified(new Date(), e55); + ClientScopePk pke55 = new ClientScopePk("APP-5555555555555558", "/orcid-bio/read-limited"); + MOCKS.put(pke55, e55); + ClientScopeEntity e56 = new ClientScopeEntity(); + injectDateCreated(new Date(), e56); + injectLastModified(new Date(), e56); + ClientScopePk pke56 = new ClientScopePk("APP-5555555555555558", "/orcid-bio/update"); + MOCKS.put(pke56, e56); + ClientScopeEntity e57 = new ClientScopeEntity(); + injectDateCreated(new Date(), e57); + injectLastModified(new Date(), e57); + ClientScopePk pke57 = new ClientScopePk("APP-5555555555555558", "/orcid-works/update"); + MOCKS.put(pke57, e57); + ClientScopeEntity e58 = new ClientScopeEntity(); + injectDateCreated(new Date(), e58); + injectLastModified(new Date(), e58); + ClientScopePk pke58 = new ClientScopePk("APP-5555555555555558", "/orcid-works/create"); + MOCKS.put(pke58, e58); + ClientScopeEntity e59 = new ClientScopeEntity(); + injectDateCreated(new Date(), e59); + injectLastModified(new Date(), e59); + ClientScopePk pke59 = new ClientScopePk("APP-5555555555555558", "/funding/create"); + MOCKS.put(pke59, e59); + ClientScopeEntity e60 = new ClientScopeEntity(); + injectDateCreated(new Date(), e60); + injectLastModified(new Date(), e60); + ClientScopePk pke60 = new ClientScopePk("APP-5555555555555558", "/funding/update"); + MOCKS.put(pke60, e60); + ClientScopeEntity e61 = new ClientScopeEntity(); + injectDateCreated(new Date(), e61); + injectLastModified(new Date(), e61); + ClientScopePk pke61 = new ClientScopePk("APP-5555555555555558", "/affiliations/create"); + MOCKS.put(pke61, e61); + ClientScopeEntity e62 = new ClientScopeEntity(); + injectDateCreated(new Date(), e62); + injectLastModified(new Date(), e62); + ClientScopePk pke62 = new ClientScopePk("APP-5555555555555558", "/authenticate"); + MOCKS.put(pke62, e62); + ClientScopeEntity e63 = new ClientScopeEntity(); + injectDateCreated(new Date(), e63); + injectLastModified(new Date(), e63); + ClientScopePk pke63 = new ClientScopePk("APP-5555555555555558", "/funding/read-limited"); + MOCKS.put(pke63, e63); + ClientScopeEntity e64 = new ClientScopeEntity(); + injectDateCreated(new Date(), e64); + injectLastModified(new Date(), e64); + ClientScopePk pke64 = new ClientScopePk("APP-5555555555555558", "/affiliations/read-limited"); + MOCKS.put(pke64, e64); + ClientScopeEntity e65 = new ClientScopeEntity(); + injectDateCreated(new Date(), e65); + injectLastModified(new Date(), e65); + ClientScopePk pke65 = new ClientScopePk("APP-5555555555555558", "/premium-notification"); + MOCKS.put(pke65, e65); + ClientScopeEntity e66 = new ClientScopeEntity(); + injectDateCreated(new Date(), e66); + injectLastModified(new Date(), e66); + ClientScopePk pke66 = new ClientScopePk("APP-5555555555555558", "/activities/update"); + MOCKS.put(pke66, e66); + ClientScopeEntity e67 = new ClientScopeEntity(); + injectDateCreated(new Date(), e67); + injectLastModified(new Date(), e67); + ClientScopePk pke67 = new ClientScopePk("APP-5555555555555558", "/activities/read-limited"); + MOCKS.put(pke67, e67); + ClientScopeEntity e68 = new ClientScopeEntity(); + injectDateCreated(new Date(), e68); + injectLastModified(new Date(), e68); + ClientScopePk pke68 = new ClientScopePk("APP-5555555555555558", "/read-limited"); + MOCKS.put(pke68, e68); + ClientScopeEntity e69 = new ClientScopeEntity(); + injectDateCreated(new Date(), e69); + injectLastModified(new Date(), e69); + ClientScopePk pke69 = new ClientScopePk("APP-5555555555555558", "/peer-review/create"); + MOCKS.put(pke69, e69); + ClientScopeEntity e70 = new ClientScopeEntity(); + injectDateCreated(new Date(), e70); + injectLastModified(new Date(), e70); + ClientScopePk pke70 = new ClientScopePk("APP-5555555555555558", "/orcid-internal/person/read"); + MOCKS.put(pke70, e70); + ClientScopeEntity e71 = new ClientScopeEntity(); + injectDateCreated(new Date(), e71); + injectLastModified(new Date(), e71); + ClientScopePk pke71 = new ClientScopePk("APP-5555555555555558", "/person/read-limited"); + MOCKS.put(pke71, e71); + ClientScopeEntity e72 = new ClientScopeEntity(); + injectDateCreated(new Date(), e72); + injectLastModified(new Date(), e72); + ClientScopePk pke72 = new ClientScopePk("APP-5555555555555558", "/person/update"); + MOCKS.put(pke72, e72); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static ClientScopeEntity getClientScope(ClientScopePk id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } + +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientSecretEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientSecretEntityMocks.java new file mode 100644 index 00000000000..8c889e4a265 --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ClientSecretEntityMocks.java @@ -0,0 +1,90 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.ClientSecretEntity; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.text.SimpleDateFormat; +import java.text.ParseException; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class ClientSecretEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + ClientSecretEntity e0 = new ClientSecretEntity(); + injectDateCreated(parseDate("2012-04-25"), e0); + injectLastModified(parseDate("2012-04-25"), e0); + org.orcid.persistence.jpa.entities.ClientSecretPk pke0 = new org.orcid.persistence.jpa.entities.ClientSecretPk("APP-5555555555555555", "DhkFj5EI0qp6GsUKi55Vja+h+bsaKpBx"); + e0.setId(pke0); + e0.setPrimary(true); + MOCKS.put(pke0, e0); + ClientSecretEntity e1 = new ClientSecretEntity(); + injectDateCreated(parseDate("2012-04-25"), e1); + injectLastModified(parseDate("2012-04-25"), e1); + org.orcid.persistence.jpa.entities.ClientSecretPk pke1 = new org.orcid.persistence.jpa.entities.ClientSecretPk("APP-5555555555555556", "DhkFj5EI0qp6GsUKi55Vja+h+bsaKpBx"); + e1.setId(pke1); + e1.setPrimary(true); + MOCKS.put(pke1, e1); + ClientSecretEntity e2 = new ClientSecretEntity(); + injectDateCreated(parseDate("2021-08-15"), e2); + injectLastModified(parseDate("2021-08-15"), e2); + org.orcid.persistence.jpa.entities.ClientSecretPk pke2 = new org.orcid.persistence.jpa.entities.ClientSecretPk("APP-5555555555555557", "B8M3Vy8aSvLeV+A4kx9HnQ=="); + e2.setId(pke2); + e2.setPrimary(true); + MOCKS.put(pke2, e2); + ClientSecretEntity e3 = new ClientSecretEntity(); + injectDateCreated(parseDate("2021-08-15"), e3); + injectLastModified(parseDate("2021-08-15"), e3); + org.orcid.persistence.jpa.entities.ClientSecretPk pke3 = new org.orcid.persistence.jpa.entities.ClientSecretPk("APP-5555555555555557", "DaVVhgVl3ab+6HYDyGCBbg=="); + e3.setId(pke3); + e3.setPrimary(false); + MOCKS.put(pke3, e3); + ClientSecretEntity e4 = new ClientSecretEntity(); + injectDateCreated(parseDate("2021-08-15"), e4); + injectLastModified(parseDate("2021-08-15"), e4); + org.orcid.persistence.jpa.entities.ClientSecretPk pke4 = new org.orcid.persistence.jpa.entities.ClientSecretPk("APP-5555555555555557", "DhkFj5EI0qp6GsUKi55Vja+h+bsaKpBx"); + e4.setId(pke4); + e4.setPrimary(false); + MOCKS.put(pke4, e4); + ClientSecretEntity e5 = new ClientSecretEntity(); + injectDateCreated(parseDate("2021-08-15"), e5); + injectLastModified(parseDate("2021-08-15"), e5); + org.orcid.persistence.jpa.entities.ClientSecretPk pke5 = new org.orcid.persistence.jpa.entities.ClientSecretPk("APP-5555555555555558", "DhkFj5EI0qp6GsUKi55Vja+h+bsaKpBx"); + e5.setId(pke5); + e5.setPrimary(true); + MOCKS.put(pke5, e5); + ClientSecretEntity e6 = new ClientSecretEntity(); + injectDateCreated(parseDate("2021-08-15"), e6); + injectLastModified(parseDate("2021-08-15"), e6); + org.orcid.persistence.jpa.entities.ClientSecretPk pke6 = new org.orcid.persistence.jpa.entities.ClientSecretPk("APP-5555555555555558", "DaVVhgVl3ab+6HYDyGCBbg=="); + e6.setId(pke6); + e6.setPrimary(false); + MOCKS.put(pke6, e6); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static ClientSecretEntity getClientSecret(org.orcid.persistence.jpa.entities.ClientSecretPk id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } + + private static Date parseDate(String dateStr) { + try { + if (dateStr.length() == 10) { + return new SimpleDateFormat("yyyy-MM-dd").parse(dateStr); + } + return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr); + } catch (ParseException e) { + throw new RuntimeException(e); + } + } +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/EmailDomainEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/EmailDomainEntityMocks.java new file mode 100644 index 00000000000..46f519c3143 --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/EmailDomainEntityMocks.java @@ -0,0 +1,38 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.EmailDomainEntity; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class EmailDomainEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + EmailDomainEntity ed0 = new EmailDomainEntity(); + injectDateCreated(parseDate("None"), ed0); + injectLastModified(parseDate("None"), ed0); + ed0.setId(0L); + ed0.setEmailDomain("orcid.org"); + ed0.setCategory(EmailDomainEntity.DomainCategory.PROFESSIONAL); + MOCKS.put(0L, ed0); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static EmailDomainEntity getEmailDomain(Long id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } + +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/EmailEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/EmailEntityMocks.java new file mode 100644 index 00000000000..c4306941f3d --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/EmailEntityMocks.java @@ -0,0 +1,586 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.EmailEntity; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class EmailEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + EmailEntity e_fa755fdf4b = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_fa755fdf4b); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), e_fa755fdf4b); + e_fa755fdf4b.setEmail("spike@milligan.com"); + e_fa755fdf4b.setId("fa755fdf4ba30ea92bbbd382f4787526d162110cd83192a3bec180e6a09396b5"); + e_fa755fdf4b.setOrcid("4444-4444-4444-4441"); + e_fa755fdf4b.setPrimary(true); + e_fa755fdf4b.setCurrent(true); + e_fa755fdf4b.setVerified(true); + e_fa755fdf4b.setVisibility("LIMITED"); + e_fa755fdf4b.setSourceId("4444-4444-4444-4441"); + MOCKS.put("fa755fdf4ba30ea92bbbd382f4787526d162110cd83192a3bec180e6a09396b5", e_fa755fdf4b); + + EmailEntity e_4266e33c87 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_4266e33c87); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), e_4266e33c87); + e_4266e33c87.setEmail("public@email.com"); + e_4266e33c87.setId("4266e33c87bf6a2410abe5a37a7c0aae3630a6ac18fb765f7ec2d570c687d898"); + e_4266e33c87.setOrcid("4444-4444-4444-4441"); + e_4266e33c87.setPrimary(false); + e_4266e33c87.setCurrent(true); + e_4266e33c87.setVerified(true); + e_4266e33c87.setVisibility("PUBLIC"); + e_4266e33c87.setSourceId("4444-4444-4444-4441"); + MOCKS.put("4266e33c87bf6a2410abe5a37a7c0aae3630a6ac18fb765f7ec2d570c687d898", e_4266e33c87); + + EmailEntity e_537969d9e9 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_537969d9e9); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), e_537969d9e9); + e_537969d9e9.setEmail("limited@email.com"); + e_537969d9e9.setId("537969d9e9df42b9ef3945c3c68ea08aeee2b81dae7114786f5bffbd471e4432"); + e_537969d9e9.setOrcid("4444-4444-4444-4441"); + e_537969d9e9.setPrimary(false); + e_537969d9e9.setCurrent(true); + e_537969d9e9.setVerified(true); + e_537969d9e9.setVisibility("LIMITED"); + e_537969d9e9.setSourceId("4444-4444-4444-4441"); + MOCKS.put("537969d9e9df42b9ef3945c3c68ea08aeee2b81dae7114786f5bffbd471e4432", e_537969d9e9); + + EmailEntity e_d0ef05afca = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_d0ef05afca); + injectLastModified(parseDate("2016-01-01 12:22:00.00"), e_d0ef05afca); + e_d0ef05afca.setEmail("1@deprecate.com"); + e_d0ef05afca.setId("d0ef05afcac77e924955030b14a5debfb69b173e21b453cfe21e52e385f82cf1"); + e_d0ef05afca.setOrcid("4444-4444-4444-4441"); + e_d0ef05afca.setPrimary(false); + e_d0ef05afca.setCurrent(false); + e_d0ef05afca.setVerified(true); + e_d0ef05afca.setVisibility("PRIVATE"); + e_d0ef05afca.setSourceId("4444-4444-4444-4441"); + MOCKS.put("d0ef05afcac77e924955030b14a5debfb69b173e21b453cfe21e52e385f82cf1", e_d0ef05afca); + + EmailEntity e_030d5c18e5 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_030d5c18e5); + injectLastModified(parseDate("2016-01-02 15:31:00.00"), e_030d5c18e5); + e_030d5c18e5.setEmail("2@deprecate.com"); + e_030d5c18e5.setId("030d5c18e52798a1c7cc5635b931dd1c0ecd16d96c9f22528a0ad83f65589990"); + e_030d5c18e5.setOrcid("4444-4444-4444-4441"); + e_030d5c18e5.setPrimary(false); + e_030d5c18e5.setCurrent(false); + e_030d5c18e5.setVerified(false); + e_030d5c18e5.setVisibility("PRIVATE"); + e_030d5c18e5.setSourceId("4444-4444-4444-4441"); + MOCKS.put("030d5c18e52798a1c7cc5635b931dd1c0ecd16d96c9f22528a0ad83f65589990", e_030d5c18e5); + + EmailEntity e_82f825b039 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_82f825b039); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_82f825b039); + e_82f825b039.setEmail("4441-10@milligan.com"); + e_82f825b039.setId("82f825b0395bea46d7360ee05758051aab8371b6a02e5bab32d278646457e772"); + e_82f825b039.setOrcid("4444-4444-4444-4499"); + e_82f825b039.setPrimary(true); + e_82f825b039.setCurrent(true); + e_82f825b039.setVerified(true); + e_82f825b039.setVisibility("PRIVATE"); + e_82f825b039.setSourceId("4444-4444-4444-4441"); + MOCKS.put("82f825b0395bea46d7360ee05758051aab8371b6a02e5bab32d278646457e772", e_82f825b039); + + EmailEntity e_3a5e03495b = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_3a5e03495b); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_3a5e03495b); + e_3a5e03495b.setEmail("4444-4444-4444-4498@milligan.com"); + e_3a5e03495b.setId("3a5e03495b39d0d18738d215d5f73141799cd3e96b40aa5c24ff54d58ced9c9f"); + e_3a5e03495b.setOrcid("4444-4444-4444-4498"); + e_3a5e03495b.setPrimary(true); + e_3a5e03495b.setCurrent(true); + e_3a5e03495b.setVerified(true); + e_3a5e03495b.setVisibility("PRIVATE"); + e_3a5e03495b.setSourceId("4444-4444-4444-4441"); + MOCKS.put("3a5e03495b39d0d18738d215d5f73141799cd3e96b40aa5c24ff54d58ced9c9f", e_3a5e03495b); + + EmailEntity e_c8017625d3 = new EmailEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), e_c8017625d3); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), e_c8017625d3); + e_c8017625d3.setEmail("michael@bentine.com"); + e_c8017625d3.setId("c8017625d38c53394062d1b5ea1a30b76fca792523435f2e87d20fea4172e97d"); + e_c8017625d3.setOrcid("4444-4444-4444-4442"); + e_c8017625d3.setPrimary(true); + e_c8017625d3.setCurrent(true); + e_c8017625d3.setVerified(true); + e_c8017625d3.setVisibility("LIMITED"); + e_c8017625d3.setSourceId("4444-4444-4444-4442"); + MOCKS.put("c8017625d38c53394062d1b5ea1a30b76fca792523435f2e87d20fea4172e97d", e_c8017625d3); + + EmailEntity e_1293bdbb7e = new EmailEntity(); + injectDateCreated(parseDate("2016-08-09 12:42:00.00"), e_1293bdbb7e); + injectLastModified(parseDate("2016-08-10 13:12:00.00"), e_1293bdbb7e); + e_1293bdbb7e.setEmail("MiXeD@cASe.com"); + e_1293bdbb7e.setId("1293bdbb7ee3963ffa4f8c3cd0182b114a2d702d85c2811797712f09d00d5027"); + e_1293bdbb7e.setOrcid("4444-4444-4444-4442"); + e_1293bdbb7e.setPrimary(false); + e_1293bdbb7e.setCurrent(true); + e_1293bdbb7e.setVerified(true); + e_1293bdbb7e.setVisibility("PRIVATE"); + e_1293bdbb7e.setSourceId("4444-4444-4444-4442"); + MOCKS.put("1293bdbb7ee3963ffa4f8c3cd0182b114a2d702d85c2811797712f09d00d5027", e_1293bdbb7e); + + EmailEntity e_93e5ca91a3 = new EmailEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), e_93e5ca91a3); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), e_93e5ca91a3); + e_93e5ca91a3.setEmail("peter@sellers.com"); + e_93e5ca91a3.setId("93e5ca91a3a030187b723f7934992cd1cab061f32b568c57a276af58f1c2f77f"); + e_93e5ca91a3.setOrcid("4444-4444-4444-4443"); + e_93e5ca91a3.setPrimary(true); + e_93e5ca91a3.setCurrent(true); + e_93e5ca91a3.setVerified(false); + e_93e5ca91a3.setVisibility("PRIVATE"); + e_93e5ca91a3.setSourceId("4444-4444-4444-4443"); + MOCKS.put("93e5ca91a3a030187b723f7934992cd1cab061f32b568c57a276af58f1c2f77f", e_93e5ca91a3); + + EmailEntity e_2c5cb98057 = new EmailEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), e_2c5cb98057); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), e_2c5cb98057); + e_2c5cb98057.setEmail("teddybass@semantico.com"); + e_2c5cb98057.setId("2c5cb98057d742ca06eff946aa12a2eb3f9a383159ec85097d8a525fc260cbe7"); + e_2c5cb98057.setOrcid("4444-4444-4444-4443"); + e_2c5cb98057.setPrimary(false); + e_2c5cb98057.setCurrent(true); + e_2c5cb98057.setVerified(false); + e_2c5cb98057.setVisibility("PRIVATE"); + e_2c5cb98057.setSourceId("4444-4444-4444-4443"); + MOCKS.put("2c5cb98057d742ca06eff946aa12a2eb3f9a383159ec85097d8a525fc260cbe7", e_2c5cb98057); + + EmailEntity e_342c1db9d1 = new EmailEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), e_342c1db9d1); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), e_342c1db9d1); + e_342c1db9d1.setEmail("teddybass2@semantico.com"); + e_342c1db9d1.setId("342c1db9d167945cb61aeb83ee2e4eb9c2774a558dde128649a2a26c30b060f2"); + e_342c1db9d1.setOrcid("4444-4444-4444-4443"); + e_342c1db9d1.setPrimary(false); + e_342c1db9d1.setCurrent(true); + e_342c1db9d1.setVerified(false); + e_342c1db9d1.setVisibility("LIMITED"); + e_342c1db9d1.setSourceId("4444-4444-4444-4443"); + MOCKS.put("342c1db9d167945cb61aeb83ee2e4eb9c2774a558dde128649a2a26c30b060f2", e_342c1db9d1); + + EmailEntity e_f956395f84 = new EmailEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), e_f956395f84); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), e_f956395f84); + e_f956395f84.setEmail("teddybass3public@semantico.com"); + e_f956395f84.setId("f956395f84a3ed21f8350dfb478daa0373b5609cb14b391fd1927168094f9e59"); + e_f956395f84.setOrcid("4444-4444-4444-4443"); + e_f956395f84.setPrimary(false); + e_f956395f84.setCurrent(true); + e_f956395f84.setVerified(false); + e_f956395f84.setVisibility("PUBLIC"); + e_f956395f84.setSourceId("4444-4444-4444-4443"); + MOCKS.put("f956395f84a3ed21f8350dfb478daa0373b5609cb14b391fd1927168094f9e59", e_f956395f84); + + EmailEntity e_7ec2c81339 = new EmailEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), e_7ec2c81339); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), e_7ec2c81339); + e_7ec2c81339.setEmail("teddybass3private@semantico.com"); + e_7ec2c81339.setId("7ec2c813391c22a9b190062fe07a78b2a409e76eb7877b6bc01097422ca24a79"); + e_7ec2c81339.setOrcid("4444-4444-4444-4443"); + e_7ec2c81339.setPrimary(false); + e_7ec2c81339.setCurrent(true); + e_7ec2c81339.setVerified(true); + e_7ec2c81339.setVisibility("PRIVATE"); + e_7ec2c81339.setClientSourceId("APP-5555555555555555"); + MOCKS.put("7ec2c813391c22a9b190062fe07a78b2a409e76eb7877b6bc01097422ca24a79", e_7ec2c81339); + + EmailEntity e_bbc3d9d7f3 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_bbc3d9d7f3); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_bbc3d9d7f3); + e_bbc3d9d7f3.setEmail("harry@secombe.com"); + e_bbc3d9d7f3.setId("bbc3d9d7f304fe0139f83ad7745cc54f5e8abb56dde4f5e1c2f966a47df63d17"); + e_bbc3d9d7f3.setOrcid("4444-4444-4444-4444"); + e_bbc3d9d7f3.setPrimary(true); + e_bbc3d9d7f3.setCurrent(true); + e_bbc3d9d7f3.setVerified(true); + e_bbc3d9d7f3.setVisibility("PRIVATE"); + e_bbc3d9d7f3.setSourceId("4444-4444-4444-4444"); + MOCKS.put("bbc3d9d7f304fe0139f83ad7745cc54f5e8abb56dde4f5e1c2f966a47df63d17", e_bbc3d9d7f3); + + EmailEntity e_813bdeb15d = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_813bdeb15d); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_813bdeb15d); + e_813bdeb15d.setEmail("aNdReW@tImOtHy.com"); + e_813bdeb15d.setId("813bdeb15d67a17a3eb119daf7098736edeb499746e45c703b06957e15c03dc0"); + e_813bdeb15d.setOrcid("4444-4444-4444-4445"); + e_813bdeb15d.setPrimary(true); + e_813bdeb15d.setCurrent(true); + e_813bdeb15d.setVerified(false); + e_813bdeb15d.setVisibility("PRIVATE"); + e_813bdeb15d.setSourceId("4444-4444-4444-4441"); + MOCKS.put("813bdeb15d67a17a3eb119daf7098736edeb499746e45c703b06957e15c03dc0", e_813bdeb15d); + + EmailEntity e_955d69759f = new EmailEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), e_955d69759f); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), e_955d69759f); + e_955d69759f.setEmail("angel2@montenegro.com"); + e_955d69759f.setId("955d69759f05bef175aff04ec0242a643442ae089f229d0c4124c525e5dd02a2"); + e_955d69759f.setOrcid("4444-4444-4444-4443"); + e_955d69759f.setPrimary(false); + e_955d69759f.setCurrent(false); + e_955d69759f.setVerified(false); + e_955d69759f.setVisibility("PRIVATE"); + e_955d69759f.setSourceId("4444-4444-4444-4441"); + MOCKS.put("955d69759f05bef175aff04ec0242a643442ae089f229d0c4124c525e5dd02a2", e_955d69759f); + + EmailEntity e_2965a4115f = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_2965a4115f); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_2965a4115f); + e_2965a4115f.setEmail("angel1@montenegro.com"); + e_2965a4115f.setId("2965a4115f2639b43e5feb78adddfff52e5324813b6c12b4e25ebdac052f72df"); + e_2965a4115f.setOrcid("4444-4444-4444-4444"); + e_2965a4115f.setPrimary(true); + e_2965a4115f.setCurrent(false); + e_2965a4115f.setVerified(true); + e_2965a4115f.setVisibility("PRIVATE"); + e_2965a4115f.setSourceId("4444-4444-4444-4441"); + MOCKS.put("2965a4115f2639b43e5feb78adddfff52e5324813b6c12b4e25ebdac052f72df", e_2965a4115f); + + EmailEntity e_716e061d83 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_716e061d83); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_716e061d83); + e_716e061d83.setEmail("andrew2@timothy.com"); + e_716e061d83.setId("716e061d83dcac0e6f7efd4574a6e4c0cd9de4520731819faa054375a0e8c9a2"); + e_716e061d83.setOrcid("4444-4444-4444-4445"); + e_716e061d83.setPrimary(false); + e_716e061d83.setCurrent(false); + e_716e061d83.setVerified(false); + e_716e061d83.setVisibility("PRIVATE"); + e_716e061d83.setSourceId("4444-4444-4444-4441"); + MOCKS.put("716e061d83dcac0e6f7efd4574a6e4c0cd9de4520731819faa054375a0e8c9a2", e_716e061d83); + + EmailEntity e_245ff4ed28 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_245ff4ed28); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_245ff4ed28); + e_245ff4ed28.setEmail("billie@holiday.com"); + e_245ff4ed28.setId("245ff4ed28f695be77c90999acdbcb372f50e82491768e45f6a01f2f18c56a4a"); + e_245ff4ed28.setOrcid("4444-4444-4444-4446"); + e_245ff4ed28.setPrimary(true); + e_245ff4ed28.setCurrent(true); + e_245ff4ed28.setVerified(true); + e_245ff4ed28.setVisibility("PRIVATE"); + e_245ff4ed28.setSourceId("4444-4444-4444-4446"); + MOCKS.put("245ff4ed28f695be77c90999acdbcb372f50e82491768e45f6a01f2f18c56a4a", e_245ff4ed28); + + EmailEntity e_f660ab912e = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_f660ab912e); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_f660ab912e); + e_f660ab912e.setEmail("test@test.com"); + e_f660ab912e.setId("f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a"); + e_f660ab912e.setOrcid("4444-4444-4444-4446"); + e_f660ab912e.setPrimary(false); + e_f660ab912e.setCurrent(true); + e_f660ab912e.setVerified(true); + e_f660ab912e.setVisibility("PRIVATE"); + e_f660ab912e.setSourceId("4444-4444-4444-4446"); + MOCKS.put("f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a", e_f660ab912e); + + EmailEntity e_b238c595b8 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_b238c595b8); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_b238c595b8); + e_b238c595b8.setEmail("user@user.com"); + e_b238c595b8.setId("b238c595b84321b35b8e57610c49523d4e3b9b5b5d090923e9e54f4b929bedba"); + e_b238c595b8.setOrcid("4444-4444-4444-4446"); + e_b238c595b8.setPrimary(false); + e_b238c595b8.setCurrent(true); + e_b238c595b8.setVerified(true); + e_b238c595b8.setVisibility("PRIVATE"); + e_b238c595b8.setSourceId("4444-4444-4444-4446"); + MOCKS.put("b238c595b84321b35b8e57610c49523d4e3b9b5b5d090923e9e54f4b929bedba", e_b238c595b8); + + EmailEntity e_ed69d58e68 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_ed69d58e68); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_ed69d58e68); + e_ed69d58e68.setEmail("otis@reading.com"); + e_ed69d58e68.setId("ed69d58e68ea6f821f13f0a5006742d3065bb412bab8bc86899ae39638ddc7b5"); + e_ed69d58e68.setOrcid("4444-4444-4444-4447"); + e_ed69d58e68.setPrimary(true); + e_ed69d58e68.setCurrent(true); + e_ed69d58e68.setVerified(true); + e_ed69d58e68.setVisibility("PRIVATE"); + e_ed69d58e68.setSourceId("4444-4444-4444-4447"); + MOCKS.put("ed69d58e68ea6f821f13f0a5006742d3065bb412bab8bc86899ae39638ddc7b5", e_ed69d58e68); + + EmailEntity e_0925f997eb = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_0925f997eb); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_0925f997eb); + e_0925f997eb.setEmail("user@email.com"); + e_0925f997eb.setId("0925f997eb0d742678f66d2da134d15d842d57722af5f7605c4785cb5358831b"); + e_0925f997eb.setOrcid("4444-4444-4444-444X"); + e_0925f997eb.setPrimary(true); + e_0925f997eb.setCurrent(true); + e_0925f997eb.setVerified(true); + e_0925f997eb.setVisibility("PUBLIC"); + e_0925f997eb.setSourceId("4444-4444-4444-444X"); + MOCKS.put("0925f997eb0d742678f66d2da134d15d842d57722af5f7605c4785cb5358831b", e_0925f997eb); + + EmailEntity e_18a88eff6e = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_18a88eff6e); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_18a88eff6e); + e_18a88eff6e.setEmail("admin@user.com"); + e_18a88eff6e.setId("18a88eff6eac8ebd45ac3451ec2c60695d614ed9cbe7b56175d76aa780841146"); + e_18a88eff6e.setOrcid("4444-4444-4444-4440"); + e_18a88eff6e.setPrimary(true); + e_18a88eff6e.setCurrent(true); + e_18a88eff6e.setVerified(true); + e_18a88eff6e.setVisibility("PRIVATE"); + e_18a88eff6e.setSourceId("4444-4444-4444-4441"); + MOCKS.put("18a88eff6eac8ebd45ac3451ec2c60695d614ed9cbe7b56175d76aa780841146", e_18a88eff6e); + + EmailEntity e_8f649f6d12 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_8f649f6d12); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_8f649f6d12); + e_8f649f6d12.setEmail("public_0000-0000-0000-0001@test.orcid.org"); + e_8f649f6d12.setId("8f649f6d12203f020ee26467547432add46bc5395ff8dd72242fa2d7aa4fc04a"); + e_8f649f6d12.setOrcid("0000-0000-0000-0001"); + e_8f649f6d12.setPrimary(true); + e_8f649f6d12.setCurrent(true); + e_8f649f6d12.setVerified(false); + e_8f649f6d12.setVisibility("PUBLIC"); + e_8f649f6d12.setClientSourceId("APP-5555555555555555"); + MOCKS.put("8f649f6d12203f020ee26467547432add46bc5395ff8dd72242fa2d7aa4fc04a", e_8f649f6d12); + + EmailEntity e_afcsd87b85 = new EmailEntity(); + injectDateCreated(parseDate("2018-01-01 00:00:00.00"), e_afcsd87b85); + injectLastModified(parseDate("2018-01-01 00:00:00.00"), e_afcsd87b85); + e_afcsd87b85.setEmail("limited_verified_0000-0000-0000-0001@test.orcid.org"); + e_afcsd87b85.setId("afcsd87b8547a96sdfba9g7sfdbba87asdf542q7aqw4fxsd5d4g77g5s1a4fx1bbc"); + e_afcsd87b85.setOrcid("0000-0000-0000-0001"); + e_afcsd87b85.setPrimary(false); + e_afcsd87b85.setCurrent(true); + e_afcsd87b85.setVerified(true); + e_afcsd87b85.setVisibility("LIMITED"); + e_afcsd87b85.setClientSourceId("APP-5555555555555555"); + MOCKS.put("afcsd87b8547a96sdfba9g7sfdbba87asdf542q7aqw4fxsd5d4g77g5s1a4fx1bbc", e_afcsd87b85); + + EmailEntity e_bb24ead143 = new EmailEntity(); + injectDateCreated(parseDate("2024-01-01 00:00:00.00"), e_bb24ead143); + injectLastModified(parseDate("2024-01-01 00:00:00.00"), e_bb24ead143); + e_bb24ead143.setEmail("verified_non_professional@nonprofessional.org"); + e_bb24ead143.setId("bb24ead143f1a58f97394436a0548e7bc3d30a539188accd5d82a28af4345778"); + e_bb24ead143.setOrcid("0000-0000-0000-0001"); + e_bb24ead143.setPrimary(false); + e_bb24ead143.setCurrent(false); + e_bb24ead143.setVerified(true); + e_bb24ead143.setVisibility("PUBLIC"); + e_bb24ead143.setClientSourceId("APP-5555555555555555"); + MOCKS.put("bb24ead143f1a58f97394436a0548e7bc3d30a539188accd5d82a28af4345778", e_bb24ead143); + + EmailEntity e_ecdc2c6aef = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_ecdc2c6aef); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_ecdc2c6aef); + e_ecdc2c6aef.setEmail("public_0000-0000-0000-0002@test.orcid.org"); + e_ecdc2c6aef.setId("ecdc2c6aef7aa5aa4012b9e5f262de2214c9b0e3f3b0201da0eeebc7531ae018"); + e_ecdc2c6aef.setOrcid("0000-0000-0000-0002"); + e_ecdc2c6aef.setPrimary(true); + e_ecdc2c6aef.setCurrent(true); + e_ecdc2c6aef.setVerified(false); + e_ecdc2c6aef.setVisibility("PUBLIC"); + e_ecdc2c6aef.setClientSourceId("APP-5555555555555555"); + MOCKS.put("ecdc2c6aef7aa5aa4012b9e5f262de2214c9b0e3f3b0201da0eeebc7531ae018", e_ecdc2c6aef); + + EmailEntity e_c3ba0b26ac = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_c3ba0b26ac); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_c3ba0b26ac); + e_c3ba0b26ac.setEmail("public_0000-0000-0000-0003@test.orcid.org"); + e_c3ba0b26ac.setId("c3ba0b26aceb622a04908c202927db3633bd1e748e049e4bd2b070d29b189aa4"); + e_c3ba0b26ac.setOrcid("0000-0000-0000-0003"); + e_c3ba0b26ac.setPrimary(true); + e_c3ba0b26ac.setCurrent(true); + e_c3ba0b26ac.setVerified(true); + e_c3ba0b26ac.setVisibility("PUBLIC"); + e_c3ba0b26ac.setClientSourceId("APP-5555555555555555"); + MOCKS.put("c3ba0b26aceb622a04908c202927db3633bd1e748e049e4bd2b070d29b189aa4", e_c3ba0b26ac); + + EmailEntity e_f936d182c8 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_f936d182c8); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_f936d182c8); + e_f936d182c8.setEmail("public_0000-0000-0000-0003@orcid.org"); + e_f936d182c8.setId("f936d182c82f831ccee9667ac7f8fc6b9107fa5647b0c4a8250759462d5707d0"); + e_f936d182c8.setOrcid("0000-0000-0000-0003"); + e_f936d182c8.setPrimary(false); + e_f936d182c8.setCurrent(true); + e_f936d182c8.setVerified(true); + e_f936d182c8.setVisibility("PUBLIC"); + e_f936d182c8.setSourceId("0000-0000-0000-0003"); + MOCKS.put("f936d182c82f831ccee9667ac7f8fc6b9107fa5647b0c4a8250759462d5707d0", e_f936d182c8); + + EmailEntity e_71d1e18acf = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_71d1e18acf); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_71d1e18acf); + e_71d1e18acf.setEmail("limited_0000-0000-0000-0003@test.orcid.org"); + e_71d1e18acf.setId("71d1e18acf189e7b14e486a53691cef30249a3aedfd5b4c988b1754eb179e6b9"); + e_71d1e18acf.setOrcid("0000-0000-0000-0003"); + e_71d1e18acf.setPrimary(false); + e_71d1e18acf.setCurrent(true); + e_71d1e18acf.setVerified(true); + e_71d1e18acf.setVisibility("LIMITED"); + e_71d1e18acf.setClientSourceId("APP-5555555555555555"); + MOCKS.put("71d1e18acf189e7b14e486a53691cef30249a3aedfd5b4c988b1754eb179e6b9", e_71d1e18acf); + + EmailEntity e_4cccdb9a83 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_4cccdb9a83); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_4cccdb9a83); + e_4cccdb9a83.setEmail("private_0000-0000-0000-0003@test.orcid.org"); + e_4cccdb9a83.setId("4cccdb9a8342f8e7e7b730b0870664f9428f6958082957ed36e22997525fe7ce"); + e_4cccdb9a83.setOrcid("0000-0000-0000-0003"); + e_4cccdb9a83.setPrimary(false); + e_4cccdb9a83.setCurrent(true); + e_4cccdb9a83.setVerified(true); + e_4cccdb9a83.setVisibility("PRIVATE"); + e_4cccdb9a83.setClientSourceId("APP-5555555555555555"); + MOCKS.put("4cccdb9a8342f8e7e7b730b0870664f9428f6958082957ed36e22997525fe7ce", e_4cccdb9a83); + + EmailEntity e_c1a6afc0ca = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_c1a6afc0ca); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_c1a6afc0ca); + e_c1a6afc0ca.setEmail("self_limited_0000-0000-0000-0003@test.orcid.org"); + e_c1a6afc0ca.setId("c1a6afc0cace346a7f9c6cc56a28f063a8d034d1f00730f3103825ce229eac95"); + e_c1a6afc0ca.setOrcid("0000-0000-0000-0003"); + e_c1a6afc0ca.setPrimary(false); + e_c1a6afc0ca.setCurrent(true); + e_c1a6afc0ca.setVerified(true); + e_c1a6afc0ca.setVisibility("LIMITED"); + e_c1a6afc0ca.setSourceId("0000-0000-0000-0003"); + MOCKS.put("c1a6afc0cace346a7f9c6cc56a28f063a8d034d1f00730f3103825ce229eac95", e_c1a6afc0ca); + + EmailEntity e_43e9409b44 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_43e9409b44); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_43e9409b44); + e_43e9409b44.setEmail("self_private_0000-0000-0000-0003@test.orcid.org"); + e_43e9409b44.setId("43e9409b44f1875bf9df470b32555c298b6e3a5bd3a28a17b1cdc2cbeccab8d7"); + e_43e9409b44.setOrcid("0000-0000-0000-0003"); + e_43e9409b44.setPrimary(false); + e_43e9409b44.setCurrent(false); + e_43e9409b44.setVerified(false); + e_43e9409b44.setVisibility("PRIVATE"); + e_43e9409b44.setSourceId("0000-0000-0000-0003"); + MOCKS.put("43e9409b44f1875bf9df470b32555c298b6e3a5bd3a28a17b1cdc2cbeccab8d7", e_43e9409b44); + + EmailEntity e_49919fd689 = new EmailEntity(); + injectDateCreated(parseDate("None"), e_49919fd689); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), e_49919fd689); + e_49919fd689.setEmail("public_0000-0000-0000-0006@test.orcid.org"); + e_49919fd689.setId("49919fd6890f32d00cad6be9dbe277c3f1f84476d2ca0ec4dd74dbf03114b8d7"); + e_49919fd689.setOrcid("0000-0000-0000-0006"); + e_49919fd689.setPrimary(false); + e_49919fd689.setCurrent(true); + e_49919fd689.setVerified(true); + e_49919fd689.setVisibility("PUBLIC"); + e_49919fd689.setClientSourceId("APP-5555555555555556"); + MOCKS.put("49919fd6890f32d00cad6be9dbe277c3f1f84476d2ca0ec4dd74dbf03114b8d7", e_49919fd689); + + EmailEntity e_a5533ff2a3 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_a5533ff2a3); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_a5533ff2a3); + e_a5533ff2a3.setEmail("public_0000-0000-0000-0004@test.orcid.org"); + e_a5533ff2a3.setId("a5533ff2a39eae9687aea9906824e5ed9a65a350cfd8ec650b18593a2f9728b2"); + e_a5533ff2a3.setOrcid("0000-0000-0000-0004"); + e_a5533ff2a3.setPrimary(false); + e_a5533ff2a3.setCurrent(false); + e_a5533ff2a3.setVerified(false); + e_a5533ff2a3.setVisibility("PUBLIC"); + e_a5533ff2a3.setSourceId("0000-0000-0000-0004"); + MOCKS.put("a5533ff2a39eae9687aea9906824e5ed9a65a350cfd8ec650b18593a2f9728b2", e_a5533ff2a3); + + EmailEntity e_4ffaa675b0 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_4ffaa675b0); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_4ffaa675b0); + e_4ffaa675b0.setEmail("limited_0000-0000-0000-0004@test.orcid.org"); + e_4ffaa675b0.setId("4ffaa675b0a65aae1fbb715f0208d14f98fe15d11c52b0b1714f594c9237b324"); + e_4ffaa675b0.setOrcid("0000-0000-0000-0004"); + e_4ffaa675b0.setPrimary(false); + e_4ffaa675b0.setCurrent(false); + e_4ffaa675b0.setVerified(false); + e_4ffaa675b0.setVisibility("LIMITED"); + e_4ffaa675b0.setSourceId("0000-0000-0000-0004"); + MOCKS.put("4ffaa675b0a65aae1fbb715f0208d14f98fe15d11c52b0b1714f594c9237b324", e_4ffaa675b0); + + EmailEntity e_eddeca51af = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_eddeca51af); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_eddeca51af); + e_eddeca51af.setEmail("public_4444-4444-4444-4497@test.orcid.org"); + e_eddeca51af.setId("eddeca51af76b619be805d740a715921a666391dcc779f4eac7f0f71623456fc"); + e_eddeca51af.setOrcid("4444-4444-4444-4497"); + e_eddeca51af.setPrimary(true); + e_eddeca51af.setCurrent(false); + e_eddeca51af.setVerified(true); + e_eddeca51af.setVisibility("PUBLIC"); + e_eddeca51af.setSourceId("4444-4444-4444-4497"); + MOCKS.put("eddeca51af76b619be805d740a715921a666391dcc779f4eac7f0f71623456fc", e_eddeca51af); + + EmailEntity e_d40c3bf051 = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_d40c3bf051); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_d40c3bf051); + e_d40c3bf051.setEmail("limited_4444-4444-4444-4497@test.orcid.org"); + e_d40c3bf051.setId("d40c3bf0519f4584cbcd3da368b7c0def44a07b912d1e43bef1b5d695f7529b9"); + e_d40c3bf051.setOrcid("4444-4444-4444-4497"); + e_d40c3bf051.setPrimary(true); + e_d40c3bf051.setCurrent(false); + e_d40c3bf051.setVerified(true); + e_d40c3bf051.setVisibility("LIMITED"); + e_d40c3bf051.setSourceId("4444-4444-4444-4497"); + MOCKS.put("d40c3bf0519f4584cbcd3da368b7c0def44a07b912d1e43bef1b5d695f7529b9", e_d40c3bf051); + + EmailEntity e_b21fcb985d = new EmailEntity(); + injectDateCreated(parseDate("2016-01-01 00:00:00.00"), e_b21fcb985d); + injectLastModified(parseDate("2016-01-01 00:00:00.00"), e_b21fcb985d); + e_b21fcb985d.setEmail("private_4444-4444-4444-4497@test.orcid.org"); + e_b21fcb985d.setId("b21fcb985dd882e44847aafbdd0fd4c7da7b9868e38b518d443ed951b3433e92"); + e_b21fcb985d.setOrcid("4444-4444-4444-4497"); + e_b21fcb985d.setPrimary(true); + e_b21fcb985d.setCurrent(false); + e_b21fcb985d.setVerified(true); + e_b21fcb985d.setVisibility("PRIVATE"); + e_b21fcb985d.setSourceId("4444-4444-4444-4497"); + MOCKS.put("b21fcb985dd882e44847aafbdd0fd4c7da7b9868e38b518d443ed951b3433e92", e_b21fcb985d); + + EmailEntity e_5b569083f3 = new EmailEntity(); + injectDateCreated(new Date(), e_5b569083f3); + injectLastModified(new Date(), e_5b569083f3); + e_5b569083f3.setEmail("5555-5555-5555-5558@user.com"); + e_5b569083f3.setId("5b569083f34079f001b6c81bff6ec764c0c70c448f032dc79d930971aa407201"); + e_5b569083f3.setOrcid("5555-5555-5555-5558"); + e_5b569083f3.setPrimary(true); + e_5b569083f3.setCurrent(true); + e_5b569083f3.setVerified(true); + e_5b569083f3.setVisibility("PRIVATE"); + e_5b569083f3.setSourceId("5555-5555-5555-5558"); + MOCKS.put("5b569083f34079f001b6c81bff6ec764c0c70c448f032dc79d930971aa407201", e_5b569083f3); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static EmailEntity getEmail(String id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } + + private static Date parseDate(String dateStr) { + try { + if (dateStr.length() == 10) { + return new SimpleDateFormat("yyyy-MM-dd").parse(dateStr); + } + return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr); + } catch (ParseException e) { + throw new RuntimeException(e); + } + } +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ExternalIdentifierEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ExternalIdentifierEntityMocks.java new file mode 100644 index 00000000000..7a099cb9aa2 --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ExternalIdentifierEntityMocks.java @@ -0,0 +1,318 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.ExternalIdentifierEntity; + +import java.lang.reflect.Field; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class ExternalIdentifierEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + ExternalIdentifierEntity ei1 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei1); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei1); + ei1.setId(1L); + ei1.setExternalIdReference("d3clan"); + ei1.setExternalIdCommonName("Facebook"); + ei1.setOrcid("4444-4444-4444-4443"); + ei1.setExternalIdUrl("http://www.facebook.com/d3clan"); + ei1.setSourceId("4444-4444-4444-4441"); + ei1.setVisibility("PUBLIC"); + ei1.setDisplayIndex(0L); + MOCKS.put(1L, ei1); + + ExternalIdentifierEntity ei2 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei2); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei2); + ei2.setId(2L); + ei2.setExternalIdReference("abc123"); + ei2.setExternalIdCommonName("Facebook"); + ei2.setOrcid("4444-4444-4444-4442"); + ei2.setExternalIdUrl("http://www.facebook.com/abc123"); + ei2.setClientSourceId("APP-5555555555555555"); + ei2.setVisibility("PUBLIC"); + ei2.setDisplayIndex(0L); + MOCKS.put(2L, ei2); + + ExternalIdentifierEntity ei3 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei3); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei3); + ei3.setId(3L); + ei3.setExternalIdReference("abc456"); + ei3.setExternalIdCommonName("Facebook"); + ei3.setOrcid("4444-4444-4444-4442"); + ei3.setExternalIdUrl("http://www.facebook.com/abc456"); + ei3.setSourceId("4444-4444-4444-4442"); + ei3.setVisibility("LIMITED"); + ei3.setDisplayIndex(0L); + MOCKS.put(3L, ei3); + + ExternalIdentifierEntity ei4 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei4); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei4); + ei4.setId(4L); + ei4.setExternalIdReference("abc789"); + ei4.setExternalIdCommonName("Facebook"); + ei4.setOrcid("4444-4444-4444-4442"); + ei4.setExternalIdUrl("http://www.facebook.com/abc789"); + ei4.setSourceId("4444-4444-4444-4441"); + ei4.setVisibility("PRIVATE"); + ei4.setDisplayIndex(0L); + MOCKS.put(4L, ei4); + + ExternalIdentifierEntity ei5 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei5); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei5); + ei5.setId(5L); + ei5.setExternalIdReference("abc012"); + ei5.setExternalIdCommonName("Facebook"); + ei5.setOrcid("4444-4444-4444-4442"); + ei5.setExternalIdUrl("http://www.facebook.com/abc012"); + ei5.setClientSourceId("APP-5555555555555555"); + ei5.setVisibility("PRIVATE"); + ei5.setDisplayIndex(0L); + MOCKS.put(5L, ei5); + + ExternalIdentifierEntity ei6 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei6); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei6); + ei6.setId(6L); + ei6.setExternalIdReference("xyz012"); + ei6.setExternalIdCommonName("Google"); + ei6.setOrcid("4444-4444-4444-4444"); + ei6.setExternalIdUrl("http://www.google.com/xyz012"); + ei6.setClientSourceId("APP-5555555555555555"); + ei6.setVisibility("PUBLIC"); + ei6.setDisplayIndex(0L); + MOCKS.put(6L, ei6); + + ExternalIdentifierEntity ei7 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei7); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei7); + ei7.setId(7L); + ei7.setExternalIdReference("A-0001"); + ei7.setExternalIdCommonName("A-0001"); + ei7.setOrcid("4444-4444-4444-4441"); + ei7.setExternalIdUrl("http://ext-id/A-0001"); + ei7.setClientSourceId("APP-5555555555555555"); + ei7.setVisibility("PUBLIC"); + ei7.setDisplayIndex(0L); + MOCKS.put(7L, ei7); + + ExternalIdentifierEntity ei8 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei8); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei8); + ei8.setId(8L); + ei8.setExternalIdReference("A-0002"); + ei8.setExternalIdCommonName("A-0002"); + ei8.setOrcid("4444-4444-4444-4441"); + ei8.setExternalIdUrl("http://ext-id/A-0002"); + ei8.setClientSourceId("APP-5555555555555555"); + ei8.setVisibility("LIMITED"); + ei8.setDisplayIndex(0L); + MOCKS.put(8L, ei8); + + ExternalIdentifierEntity ei9 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei9); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei9); + ei9.setId(9L); + ei9.setExternalIdReference("ref1"); + ei9.setExternalIdCommonName("type1"); + ei9.setOrcid("4444-4444-4444-4497"); + ei9.setExternalIdUrl("http://ext-id/ref1"); + ei9.setClientSourceId("APP-5555555555555556"); + ei9.setVisibility("PRIVATE"); + ei9.setDisplayIndex(0L); + MOCKS.put(9L, ei9); + + ExternalIdentifierEntity ei10 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei10); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei10); + ei10.setId(10L); + ei10.setExternalIdReference("ref2"); + ei10.setExternalIdCommonName("type2"); + ei10.setOrcid("4444-4444-4444-4497"); + ei10.setExternalIdUrl("http://ext-id/ref2"); + ei10.setClientSourceId("APP-5555555555555555"); + ei10.setVisibility("PRIVATE"); + ei10.setDisplayIndex(0L); + MOCKS.put(10L, ei10); + + ExternalIdentifierEntity ei11 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei11); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei11); + ei11.setId(11L); + ei11.setExternalIdReference("ref3"); + ei11.setExternalIdCommonName("type3"); + ei11.setOrcid("4444-4444-4444-4497"); + ei11.setExternalIdUrl("http://ext-id/ref3"); + ei11.setClientSourceId("APP-5555555555555555"); + ei11.setVisibility("LIMITED"); + ei11.setDisplayIndex(0L); + MOCKS.put(11L, ei11); + + ExternalIdentifierEntity ei12 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei12); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei12); + ei12.setId(12L); + ei12.setExternalIdReference("ref4"); + ei12.setExternalIdCommonName("type4"); + ei12.setOrcid("4444-4444-4444-4497"); + ei12.setExternalIdUrl("http://ext-id/ref4"); + ei12.setClientSourceId("APP-5555555555555555"); + ei12.setVisibility("PUBLIC"); + ei12.setDisplayIndex(0L); + MOCKS.put(12L, ei12); + + ExternalIdentifierEntity ei13 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei13); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei13); + ei13.setId(13L); + ei13.setExternalIdReference("public_ref"); + ei13.setExternalIdCommonName("public_type"); + ei13.setOrcid("0000-0000-0000-0003"); + ei13.setExternalIdUrl("http://ext-id/public_ref"); + ei13.setClientSourceId("APP-5555555555555555"); + ei13.setVisibility("PUBLIC"); + ei13.setDisplayIndex(0L); + MOCKS.put(13L, ei13); + + ExternalIdentifierEntity ei14 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei14); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei14); + ei14.setId(14L); + ei14.setExternalIdReference("limited_ref"); + ei14.setExternalIdCommonName("limited_type"); + ei14.setOrcid("0000-0000-0000-0003"); + ei14.setExternalIdUrl("http://ext-id/limited_ref"); + ei14.setClientSourceId("APP-5555555555555555"); + ei14.setVisibility("LIMITED"); + ei14.setDisplayIndex(1L); + MOCKS.put(14L, ei14); + + ExternalIdentifierEntity ei15 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei15); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei15); + ei15.setId(15L); + ei15.setExternalIdReference("private_ref"); + ei15.setExternalIdCommonName("private_type"); + ei15.setOrcid("0000-0000-0000-0003"); + ei15.setExternalIdUrl("http://ext-id/private_ref"); + ei15.setClientSourceId("APP-5555555555555555"); + ei15.setVisibility("PRIVATE"); + ei15.setDisplayIndex(2L); + MOCKS.put(15L, ei15); + + ExternalIdentifierEntity ei16 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei16); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei16); + ei16.setId(16L); + ei16.setExternalIdReference("self_limited_ref"); + ei16.setExternalIdCommonName("self_limited_type"); + ei16.setOrcid("0000-0000-0000-0003"); + ei16.setExternalIdUrl("http://ext-id/self/limited"); + ei16.setSourceId("0000-0000-0000-0003"); + ei16.setVisibility("LIMITED"); + ei16.setDisplayIndex(3L); + MOCKS.put(16L, ei16); + + ExternalIdentifierEntity ei17 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei17); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei17); + ei17.setId(17L); + ei17.setExternalIdReference("self_private_ref"); + ei17.setExternalIdCommonName("self_private_type"); + ei17.setOrcid("0000-0000-0000-0003"); + ei17.setExternalIdUrl("http://ext-id/self/private"); + ei17.setSourceId("0000-0000-0000-0003"); + ei17.setVisibility("PRIVATE"); + ei17.setDisplayIndex(4L); + MOCKS.put(17L, ei17); + + ExternalIdentifierEntity ei18 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:32:00.00"), ei18); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei18); + ei18.setId(18L); + ei18.setExternalIdReference("self_public_ref"); + ei18.setExternalIdCommonName("self_public_type"); + ei18.setOrcid("0000-0000-0000-0003"); + ei18.setExternalIdUrl("http://ext-id/self/public"); + ei18.setSourceId("0000-0000-0000-0003"); + ei18.setVisibility("PUBLIC"); + ei18.setDisplayIndex(5L); + MOCKS.put(18L, ei18); + + ExternalIdentifierEntity ei19 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:32:00.00"), ei19); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei19); + ei19.setId(19L); + ei19.setExternalIdReference("self_public_user_obo_ref"); + ei19.setExternalIdCommonName("self_public_user_obo_type"); + ei19.setOrcid("0000-0000-0000-0003"); + ei19.setExternalIdUrl("http://ext-id/self/obo/public"); + ei19.setClientSourceId("APP-5555555555555558"); + ei19.setVisibility("PUBLIC"); + ei19.setDisplayIndex(6L); + MOCKS.put(19L, ei19); + + ExternalIdentifierEntity ei20 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei20); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei20); + ei20.setId(20L); + ei20.setExternalIdReference("public"); + ei20.setExternalIdCommonName("public"); + ei20.setOrcid("0000-0000-0000-0001"); + ei20.setExternalIdUrl("http://ext-id/self/public"); + ei20.setClientSourceId("APP-5555555555555555"); + ei20.setVisibility("PUBLIC"); + ei20.setDisplayIndex(1L); + MOCKS.put(20L, ei20); + + ExternalIdentifierEntity ei21 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei21); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei21); + ei21.setId(21L); + ei21.setExternalIdReference("limited"); + ei21.setExternalIdCommonName("limited"); + ei21.setOrcid("0000-0000-0000-0001"); + ei21.setExternalIdUrl("http://ext-id/self/limited"); + ei21.setClientSourceId("APP-5555555555555555"); + ei21.setVisibility("LIMITED"); + ei21.setDisplayIndex(2L); + MOCKS.put(21L, ei21); + + ExternalIdentifierEntity ei22 = new ExternalIdentifierEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ei22); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ei22); + ei22.setId(22L); + ei22.setExternalIdReference("private"); + ei22.setExternalIdCommonName("private"); + ei22.setOrcid("0000-0000-0000-0001"); + ei22.setExternalIdUrl("http://ext-id/self/private"); + ei22.setClientSourceId("APP-5555555555555555"); + ei22.setVisibility("PRIVATE"); + ei22.setDisplayIndex(2L); + MOCKS.put(22L, ei22); + + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public static ExternalIdentifierEntity getExternalIdentifier(Long id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/MocksHelper.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/MocksHelper.java new file mode 100644 index 00000000000..d92a52e9433 --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/MocksHelper.java @@ -0,0 +1,44 @@ +package org.orcid.persistence.test.mocks; + +import java.lang.reflect.Field; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class MocksHelper { + static Date parseDate(String dateStr) { + try { + if (dateStr.length() == 10) { + return new SimpleDateFormat("yyyy-MM-dd").parse(dateStr); + } + return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr); + } catch (ParseException e) { + throw new RuntimeException(e); + } + } + + static void injectDateCreated(Date dateCreated, Object o) throws NoSuchFieldException, IllegalAccessException { + Field field = getField(o.getClass(), "dateCreated"); + field.setAccessible(true); + field.set(o, dateCreated); + field.setAccessible(false); + } + + static void injectLastModified(Date lastModified, Object o) throws NoSuchFieldException, IllegalAccessException { + Field field = getField(o.getClass(), "lastModified"); + field.setAccessible(true); + field.set(o, lastModified); + field.setAccessible(false); + } + + private static Field getField(Class clazz, String fieldName) throws NoSuchFieldException { + try { + return clazz.getDeclaredField(fieldName); + } catch (NoSuchFieldException e) { + if (clazz.getSuperclass() != null) { + return getField(clazz.getSuperclass(), fieldName); + } + throw e; + } + } +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/OtherNameEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/OtherNameEntityMocks.java new file mode 100644 index 00000000000..1e7eeb5e078 --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/OtherNameEntityMocks.java @@ -0,0 +1,251 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.OtherNameEntity; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class OtherNameEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + OtherNameEntity on1 = new OtherNameEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), on1); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), on1); + on1.setId(1L); + on1.setDisplayName("Slibberdy Slabinah"); + on1.setOrcid("4444-4444-4444-4443"); + on1.setClientSourceId("APP-5555555555555555"); + on1.setVisibility("PUBLIC"); + on1.setDisplayIndex(0L); + MOCKS.put(1L, on1); + + OtherNameEntity on2 = new OtherNameEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), on2); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), on2); + on2.setId(2L); + on2.setDisplayName("Flibberdy Flabinah"); + on2.setOrcid("4444-4444-4444-4443"); + on2.setSourceId("4444-4444-4444-4443"); + on2.setVisibility("PUBLIC"); + on2.setDisplayIndex(0L); + MOCKS.put(2L, on2); + + OtherNameEntity on3 = new OtherNameEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), on3); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), on3); + on3.setId(3L); + on3.setDisplayName("other-name-1"); + on3.setOrcid("4444-4444-4444-4441"); + on3.setSourceId("4444-4444-4444-4441"); + on3.setVisibility("PUBLIC"); + on3.setDisplayIndex(0L); + MOCKS.put(3L, on3); + + OtherNameEntity on4 = new OtherNameEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), on4); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), on4); + on4.setId(4L); + on4.setDisplayName("other-name-2"); + on4.setOrcid("4444-4444-4444-4441"); + on4.setSourceId("4444-4444-4444-4441"); + on4.setVisibility("PUBLIC"); + on4.setDisplayIndex(0L); + MOCKS.put(4L, on4); + + OtherNameEntity on5 = new OtherNameEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), on5); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), on5); + on5.setId(5L); + on5.setDisplayName("Other Name # 1"); + on5.setOrcid("4444-4444-4444-4446"); + on5.setClientSourceId("APP-5555555555555555"); + on5.setVisibility("PUBLIC"); + on5.setDisplayIndex(0L); + MOCKS.put(5L, on5); + + OtherNameEntity on6 = new OtherNameEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), on6); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), on6); + on6.setId(6L); + on6.setDisplayName("Other Name # 2"); + on6.setOrcid("4444-4444-4444-4446"); + on6.setSourceId("4444-4444-4444-4446"); + on6.setVisibility("LIMITED"); + on6.setDisplayIndex(0L); + MOCKS.put(6L, on6); + + OtherNameEntity on7 = new OtherNameEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), on7); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), on7); + on7.setId(7L); + on7.setDisplayName("Other Name # 3"); + on7.setOrcid("4444-4444-4444-4446"); + on7.setSourceId("4444-4444-4444-4446"); + on7.setVisibility("PRIVATE"); + on7.setDisplayIndex(0L); + MOCKS.put(7L, on7); + + OtherNameEntity on8 = new OtherNameEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), on8); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), on8); + on8.setId(8L); + on8.setDisplayName("Other Name # 4"); + on8.setOrcid("4444-4444-4444-4446"); + on8.setClientSourceId("APP-5555555555555555"); + on8.setVisibility("PRIVATE"); + on8.setDisplayIndex(0L); + MOCKS.put(8L, on8); + + OtherNameEntity on9 = new OtherNameEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), on9); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), on9); + on9.setId(9L); + on9.setDisplayName("Other Name # 1"); + on9.setOrcid("4444-4444-4444-4447"); + on9.setClientSourceId("APP-5555555555555555"); + on9.setVisibility("PUBLIC"); + on9.setDisplayIndex(0L); + MOCKS.put(9L, on9); + + OtherNameEntity on10 = new OtherNameEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), on10); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), on10); + on10.setId(10L); + on10.setDisplayName("Other Name # 1"); + on10.setOrcid("4444-4444-4444-4442"); + on10.setClientSourceId("APP-5555555555555555"); + on10.setVisibility("PUBLIC"); + on10.setDisplayIndex(0L); + MOCKS.put(10L, on10); + + OtherNameEntity on11 = new OtherNameEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), on11); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), on11); + on11.setId(11L); + on11.setDisplayName("Other Name # 2"); + on11.setOrcid("4444-4444-4444-4442"); + on11.setClientSourceId("APP-5555555555555555"); + on11.setVisibility("PRIVATE"); + on11.setDisplayIndex(0L); + MOCKS.put(11L, on11); + + OtherNameEntity on12 = new OtherNameEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), on12); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), on12); + on12.setId(12L); + on12.setDisplayName("Other Name # 3"); + on12.setOrcid("4444-4444-4444-4442"); + on12.setSourceId("4444-4444-4444-4442"); + on12.setVisibility("PRIVATE"); + on12.setDisplayIndex(0L); + MOCKS.put(12L, on12); + + OtherNameEntity on13 = new OtherNameEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), on13); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), on13); + on13.setId(13L); + on13.setDisplayName("Other Name PUBLIC"); + on13.setOrcid("0000-0000-0000-0003"); + on13.setClientSourceId("APP-5555555555555555"); + on13.setVisibility("PUBLIC"); + on13.setDisplayIndex(0L); + MOCKS.put(13L, on13); + + OtherNameEntity on14 = new OtherNameEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), on14); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), on14); + on14.setId(14L); + on14.setDisplayName("Other Name LIMITED"); + on14.setOrcid("0000-0000-0000-0003"); + on14.setClientSourceId("APP-5555555555555555"); + on14.setVisibility("LIMITED"); + on14.setDisplayIndex(1L); + MOCKS.put(14L, on14); + + OtherNameEntity on15 = new OtherNameEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), on15); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), on15); + on15.setId(15L); + on15.setDisplayName("Other Name PRIVATE"); + on15.setOrcid("0000-0000-0000-0003"); + on15.setClientSourceId("APP-5555555555555555"); + on15.setVisibility("PRIVATE"); + on15.setDisplayIndex(2L); + MOCKS.put(15L, on15); + + OtherNameEntity on16 = new OtherNameEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), on16); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), on16); + on16.setId(16L); + on16.setDisplayName("Other Name SELF LIMITED"); + on16.setOrcid("0000-0000-0000-0003"); + on16.setSourceId("0000-0000-0000-0003"); + on16.setVisibility("LIMITED"); + on16.setDisplayIndex(3L); + MOCKS.put(16L, on16); + + OtherNameEntity on17 = new OtherNameEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), on17); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), on17); + on17.setId(17L); + on17.setDisplayName("Other Name SELF PRIVATE"); + on17.setOrcid("0000-0000-0000-0003"); + on17.setSourceId("0000-0000-0000-0003"); + on17.setVisibility("PRIVATE"); + on17.setDisplayIndex(4L); + MOCKS.put(17L, on17); + + OtherNameEntity on18 = new OtherNameEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), on18); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), on18); + on18.setId(18L); + on18.setDisplayName("PUBLIC"); + on18.setOrcid("0000-0000-0000-0001"); + on18.setClientSourceId("APP-5555555555555555"); + on18.setVisibility("PUBLIC"); + on18.setDisplayIndex(1L); + MOCKS.put(18L, on18); + + OtherNameEntity on19 = new OtherNameEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), on19); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), on19); + on19.setId(19L); + on19.setDisplayName("LIMITED"); + on19.setOrcid("0000-0000-0000-0001"); + on19.setClientSourceId("APP-5555555555555555"); + on19.setVisibility("LIMITED"); + on19.setDisplayIndex(2L); + MOCKS.put(19L, on19); + + OtherNameEntity on20 = new OtherNameEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), on20); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), on20); + on20.setId(20L); + on20.setDisplayName("PRIVATE"); + on20.setOrcid("0000-0000-0000-0001"); + on20.setClientSourceId("APP-5555555555555555"); + on20.setVisibility("PRIVATE"); + on20.setDisplayIndex(3L); + MOCKS.put(20L, on20); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static OtherNameEntity getOtherName(Long id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } + +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ProfileEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ProfileEntityMocks.java new file mode 100644 index 00000000000..12c60692d76 --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ProfileEntityMocks.java @@ -0,0 +1,460 @@ + package org.orcid.persistence.test.mocks; + + import org.orcid.persistence.jpa.entities.ProfileEntity; + import org.orcid.persistence.jpa.entities.IndexingStatus; + + import java.lang.reflect.Field; + import java.util.Date; + import java.util.HashMap; + import java.util.Map; + import java.text.SimpleDateFormat; + import java.text.ParseException; + + import static org.orcid.persistence.test.mocks.MocksHelper.*; + + public class ProfileEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + ProfileEntity p4444_4444_4444_4441 = new ProfileEntity("4444-4444-4444-4441"); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), p4444_4444_4444_4441); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), p4444_4444_4444_4441); + p4444_4444_4444_4441.setCreationMethod("API"); + p4444_4444_4444_4441.setCompletedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4441.setSubmissionDate(parseDate("2011-06-29 15:31:00.00")); + p4444_4444_4444_4441.setLastIndexedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4441.setClaimed(true); + p4444_4444_4444_4441.setIsSelectableSponsor(false); + p4444_4444_4444_4441.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p4444_4444_4444_4441.setActivitiesVisibilityDefault("PUBLIC"); + p4444_4444_4444_4441.setIndexingStatus(IndexingStatus.DONE); + p4444_4444_4444_4441.setOrcidType("CLIENT"); + p4444_4444_4444_4441.setReviewed(false); + p4444_4444_4444_4441.setRecordLocked(false); + MOCKS.put("4444-4444-4444-4441", p4444_4444_4444_4441); + + ProfileEntity p4444_4444_4444_4442 = new ProfileEntity("4444-4444-4444-4442"); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), p4444_4444_4444_4442); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), p4444_4444_4444_4442); + p4444_4444_4444_4442.setCreationMethod("API"); + p4444_4444_4444_4442.setCompletedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4442.setSubmissionDate(parseDate("2011-06-29 15:31:00.00")); + p4444_4444_4444_4442.setLastIndexedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4442.setClaimed(true); + p4444_4444_4444_4442.setIsSelectableSponsor(false); + p4444_4444_4444_4442.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p4444_4444_4444_4442.setActivitiesVisibilityDefault("LIMITED"); + p4444_4444_4444_4442.setIndexingStatus(IndexingStatus.DONE); + p4444_4444_4444_4442.setOrcidType("USER"); + p4444_4444_4444_4442.setReviewed(true); + p4444_4444_4444_4442.setRecordLocked(false); + MOCKS.put("4444-4444-4444-4442", p4444_4444_4444_4442); + + ProfileEntity p4444_4444_4444_4443 = new ProfileEntity("4444-4444-4444-4443"); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), p4444_4444_4444_4443); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), p4444_4444_4444_4443); + p4444_4444_4444_4443.setCreationMethod("API"); + p4444_4444_4444_4443.setCompletedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4443.setSubmissionDate(parseDate("2011-06-29 15:31:00.00")); + p4444_4444_4444_4443.setLastIndexedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4443.setClaimed(true); + p4444_4444_4444_4443.setIsSelectableSponsor(false); + p4444_4444_4444_4443.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p4444_4444_4444_4443.setActivitiesVisibilityDefault("PUBLIC"); + p4444_4444_4444_4443.setIndexingStatus(IndexingStatus.DONE); + p4444_4444_4444_4443.setOrcidType("CLIENT"); + p4444_4444_4444_4443.setReviewed(false); + p4444_4444_4444_4443.setRecordLocked(false); + p4444_4444_4444_4443.setUsing2FA(false); + p4444_4444_4444_4443.setSecretFor2FA("secret"); + MOCKS.put("4444-4444-4444-4443", p4444_4444_4444_4443); + + ProfileEntity p4444_4444_4444_4444 = new ProfileEntity("4444-4444-4444-4444"); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), p4444_4444_4444_4444); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), p4444_4444_4444_4444); + p4444_4444_4444_4444.setCreationMethod("API"); + p4444_4444_4444_4444.setCompletedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4444.setSubmissionDate(parseDate("2011-06-29 15:31:00.00")); + p4444_4444_4444_4444.setLastIndexedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4444.setClaimed(true); + p4444_4444_4444_4444.setIsSelectableSponsor(true); + p4444_4444_4444_4444.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p4444_4444_4444_4444.setActivitiesVisibilityDefault("PRIVATE"); + p4444_4444_4444_4444.setIndexingStatus(IndexingStatus.DONE); + p4444_4444_4444_4444.setOrcidType("CLIENT"); + p4444_4444_4444_4444.setReviewed(false); + p4444_4444_4444_4444.setRecordLocked(false); + MOCKS.put("4444-4444-4444-4444", p4444_4444_4444_4444); + + ProfileEntity p4444_4444_4444_4445 = new ProfileEntity("4444-4444-4444-4445"); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), p4444_4444_4444_4445); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), p4444_4444_4444_4445); + p4444_4444_4444_4445.setCreationMethod("API"); + p4444_4444_4444_4445.setCompletedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4445.setSubmissionDate(parseDate("2011-06-29 15:31:00.00")); + p4444_4444_4444_4445.setLastIndexedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4445.setClaimed(true); + p4444_4444_4444_4445.setIsSelectableSponsor(false); + p4444_4444_4444_4445.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p4444_4444_4444_4445.setActivitiesVisibilityDefault("PRIVATE"); + p4444_4444_4444_4445.setIndexingStatus(IndexingStatus.PENDING); + p4444_4444_4444_4445.setOrcidType("CLIENT"); + p4444_4444_4444_4445.setReviewed(false); + p4444_4444_4444_4445.setRecordLocked(false); + MOCKS.put("4444-4444-4444-4445", p4444_4444_4444_4445); + + ProfileEntity p4444_4444_4444_4446 = new ProfileEntity("4444-4444-4444-4446"); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), p4444_4444_4444_4446); + injectLastModified(parseDate("2011-07-02 15:32:00.00"), p4444_4444_4444_4446); + p4444_4444_4444_4446.setCreationMethod("API"); + p4444_4444_4444_4446.setCompletedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4446.setSubmissionDate(parseDate("2011-06-29 15:31:00.00")); + p4444_4444_4444_4446.setLastIndexedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4446.setClaimed(true); + p4444_4444_4444_4446.setIsSelectableSponsor(true); + p4444_4444_4444_4446.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p4444_4444_4444_4446.setActivitiesVisibilityDefault("LIMITED"); + p4444_4444_4444_4446.setIndexingStatus(IndexingStatus.PENDING); + p4444_4444_4444_4446.setOrcidType("GROUP"); + p4444_4444_4444_4446.setReviewed(false); + p4444_4444_4444_4446.setRecordLocked(false); + p4444_4444_4444_4446.setUsing2FA(false); + p4444_4444_4444_4446.setSecretFor2FA("secret"); + MOCKS.put("4444-4444-4444-4446", p4444_4444_4444_4446); + + ProfileEntity p4444_4444_4444_4447 = new ProfileEntity("4444-4444-4444-4447"); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), p4444_4444_4444_4447); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), p4444_4444_4444_4447); + p4444_4444_4444_4447.setCreationMethod("API"); + p4444_4444_4444_4447.setCompletedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4447.setSubmissionDate(parseDate("2011-06-29 15:31:00.00")); + p4444_4444_4444_4447.setLastIndexedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4447.setClaimed(false); + p4444_4444_4444_4447.setIsSelectableSponsor(true); + p4444_4444_4444_4447.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p4444_4444_4444_4447.setActivitiesVisibilityDefault("PRIVATE"); + p4444_4444_4444_4447.setIndexingStatus(IndexingStatus.DONE); + p4444_4444_4444_4447.setOrcidType("USER"); + p4444_4444_4444_4447.setReviewed(false); + p4444_4444_4444_4447.setRecordLocked(false); + p4444_4444_4444_4447.setUsing2FA(false); + p4444_4444_4444_4447.setSecretFor2FA("secret"); + MOCKS.put("4444-4444-4444-4447", p4444_4444_4444_4447); + + ProfileEntity p4444_4444_4444_444X = new ProfileEntity("4444-4444-4444-444X"); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), p4444_4444_4444_444X); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), p4444_4444_4444_444X); + p4444_4444_4444_444X.setCreationMethod("API"); + p4444_4444_4444_444X.setCompletedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_444X.setSubmissionDate(parseDate("2011-06-29 15:31:00.00")); + p4444_4444_4444_444X.setLastIndexedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_444X.setClaimed(true); + p4444_4444_4444_444X.setIsSelectableSponsor(true); + p4444_4444_4444_444X.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p4444_4444_4444_444X.setActivitiesVisibilityDefault("PRIVATE"); + p4444_4444_4444_444X.setIndexingStatus(IndexingStatus.DONE); + p4444_4444_4444_444X.setOrcidType("USER"); + p4444_4444_4444_444X.setReviewed(false); + p4444_4444_4444_444X.setRecordLocked(false); + p4444_4444_4444_444X.setUsing2FA(false); + p4444_4444_4444_444X.setSecretFor2FA("secret"); + MOCKS.put("4444-4444-4444-444X", p4444_4444_4444_444X); + + ProfileEntity p4444_4444_4444_4440 = new ProfileEntity("4444-4444-4444-4440"); + injectDateCreated(parseDate("2014-03-06 15:31:00.00"), p4444_4444_4444_4440); + injectLastModified(parseDate("2014-03-06 15:32:00.00"), p4444_4444_4444_4440); + p4444_4444_4444_4440.setCreationMethod("API"); + p4444_4444_4444_4440.setCompletedDate(parseDate("2014-03-06 15:31:00.00")); + p4444_4444_4444_4440.setSubmissionDate(parseDate("2014-03-06 15:31:00.00")); + p4444_4444_4444_4440.setLastIndexedDate(parseDate("2014-03-06 15:31:00.00")); + p4444_4444_4444_4440.setClaimed(true); + p4444_4444_4444_4440.setIsSelectableSponsor(true); + p4444_4444_4444_4440.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p4444_4444_4444_4440.setActivitiesVisibilityDefault("PRIVATE"); + p4444_4444_4444_4440.setIndexingStatus(IndexingStatus.DONE); + p4444_4444_4444_4440.setOrcidType("ADMIN"); + p4444_4444_4444_4440.setReviewed(false); + p4444_4444_4444_4440.setRecordLocked(false); + p4444_4444_4444_4440.setUsing2FA(false); + p4444_4444_4444_4440.setSecretFor2FA("secret"); + MOCKS.put("4444-4444-4444-4440", p4444_4444_4444_4440); + + ProfileEntity p4444_4444_4444_4499 = new ProfileEntity("4444-4444-4444-4499"); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), p4444_4444_4444_4499); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), p4444_4444_4444_4499); + p4444_4444_4444_4499.setCreationMethod("API"); + p4444_4444_4444_4499.setCompletedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4499.setSubmissionDate(parseDate("2011-06-29 15:31:00.00")); + p4444_4444_4444_4499.setLastIndexedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4499.setClaimed(true); + p4444_4444_4444_4499.setIsSelectableSponsor(false); + p4444_4444_4444_4499.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p4444_4444_4444_4499.setActivitiesVisibilityDefault("PUBLIC"); + p4444_4444_4444_4499.setIndexingStatus(IndexingStatus.DONE); + p4444_4444_4444_4499.setOrcidType("USER"); + p4444_4444_4444_4499.setReviewed(false); + p4444_4444_4444_4499.setRecordLocked(false); + p4444_4444_4444_4499.setUsing2FA(false); + p4444_4444_4444_4499.setSecretFor2FA("secret"); + MOCKS.put("4444-4444-4444-4499", p4444_4444_4444_4499); + + ProfileEntity p4444_4444_4444_4498 = new ProfileEntity("4444-4444-4444-4498"); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), p4444_4444_4444_4498); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), p4444_4444_4444_4498); + p4444_4444_4444_4498.setCreationMethod("API"); + p4444_4444_4444_4498.setCompletedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4498.setSubmissionDate(parseDate("2011-06-29 15:31:00.00")); + p4444_4444_4444_4498.setLastIndexedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4498.setClaimed(true); + p4444_4444_4444_4498.setIsSelectableSponsor(false); + p4444_4444_4444_4498.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p4444_4444_4444_4498.setActivitiesVisibilityDefault("PRIVATE"); + p4444_4444_4444_4498.setIndexingStatus(IndexingStatus.DONE); + p4444_4444_4444_4498.setOrcidType("CLIENT"); + p4444_4444_4444_4498.setReviewed(false); + p4444_4444_4444_4498.setRecordLocked(false); + p4444_4444_4444_4498.setUsing2FA(false); + p4444_4444_4444_4498.setSecretFor2FA("secret"); + MOCKS.put("4444-4444-4444-4498", p4444_4444_4444_4498); + + ProfileEntity p4444_4444_4444_4497 = new ProfileEntity("4444-4444-4444-4497"); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), p4444_4444_4444_4497); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), p4444_4444_4444_4497); + p4444_4444_4444_4497.setCreationMethod("API"); + p4444_4444_4444_4497.setCompletedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4497.setSubmissionDate(parseDate("2011-06-29 15:31:00.00")); + p4444_4444_4444_4497.setLastIndexedDate(parseDate("2011-07-02 15:31:00.00")); + p4444_4444_4444_4497.setClaimed(true); + p4444_4444_4444_4497.setIsSelectableSponsor(false); + p4444_4444_4444_4497.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p4444_4444_4444_4497.setActivitiesVisibilityDefault("PUBLIC"); + p4444_4444_4444_4497.setIndexingStatus(IndexingStatus.DONE); + p4444_4444_4444_4497.setOrcidType("USER"); + p4444_4444_4444_4497.setReviewed(false); + p4444_4444_4444_4497.setRecordLocked(false); + p4444_4444_4444_4497.setUsing2FA(false); + p4444_4444_4444_4497.setSecretFor2FA("secret"); + MOCKS.put("4444-4444-4444-4497", p4444_4444_4444_4497); + + ProfileEntity p0000_0000_0000_0001 = new ProfileEntity("0000-0000-0000-0001"); + injectDateCreated(parseDate("2016-01-01 15:31:00.00"), p0000_0000_0000_0001); + injectLastModified(parseDate("2016-01-01 15:31:00.00"), p0000_0000_0000_0001); + p0000_0000_0000_0001.setCreationMethod("API"); + p0000_0000_0000_0001.setCompletedDate(parseDate("2016-12-12 00:00:00.00")); + p0000_0000_0000_0001.setSubmissionDate(parseDate("2016-01-01 15:31:00.00")); + p0000_0000_0000_0001.setLastIndexedDate(parseDate("2016-01-01 15:31:00.00")); + p0000_0000_0000_0001.setClaimed(false); + p0000_0000_0000_0001.setIsSelectableSponsor(false); + p0000_0000_0000_0001.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p0000_0000_0000_0001.setActivitiesVisibilityDefault("LIMITED"); + p0000_0000_0000_0001.setIndexingStatus(IndexingStatus.DONE); + p0000_0000_0000_0001.setOrcidType("USER"); + p0000_0000_0000_0001.setReviewed(true); + p0000_0000_0000_0001.setRecordLocked(false); + p0000_0000_0000_0001.setUsing2FA(false); + p0000_0000_0000_0001.setSecretFor2FA("secret"); + MOCKS.put("0000-0000-0000-0001", p0000_0000_0000_0001); + + ProfileEntity p0000_0000_0000_0002 = new ProfileEntity("0000-0000-0000-0002"); + injectDateCreated(parseDate("2016-03-29 15:31:00.00"), p0000_0000_0000_0002); + injectLastModified(parseDate("2016-03-29 15:31:00.00"), p0000_0000_0000_0002); + p0000_0000_0000_0002.setCreationMethod("API"); + p0000_0000_0000_0002.setCompletedDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0002.setSubmissionDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0002.setLastIndexedDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0002.setClaimed(true); + p0000_0000_0000_0002.setIsSelectableSponsor(false); + p0000_0000_0000_0002.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p0000_0000_0000_0002.setActivitiesVisibilityDefault("LIMITED"); + p0000_0000_0000_0002.setIndexingStatus(IndexingStatus.DONE); + p0000_0000_0000_0002.setOrcidType("USER"); + p0000_0000_0000_0002.setReviewed(true); + p0000_0000_0000_0002.setRecordLocked(false); + p0000_0000_0000_0002.setUsing2FA(false); + p0000_0000_0000_0002.setSecretFor2FA("secret"); + MOCKS.put("0000-0000-0000-0002", p0000_0000_0000_0002); + + ProfileEntity p0000_0000_0000_0003 = new ProfileEntity("0000-0000-0000-0003"); + injectDateCreated(parseDate("2016-03-29 15:31:00.00"), p0000_0000_0000_0003); + injectLastModified(parseDate("2016-03-29 15:31:00.00"), p0000_0000_0000_0003); + p0000_0000_0000_0003.setCreationMethod("integration-test"); + p0000_0000_0000_0003.setCompletedDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0003.setSubmissionDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0003.setLastIndexedDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0003.setClaimed(true); + p0000_0000_0000_0003.setIsSelectableSponsor(false); + p0000_0000_0000_0003.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p0000_0000_0000_0003.setActivitiesVisibilityDefault("PUBLIC"); + p0000_0000_0000_0003.setIndexingStatus(IndexingStatus.DONE); + p0000_0000_0000_0003.setOrcidType("USER"); + p0000_0000_0000_0003.setReviewed(true); + p0000_0000_0000_0003.setRecordLocked(false); + p0000_0000_0000_0003.setUsing2FA(false); + p0000_0000_0000_0003.setSecretFor2FA("secret"); + MOCKS.put("0000-0000-0000-0003", p0000_0000_0000_0003); + + ProfileEntity p0000_0000_0000_0004 = new ProfileEntity("0000-0000-0000-0004"); + injectDateCreated(parseDate("2016-03-29 15:31:00.00"), p0000_0000_0000_0004); + injectLastModified(parseDate("2016-03-29 15:31:00.00"), p0000_0000_0000_0004); + p0000_0000_0000_0004.setCreationMethod("integration-test"); + p0000_0000_0000_0004.setCompletedDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0004.setSubmissionDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0004.setLastIndexedDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0004.setClaimed(true); + p0000_0000_0000_0004.setIsSelectableSponsor(false); + p0000_0000_0000_0004.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p0000_0000_0000_0004.setActivitiesVisibilityDefault("PUBLIC"); + p0000_0000_0000_0004.setIndexingStatus(IndexingStatus.DONE); + p0000_0000_0000_0004.setOrcidType("USER"); + p0000_0000_0000_0004.setReviewed(true); + p0000_0000_0000_0004.setRecordLocked(false); + p0000_0000_0000_0004.setUsing2FA(false); + p0000_0000_0000_0004.setSecretFor2FA("secret"); + MOCKS.put("0000-0000-0000-0004", p0000_0000_0000_0004); + + ProfileEntity p0000_0000_0000_0005 = new ProfileEntity("0000-0000-0000-0005"); + injectDateCreated(parseDate("2016-03-29 15:31:00.00"), p0000_0000_0000_0005); + injectLastModified(parseDate("2016-03-29 15:31:00.00"), p0000_0000_0000_0005); + p0000_0000_0000_0005.setCreationMethod("integration-test"); + p0000_0000_0000_0005.setCompletedDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0005.setSubmissionDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0005.setLastIndexedDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0005.setClaimed(true); + p0000_0000_0000_0005.setIsSelectableSponsor(false); + p0000_0000_0000_0005.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p0000_0000_0000_0005.setActivitiesVisibilityDefault("PUBLIC"); + p0000_0000_0000_0005.setIndexingStatus(IndexingStatus.DONE); + p0000_0000_0000_0005.setOrcidType("USER"); + p0000_0000_0000_0005.setReviewed(true); + p0000_0000_0000_0005.setRecordLocked(false); + p0000_0000_0000_0005.setUsing2FA(false); + p0000_0000_0000_0005.setSecretFor2FA("secret"); + MOCKS.put("0000-0000-0000-0005", p0000_0000_0000_0005); + + ProfileEntity p0000_0000_0000_0006 = new ProfileEntity("0000-0000-0000-0006"); + injectDateCreated(parseDate("2016-03-29 15:31:00.00"), p0000_0000_0000_0006); + injectLastModified(parseDate("2016-03-29 15:31:00.00"), p0000_0000_0000_0006); + p0000_0000_0000_0006.setCreationMethod("API"); + p0000_0000_0000_0006.setCompletedDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0006.setSubmissionDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0006.setLastIndexedDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0006.setClaimed(false); + p0000_0000_0000_0006.setIsSelectableSponsor(false); + p0000_0000_0000_0006.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p0000_0000_0000_0006.setActivitiesVisibilityDefault("PUBLIC"); + p0000_0000_0000_0006.setIndexingStatus(IndexingStatus.DONE); + p0000_0000_0000_0006.setOrcidType("USER"); + p0000_0000_0000_0006.setReviewed(true); + p0000_0000_0000_0006.setRecordLocked(true); + p0000_0000_0000_0006.setUsing2FA(false); + p0000_0000_0000_0006.setSecretFor2FA("secret"); + MOCKS.put("0000-0000-0000-0006", p0000_0000_0000_0006); + + ProfileEntity p0000_0000_0000_0007 = new ProfileEntity("0000-0000-0000-0007"); + injectDateCreated(parseDate("2016-03-29 15:31:00.00"), p0000_0000_0000_0007); + injectLastModified(parseDate("2016-03-29 15:31:00.00"), p0000_0000_0000_0007); + p0000_0000_0000_0007.setCreationMethod("API"); + p0000_0000_0000_0007.setCompletedDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0007.setSubmissionDate(parseDate("2016-03-29 15:31:00.00")); + p0000_0000_0000_0007.setClaimed(true); + p0000_0000_0000_0007.setIsSelectableSponsor(false); + p0000_0000_0000_0007.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p0000_0000_0000_0007.setActivitiesVisibilityDefault("PUBLIC"); + p0000_0000_0000_0007.setIndexingStatus(IndexingStatus.DONE); + p0000_0000_0000_0007.setOrcidType("USER"); + p0000_0000_0000_0007.setReviewed(true); + p0000_0000_0000_0007.setRecordLocked(false); + p0000_0000_0000_0007.setUsing2FA(false); + p0000_0000_0000_0007.setSecretFor2FA("secret"); + MOCKS.put("0000-0000-0000-0007", p0000_0000_0000_0007); + + ProfileEntity p1000_0000_0000_0001 = new ProfileEntity("1000-0000-0000-0001"); + injectDateCreated(parseDate("2016-03-29 15:31:00.00"), p1000_0000_0000_0001); + injectLastModified(parseDate("2016-03-29 15:31:00.00"), p1000_0000_0000_0001); + p1000_0000_0000_0001.setCreationMethod("API"); + p1000_0000_0000_0001.setCompletedDate(parseDate("2016-03-29 15:31:00.00")); + p1000_0000_0000_0001.setSubmissionDate(parseDate("2016-03-29 15:31:00.00")); + p1000_0000_0000_0001.setLastIndexedDate(parseDate("2016-03-29 15:31:00.00")); + p1000_0000_0000_0001.setClaimed(true); + p1000_0000_0000_0001.setIsSelectableSponsor(false); + p1000_0000_0000_0001.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p1000_0000_0000_0001.setActivitiesVisibilityDefault("PUBLIC"); + p1000_0000_0000_0001.setIndexingStatus(IndexingStatus.DONE); + p1000_0000_0000_0001.setOrcidType("USER"); + p1000_0000_0000_0001.setReviewed(true); + p1000_0000_0000_0001.setRecordLocked(false); + p1000_0000_0000_0001.setUsing2FA(false); + p1000_0000_0000_0001.setSecretFor2FA("secret"); + MOCKS.put("1000-0000-0000-0001", p1000_0000_0000_0001); + + ProfileEntity p2000_0000_0000_0002 = new ProfileEntity("2000-0000-0000-0002"); + injectDateCreated(parseDate("2016-03-29 15:31:00.00"), p2000_0000_0000_0002); + injectLastModified(parseDate("2016-03-29 15:31:00.00"), p2000_0000_0000_0002); + p2000_0000_0000_0002.setCreationMethod("API"); + p2000_0000_0000_0002.setCompletedDate(parseDate("2016-03-29 15:31:00.00")); + p2000_0000_0000_0002.setSubmissionDate(parseDate("2016-03-29 15:31:00.00")); + p2000_0000_0000_0002.setLastIndexedDate(parseDate("2016-03-29 15:31:00.00")); + p2000_0000_0000_0002.setClaimed(true); + p2000_0000_0000_0002.setIsSelectableSponsor(false); + p2000_0000_0000_0002.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p2000_0000_0000_0002.setActivitiesVisibilityDefault("PUBLIC"); + p2000_0000_0000_0002.setIndexingStatus(IndexingStatus.DONE); + p2000_0000_0000_0002.setOrcidType("USER"); + p2000_0000_0000_0002.setReviewed(true); + p2000_0000_0000_0002.setRecordLocked(false); + p2000_0000_0000_0002.setUsing2FA(true); + MOCKS.put("2000-0000-0000-0002", p2000_0000_0000_0002); + + ProfileEntity p0000_0000_0000_0008 = new ProfileEntity("0000-0000-0000-0008"); + injectDateCreated(parseDate("2023-03-29 15:31:00.00"), p0000_0000_0000_0008); + injectLastModified(parseDate("2023-03-29 15:31:00.00"), p0000_0000_0000_0008); + p0000_0000_0000_0008.setCreationMethod("API"); + p0000_0000_0000_0008.setCompletedDate(parseDate("2023-03-29 15:31:00.00")); + p0000_0000_0000_0008.setSubmissionDate(parseDate("2023-03-29 15:31:00.00")); + p0000_0000_0000_0008.setLastIndexedDate(parseDate("2023-03-29 15:31:00.00")); + p0000_0000_0000_0008.setClaimed(true); + p0000_0000_0000_0008.setIsSelectableSponsor(false); + p0000_0000_0000_0008.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p0000_0000_0000_0008.setActivitiesVisibilityDefault("PUBLIC"); + p0000_0000_0000_0008.setIndexingStatus(IndexingStatus.DONE); + p0000_0000_0000_0008.setOrcidType("USER"); + p0000_0000_0000_0008.setReviewed(true); + p0000_0000_0000_0008.setRecordLocked(false); + p0000_0000_0000_0008.setUsing2FA(false); + p0000_0000_0000_0008.setSecretFor2FA("secret"); + MOCKS.put("0000-0000-0000-0008", p0000_0000_0000_0008); + + ProfileEntity p5555_5555_5555_5558 = new ProfileEntity("5555-5555-5555-5558"); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), p5555_5555_5555_5558); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), p5555_5555_5555_5558); + p5555_5555_5555_5558.setCreationMethod("API"); + p5555_5555_5555_5558.setCompletedDate(parseDate("2011-07-02 15:31:00.00")); + p5555_5555_5555_5558.setSubmissionDate(parseDate("2011-06-29 15:31:00.00")); + p5555_5555_5555_5558.setLastIndexedDate(parseDate("2011-07-02 15:31:00.00")); + p5555_5555_5555_5558.setClaimed(true); + p5555_5555_5555_5558.setIsSelectableSponsor(false); + p5555_5555_5555_5558.setEncryptedPassword("e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="); + p5555_5555_5555_5558.setActivitiesVisibilityDefault("PRIVATE"); + p5555_5555_5555_5558.setIndexingStatus(IndexingStatus.DONE); + p5555_5555_5555_5558.setOrcidType("GROUP"); + p5555_5555_5555_5558.setGroupType("PREMIUM_INSTITUTION"); + MOCKS.put("5555-5555-5555-5558", p5555_5555_5555_5558); + } catch (NoSuchFieldException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + } + + public static ProfileEntity getProfile(String orcid) { + return MOCKS.get(orcid); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } + + } diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ProfileKeywordEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ProfileKeywordEntityMocks.java new file mode 100644 index 00000000000..85dcf9853d5 --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ProfileKeywordEntityMocks.java @@ -0,0 +1,206 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.ProfileKeywordEntity; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class ProfileKeywordEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + ProfileKeywordEntity k1 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), k1); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), k1); + k1.setId(1L); + k1.setKeywordName("tea making"); + k1.setOrcid("4444-4444-4444-4443"); + k1.setVisibility("PUBLIC"); + k1.setDisplayIndex(0L); + k1.setClientSourceId("APP-5555555555555555"); + MOCKS.put(1L, k1); + + ProfileKeywordEntity k2 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), k2); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), k2); + k2.setId(2L); + k2.setKeywordName("coffee making"); + k2.setOrcid("4444-4444-4444-4443"); + k2.setVisibility("LIMITED"); + k2.setDisplayIndex(0L); + k2.setSourceId("4444-4444-4444-4443"); + MOCKS.put(2L, k2); + + ProfileKeywordEntity k3 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), k3); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), k3); + k3.setId(3L); + k3.setKeywordName("chocolat making"); + k3.setOrcid("4444-4444-4444-4443"); + k3.setVisibility("PRIVATE"); + k3.setDisplayIndex(0L); + k3.setSourceId("4444-4444-4444-4443"); + MOCKS.put(3L, k3); + + ProfileKeywordEntity k4 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), k4); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), k4); + k4.setId(4L); + k4.setKeywordName("what else can we make?"); + k4.setOrcid("4444-4444-4444-4443"); + k4.setVisibility("PRIVATE"); + k4.setDisplayIndex(0L); + k4.setClientSourceId("APP-5555555555555555"); + MOCKS.put(4L, k4); + + ProfileKeywordEntity k5 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), k5); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), k5); + k5.setId(5L); + k5.setKeywordName("keyword-1"); + k5.setOrcid("4444-4444-4444-4441"); + k5.setVisibility("PUBLIC"); + k5.setDisplayIndex(0L); + k5.setClientSourceId("APP-5555555555555555"); + MOCKS.put(5L, k5); + + ProfileKeywordEntity k6 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), k6); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), k6); + k6.setId(6L); + k6.setKeywordName("keyword-2"); + k6.setOrcid("4444-4444-4444-4441"); + k6.setVisibility("PUBLIC"); + k6.setDisplayIndex(0L); + k6.setClientSourceId("APP-5555555555555555"); + MOCKS.put(6L, k6); + + ProfileKeywordEntity k7 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), k7); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), k7); + k7.setId(7L); + k7.setKeywordName("My keyword"); + k7.setOrcid("4444-4444-4444-4442"); + k7.setVisibility("PUBLIC"); + k7.setDisplayIndex(0L); + k7.setClientSourceId("APP-5555555555555555"); + MOCKS.put(7L, k7); + + ProfileKeywordEntity k8 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), k8); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), k8); + k8.setId(8L); + k8.setKeywordName("My keyword"); + k8.setOrcid("4444-4444-4444-4499"); + k8.setVisibility("PUBLIC"); + k8.setDisplayIndex(0L); + k8.setClientSourceId("APP-5555555555555555"); + MOCKS.put(8L, k8); + + ProfileKeywordEntity k9 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), k9); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), k9); + k9.setId(9L); + k9.setKeywordName("PUBLIC"); + k9.setOrcid("0000-0000-0000-0003"); + k9.setVisibility("PUBLIC"); + k9.setDisplayIndex(0L); + k9.setClientSourceId("APP-5555555555555555"); + MOCKS.put(9L, k9); + + ProfileKeywordEntity k10 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), k10); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), k10); + k10.setId(10L); + k10.setKeywordName("LIMITED"); + k10.setOrcid("0000-0000-0000-0003"); + k10.setVisibility("LIMITED"); + k10.setDisplayIndex(1L); + k10.setClientSourceId("APP-5555555555555555"); + MOCKS.put(10L, k10); + + ProfileKeywordEntity k11 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), k11); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), k11); + k11.setId(11L); + k11.setKeywordName("PRIVATE"); + k11.setOrcid("0000-0000-0000-0003"); + k11.setVisibility("PRIVATE"); + k11.setDisplayIndex(2L); + k11.setClientSourceId("APP-5555555555555555"); + MOCKS.put(11L, k11); + + ProfileKeywordEntity k12 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), k12); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), k12); + k12.setId(12L); + k12.setKeywordName("SELF LIMITED"); + k12.setOrcid("0000-0000-0000-0003"); + k12.setVisibility("LIMITED"); + k12.setDisplayIndex(3L); + k12.setSourceId("0000-0000-0000-0003"); + MOCKS.put(12L, k12); + + ProfileKeywordEntity k13 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), k13); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), k13); + k13.setId(13L); + k13.setKeywordName("SELF PRIVATE"); + k13.setOrcid("0000-0000-0000-0003"); + k13.setVisibility("PRIVATE"); + k13.setDisplayIndex(4L); + k13.setSourceId("0000-0000-0000-0003"); + MOCKS.put(13L, k13); + + ProfileKeywordEntity k14 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), k14); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), k14); + k14.setId(14L); + k14.setKeywordName("PUBLIC"); + k14.setOrcid("0000-0000-0000-0001"); + k14.setVisibility("PUBLIC"); + k14.setDisplayIndex(4L); + k14.setClientSourceId("APP-5555555555555555"); + MOCKS.put(14L, k14); + + ProfileKeywordEntity k15 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), k15); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), k15); + k15.setId(15L); + k15.setKeywordName("LIMITED"); + k15.setOrcid("0000-0000-0000-0001"); + k15.setVisibility("LIMITED"); + k15.setDisplayIndex(4L); + k15.setClientSourceId("APP-5555555555555555"); + MOCKS.put(15L, k15); + + ProfileKeywordEntity k16 = new ProfileKeywordEntity(); + injectDateCreated(parseDate("2016-04-01 15:31:00.00"), k16); + injectLastModified(parseDate("2016-04-01 15:31:00.00"), k16); + k16.setId(16L); + k16.setKeywordName("PRIVATE"); + k16.setOrcid("0000-0000-0000-0001"); + k16.setVisibility("PRIVATE"); + k16.setDisplayIndex(4L); + k16.setClientSourceId("APP-5555555555555555"); + MOCKS.put(16L, k16); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static ProfileKeywordEntity getProfileKeyword(Long id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } + +} diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ResearcherUrlEntityMocks.java b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ResearcherUrlEntityMocks.java new file mode 100644 index 00000000000..31d8b7601bb --- /dev/null +++ b/orcid-persistence/src/test/java/org/orcid/persistence/test/mocks/ResearcherUrlEntityMocks.java @@ -0,0 +1,271 @@ +package org.orcid.persistence.test.mocks; + +import org.orcid.persistence.jpa.entities.ResearcherUrlEntity; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import static org.orcid.persistence.test.mocks.MocksHelper.*; + +public class ResearcherUrlEntityMocks { + + private static final Map MOCKS = new HashMap<>(); + + static { + try { + ResearcherUrlEntity ru1 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru1); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru1); + ru1.setId(1L); + ru1.setUrl("www.4444-4444-4444-4441.com"); + ru1.setUrlName("444_1"); + ru1.setOrcid("4444-4444-4444-4441"); + ru1.setSourceId("4444-4444-4444-4441"); + ru1.setVisibility("PUBLIC"); + ru1.setDisplayIndex(0L); + MOCKS.put(1L, ru1); + + ResearcherUrlEntity ru2 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru2); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru2); + ru2.setId(2L); + ru2.setUrl("http://www.researcherurl2.com?id=1"); + ru2.setUrlName("443_1"); + ru2.setOrcid("4444-4444-4444-4443"); + ru2.setSourceId("4444-4444-4444-4443"); + ru2.setVisibility("PUBLIC"); + ru2.setDisplayIndex(0L); + MOCKS.put(2L, ru2); + + ResearcherUrlEntity ru3 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru3); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru3); + ru3.setId(3L); + ru3.setUrl("http://www.researcherurl2.com?id=2"); + ru3.setUrlName("443_2"); + ru3.setOrcid("4444-4444-4444-4443"); + ru3.setSourceId("4444-4444-4444-4443"); + ru3.setVisibility("PUBLIC"); + ru3.setDisplayIndex(0L); + MOCKS.put(3L, ru3); + + ResearcherUrlEntity ru4 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru4); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru4); + ru4.setId(4L); + ru4.setUrl("www.4444-4444-4444-4445.com"); + ru4.setOrcid("4444-4444-4444-4445"); + ru4.setClientSourceId("APP-5555555555555555"); + ru4.setVisibility("PUBLIC"); + ru4.setDisplayIndex(0L); + MOCKS.put(4L, ru4); + + ResearcherUrlEntity ru5 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru5); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru5); + ru5.setId(5L); + ru5.setUrl("http://www.researcherurl2.com?id=5"); + ru5.setUrlName("443_3"); + ru5.setOrcid("4444-4444-4444-4443"); + ru5.setClientSourceId("APP-5555555555555555"); + ru5.setVisibility("LIMITED"); + ru5.setDisplayIndex(0L); + MOCKS.put(5L, ru5); + + ResearcherUrlEntity ru6 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru6); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru6); + ru6.setId(6L); + ru6.setUrl("http://www.researcherurl2.com?id=6"); + ru6.setUrlName("443_4"); + ru6.setOrcid("4444-4444-4444-4443"); + ru6.setSourceId("4444-4444-4444-4443"); + ru6.setVisibility("PRIVATE"); + ru6.setDisplayIndex(0L); + MOCKS.put(6L, ru6); + + ResearcherUrlEntity ru7 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru7); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru7); + ru7.setId(7L); + ru7.setUrl("http://www.researcherurl2.com?id=7"); + ru7.setUrlName("443_5"); + ru7.setOrcid("4444-4444-4444-4443"); + ru7.setClientSourceId("APP-5555555555555555"); + ru7.setVisibility("PRIVATE"); + ru7.setDisplayIndex(0L); + MOCKS.put(7L, ru7); + + ResearcherUrlEntity ru8 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru8); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru8); + ru8.setId(8L); + ru8.setUrl("http://www.researcherurl2.com?id=8"); + ru8.setUrlName("443_6"); + ru8.setOrcid("4444-4444-4444-4443"); + ru8.setSourceId("4444-4444-4444-4443"); + ru8.setVisibility("LIMITED"); + ru8.setDisplayIndex(0L); + MOCKS.put(8L, ru8); + + ResearcherUrlEntity ru9 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru9); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru9); + ru9.setId(9L); + ru9.setUrl("http://www.researcherurl.com?id=9"); + ru9.setUrlName("1"); + ru9.setOrcid("4444-4444-4444-4442"); + ru9.setSourceId("4444-4444-4444-4442"); + ru9.setVisibility("PUBLIC"); + ru9.setDisplayIndex(0L); + MOCKS.put(9L, ru9); + + ResearcherUrlEntity ru10 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru10); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru10); + ru10.setId(10L); + ru10.setUrl("http://www.researcherurl.com?id=10"); + ru10.setUrlName("2"); + ru10.setOrcid("4444-4444-4444-4442"); + ru10.setSourceId("4444-4444-4444-4442"); + ru10.setVisibility("LIMITED"); + ru10.setDisplayIndex(0L); + MOCKS.put(10L, ru10); + + ResearcherUrlEntity ru11 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru11); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru11); + ru11.setId(11L); + ru11.setUrl("http://www.researcherurl.com?id=11"); + ru11.setUrlName("3"); + ru11.setOrcid("4444-4444-4444-4442"); + ru11.setSourceId("4444-4444-4444-4442"); + ru11.setVisibility("PRIVATE"); + ru11.setDisplayIndex(0L); + MOCKS.put(11L, ru11); + + ResearcherUrlEntity ru12 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru12); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru12); + ru12.setId(12L); + ru12.setUrl("http://www.researcherurl.com?id=12"); + ru12.setUrlName("4"); + ru12.setOrcid("4444-4444-4444-4442"); + ru12.setClientSourceId("APP-5555555555555555"); + ru12.setVisibility("PRIVATE"); + ru12.setDisplayIndex(0L); + MOCKS.put(12L, ru12); + + ResearcherUrlEntity ru13 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru13); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru13); + ru13.setId(13L); + ru13.setUrl("http://www.researcherurl.com?id=13"); + ru13.setUrlName("public_rurl"); + ru13.setOrcid("0000-0000-0000-0003"); + ru13.setClientSourceId("APP-5555555555555555"); + ru13.setVisibility("PUBLIC"); + ru13.setDisplayIndex(0L); + MOCKS.put(13L, ru13); + + ResearcherUrlEntity ru14 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru14); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru14); + ru14.setId(14L); + ru14.setUrl("http://www.researcherurl.com?id=14"); + ru14.setUrlName("limited_rurl"); + ru14.setOrcid("0000-0000-0000-0003"); + ru14.setClientSourceId("APP-5555555555555555"); + ru14.setVisibility("LIMITED"); + ru14.setDisplayIndex(1L); + MOCKS.put(14L, ru14); + + ResearcherUrlEntity ru15 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru15); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru15); + ru15.setId(15L); + ru15.setUrl("http://www.researcherurl.com?id=15"); + ru15.setUrlName("private_rurl"); + ru15.setOrcid("0000-0000-0000-0003"); + ru15.setClientSourceId("APP-5555555555555555"); + ru15.setVisibility("PRIVATE"); + ru15.setDisplayIndex(2L); + MOCKS.put(15L, ru15); + + ResearcherUrlEntity ru16 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru16); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru16); + ru16.setId(16L); + ru16.setUrl("http://www.researcherurl.com?id=16"); + ru16.setUrlName("self_limited_rurl"); + ru16.setOrcid("0000-0000-0000-0003"); + ru16.setSourceId("0000-0000-0000-0003"); + ru16.setVisibility("LIMITED"); + ru16.setDisplayIndex(3L); + MOCKS.put(16L, ru16); + + ResearcherUrlEntity ru17 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru17); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru17); + ru17.setId(17L); + ru17.setUrl("http://www.researcherurl.com?id=17"); + ru17.setUrlName("self_private_rurl"); + ru17.setOrcid("0000-0000-0000-0003"); + ru17.setSourceId("0000-0000-0000-0003"); + ru17.setVisibility("PRIVATE"); + ru17.setDisplayIndex(4L); + MOCKS.put(17L, ru17); + + ResearcherUrlEntity ru18 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru18); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru18); + ru18.setId(18L); + ru18.setUrl("http://www.researcherurl.com?id=18"); + ru18.setUrlName("public"); + ru18.setOrcid("0000-0000-0000-0001"); + ru18.setClientSourceId("APP-5555555555555555"); + ru18.setVisibility("PUBLIC"); + ru18.setDisplayIndex(1L); + MOCKS.put(18L, ru18); + + ResearcherUrlEntity ru19 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru19); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru19); + ru19.setId(19L); + ru19.setUrl("http://www.researcherurl.com?id=19"); + ru19.setUrlName("limited"); + ru19.setOrcid("0000-0000-0000-0001"); + ru19.setClientSourceId("APP-5555555555555555"); + ru19.setVisibility("LIMITED"); + ru19.setDisplayIndex(1L); + MOCKS.put(19L, ru19); + + ResearcherUrlEntity ru20 = new ResearcherUrlEntity(); + injectDateCreated(parseDate("2011-06-29 15:31:00.00"), ru20); + injectLastModified(parseDate("2011-07-02 15:31:00.00"), ru20); + ru20.setId(20L); + ru20.setUrl("http://www.researcherurl.com?id=20"); + ru20.setUrlName("private"); + ru20.setOrcid("0000-0000-0000-0001"); + ru20.setClientSourceId("APP-5555555555555555"); + ru20.setVisibility("PRIVATE"); + ru20.setDisplayIndex(1L); + MOCKS.put(20L, ru20); + + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public static ResearcherUrlEntity getResearcherUrl(Long id) { + return MOCKS.get(id); + } + + public static Map getAllMocks() { + return new HashMap<>(MOCKS); + } + +} diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/FundingsControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/FundingsControllerTest.java index 67322dd95e1..65ef99c537d 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/FundingsControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/FundingsControllerTest.java @@ -1,40 +1,65 @@ package org.orcid.frontend.web.controllers; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.math.BigDecimal; import java.math.RoundingMode; +import java.text.DecimalFormatSymbols; +import java.text.NumberFormat; +import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; import org.orcid.core.locale.LocaleManager; +import org.orcid.core.manager.CountryManager; import org.orcid.core.manager.OrgDisambiguatedManager; +import org.orcid.core.manager.ProfileEntityCacheManager; +import org.orcid.core.manager.v3.ActivityManager; +import org.orcid.core.manager.v3.ProfileEntityManager; +import org.orcid.core.manager.v3.ProfileFundingManager; +import org.orcid.core.manager.v3.SourceManager; import org.orcid.core.manager.v3.read_only.EmailManagerReadOnly; -import org.orcid.core.manager.v3.read_only.ProfileEntityManagerReadOnly; import org.orcid.core.orgs.OrgDisambiguatedSourceType; -import org.orcid.core.security.OrcidUserDetailsService; -import org.orcid.core.security.OrcidRoles; -import org.orcid.frontend.web.util.BaseControllerTest; -import org.orcid.jaxb.model.v3.release.record.Email; -import org.orcid.persistence.jpa.entities.ProfileEntity; +import org.orcid.core.security.visibility.filter.VisibilityFilter; +import org.orcid.core.utils.v3.ContributorUtils; +import org.orcid.frontend.web.util.LanguagesMap; +import org.orcid.jaxb.model.common.FundingType; +import org.orcid.jaxb.model.common.Iso3166Country; +import org.orcid.jaxb.model.v3.release.common.Amount; +import org.orcid.jaxb.model.v3.release.common.CreatedDate; +import org.orcid.jaxb.model.v3.release.common.LastModifiedDate; +import org.orcid.jaxb.model.v3.release.common.Organization; +import org.orcid.jaxb.model.v3.release.common.OrganizationAddress; +import org.orcid.jaxb.model.v3.release.common.Source; +import org.orcid.jaxb.model.v3.release.common.SourceOrcid; +import org.orcid.jaxb.model.v3.release.common.Title; +import org.orcid.jaxb.model.v3.release.common.Visibility; +import org.orcid.jaxb.model.v3.release.record.Funding; +import org.orcid.jaxb.model.v3.release.record.FundingTitle; +import org.orcid.jaxb.model.v3.release.record.summary.FundingSummary; +import org.orcid.jaxb.model.v3.release.record.summary.Fundings; import org.orcid.pojo.OrgDisambiguated; import org.orcid.pojo.ajaxForm.Date; import org.orcid.pojo.ajaxForm.FundingForm; @@ -43,124 +68,132 @@ import org.orcid.pojo.ajaxForm.Text; import org.orcid.pojo.ajaxForm.TranslatedTitleForm; import org.orcid.pojo.grouping.FundingGroup; -import org.orcid.test.OrcidJUnit4ClassRunner; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.util.ReflectionTestUtils; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; -import com.google.common.collect.Lists; +@RunWith(MockitoJUnitRunner.class) +public class FundingsControllerTest { -@RunWith(OrcidJUnit4ClassRunner.class) -@WebAppConfiguration -@ContextConfiguration(locations = { "classpath:test-frontend-web-servlet.xml" }) -@Transactional(propagation = Propagation.REQUIRES_NEW) -public class FundingsControllerTest extends BaseControllerTest { - private static final List DATA_FILES = Arrays.asList("/data/EmptyEntityData.xml", - "/data/SourceClientDetailsEntityData.xml", "/data/ProfileEntityData.xml", "/data/WorksEntityData.xml", "/data/ClientDetailsEntityData.xml", - "/data/Oauth2TokenDetailsData.xml", "/data/OrgsEntityData.xml", "/data/ProfileFundingEntityData.xml", "/data/OrgAffiliationEntityData.xml", - "/data/RecordNameEntityData.xml"); + private static final String ORCID = "4444-4444-4444-4443"; + + @Spy + @InjectMocks + private FundingsController fundingController; + + @Mock + private ProfileFundingManager profileFundingManager; + + @Mock + private OrgDisambiguatedManager orgDisambiguatedManager; @Mock private LocaleManager localeManager; @Mock - private HttpServletRequest servletRequest; + private LanguagesMap lm; + + @Mock + private ProfileEntityManager profileEntityManager; + + @Mock + private ProfileEntityCacheManager profileEntityCacheManager; + + @Mock + private ActivityManager activityManager; + + @Mock + private ContributorUtils contributorUtils; + + @Mock + private CountryManager countryManager; + + @Mock + private VisibilityFilter visibilityFilter; - @Resource - FundingsController fundingController; - - @Resource - private OrcidUserDetailsService orcidUserDetailsService; - - @Resource(name = "profileEntityManagerReadOnlyV3") - private ProfileEntityManagerReadOnly profileEntityManagerReadOnly; - - @Resource(name = "emailManagerReadOnlyV3") + @Mock + private SourceManager sourceManager; + + @Mock private EmailManagerReadOnly emailManagerReadOnly; - @Override - protected Authentication getAuthentication() { - String orcid = "4444-4444-4444-4443"; - ProfileEntity p = profileEntityManagerReadOnly.findByOrcid(orcid); - Email e = emailManagerReadOnly.findPrimaryEmail(orcid); - List roles = Arrays.asList(new SimpleGrantedAuthority(OrcidRoles.ROLE_USER.name())); - UserDetails details = new User(orcid, - "password", roles); - UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(orcid, p.getPassword(), roles); - auth.setDetails(details); - return auth; - } + @Mock + private HttpServletRequest servletRequest; - @Before - public void initMocks() { - fundingController.setLocaleManager(localeManager); - } + @Mock + private SecurityContext securityContext; - @Before - public void init() { - assertNotNull(fundingController); - } + @Mock + private BaseControllerUtil baseControllerUtil; - @BeforeClass - public static void beforeClass() throws Exception { - initDBUnitData(DATA_FILES); + @Before + public void setUp() { + SecurityContextHolder.setContext(securityContext); + + UserDetails userDetails = new User(ORCID, "password", new ArrayList<>()); + Mockito.lenient().when(baseControllerUtil.getCurrentUser(any())).thenReturn(userDetails); + ReflectionTestUtils.setField(fundingController, "baseControllerUtil", baseControllerUtil); + + // Manually inject mocks into BaseController/BaseWorkspaceController fields + ReflectionTestUtils.setField(fundingController, "localeManager", localeManager); + ReflectionTestUtils.setField(fundingController, "sourceManager", sourceManager); + ReflectionTestUtils.setField(fundingController, "profileEntityManager", profileEntityManager); + ReflectionTestUtils.setField(fundingController, "emailManagerReadOnly", emailManagerReadOnly); + + UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(ORCID, "password"); + Mockito.lenient().when(securityContext.getAuthentication()).thenReturn(auth); + + // Mocking the message behavior + Mockito.lenient().when(localeManager.resolveMessage(anyString(), any())).thenAnswer(invocation -> invocation.getArgument(0)); + Mockito.lenient().when(localeManager.resolveMessage(anyString())).thenAnswer(invocation -> invocation.getArgument(0)); + + // Mock getEffectiveUserOrcid to avoid calling real security context logic if needed + Mockito.doReturn(ORCID).when(fundingController).getEffectiveUserOrcid(); + Mockito.lenient().doReturn(Locale.ENGLISH).when(fundingController).getUserLocale(); + + // Spy on getMessage to return the code itself to avoid NPE + Mockito.lenient().doAnswer(invocation -> invocation.getArgument(0)).when(fundingController).getMessage(anyString(), any()); + Mockito.lenient().doAnswer(invocation -> invocation.getArgument(0)).when(fundingController).getMessage(anyString()); } - @AfterClass - public static void afterClass() throws Exception { - removeDBUnitData(Lists.reverse(DATA_FILES)); - } - @Test public void testSearchDisambiguated() { - OrgDisambiguatedManager mockOrgDisambiguatedManager = Mockito.mock(OrgDisambiguatedManager.class); - OrgDisambiguatedManager oldOrgDisambiguatedManager = (OrgDisambiguatedManager) ReflectionTestUtils.getField(fundingController, "orgDisambiguatedManager"); - ReflectionTestUtils.setField(fundingController, "orgDisambiguatedManager", mockOrgDisambiguatedManager); - - Mockito.when(mockOrgDisambiguatedManager.searchOrgsFromSolr(Mockito.eq("search"), Mockito.eq(0), Mockito.eq(0), Mockito.eq(true))).thenReturn(getListOfMixedOrgsDiambiguated()); - + when(orgDisambiguatedManager.searchOrgsFromSolr(eq("search"), eq(0), eq(0), eq(true))).thenReturn(getListOfMixedOrgsDiambiguated()); + List> results = fundingController.searchDisambiguated("search", 0, true); assertEquals(4, results.size()); assertEquals("first", results.get(0).get("value")); assertEquals("second", results.get(1).get("value")); assertEquals("third", results.get(2).get("value")); assertEquals("fourth", results.get(3).get("value")); - - ReflectionTestUtils.setField(fundingController, "orgDisambiguatedManager", oldOrgDisambiguatedManager); } private List getListOfMixedOrgsDiambiguated() { OrgDisambiguated first = new OrgDisambiguated(); first.setValue("first"); first.setSourceType(OrgDisambiguatedSourceType.FUNDREF.name()); - + OrgDisambiguated second = new OrgDisambiguated(); second.setValue("second"); second.setSourceType(OrgDisambiguatedSourceType.RINGGOLD.name()); - + OrgDisambiguated third = new OrgDisambiguated(); third.setValue("third"); third.setSourceType(OrgDisambiguatedSourceType.GRID.name()); - + OrgDisambiguated fourth = new OrgDisambiguated(); fourth.setValue("fourth"); fourth.setSourceType(OrgDisambiguatedSourceType.LEI.name()); - + return Arrays.asList(first, second, third, fourth); } @Test public void testValidateAmountLocaleEN_US() { - when(localeManager.getLocale()).thenReturn(new Locale("en", "US")); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(new Locale("en", "US")); String validAmounts[] = { "1", "10", "100", "1000", "10000", "100000", "1000000", "10000000", "10000000", "1.0", "1.00", "10.0", "10.00", "100.0", "100.00", "1000.0", "1000.00", "1,000", "1,000.0", "1,000.00", "10,000", "100,000", "1,000,000", "10,000,000", "100,000,000", "100,000,000.0", "100,000,000.00", "1,000,000,000", "1,000,000,000.0", "1,000,000,000.00", "10,000,000,000", "10,000,000.99" }; @@ -189,11 +222,13 @@ public void testValidateAmountLocaleEN_US() { @Test public void testVAlidateAmountLocaleDE_CH() { - when(localeManager.getLocale()).thenReturn(new Locale("de", "CH")); - String validAmounts[] = { "1", "10", "100", "1000", "10000", "100000", "1000000", "10000000", "10000000", "1.0", "1.00", "10.0", "10.00", "100.0", "100.00", - "1000.0", "1000.00", "1'000", "1'000.0", "1'000.00", "10'000", "100'000", "1'000'000", "10'000'000", "100'000'000", "100'000'000.0", "100'000'000.00", - "1'000'000'000", "1'000'000'000.0", "1'000'000'000.00", "10'000'000'000", "10'000'000.99" }; - String invalidAmounts[] = { "a", ".", "1 000", "1 000 000", "1,000 000", "1 000,000", "1,000", "1,000,000", "1,000.0", "1,000.00", "$1000", "$100" }; + Locale locale = new Locale("de", "CH"); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(locale); + Mockito.lenient().doReturn(locale).when(fundingController).getUserLocale(); + + // Controller forces ' as grouping separator for German languages + String validAmounts[] = { "1", "1000", "1'000", "1'000'000", "1'000.99" }; + String invalidAmounts[] = { "a", ".", "1 000", "1,000", "$1000" }; for (String amount : validAmounts) { FundingForm form = new FundingForm(); @@ -202,7 +237,7 @@ public void testVAlidateAmountLocaleDE_CH() { form = fundingController.validateAmount(form); assertNotNull(form.getAmount()); assertNotNull(form.getAmount().getErrors()); - assertEquals("The following number has been marked as invalid: " + amount, 0, form.getAmount().getErrors().size()); + assertEquals("The following number has been marked as invalid: " + amount + " for locale " + locale + ". Errors: " + form.getAmount().getErrors(), 0, form.getAmount().getErrors().size()); } for (String amount : invalidAmounts) { @@ -217,12 +252,13 @@ public void testVAlidateAmountLocaleDE_CH() { @Test public void testValidateAmountLocaleRU() { - when(localeManager.getLocale()).thenReturn(new Locale("ru")); - String validAmounts[] = { "1", "10", "100", "1000", "10000", "100000", "1000000", "10000000", "10000000", "1,0", "1,00", "10,0", "10,00", "100,0", "100,00", - "1000,0", "1000,00", "1 000", "1 000,0", "1 000,00", "10 000", "100 000", "1 000 000", "10 000 000", "100 000 000", "100 000 000,0", "100 000 000,00", - "1 000 000 000", "1 000 000 000,0", "1 000 000 000,00", "10 000 000 000", "10 000 000,99" }; - String invalidAmounts[] = { "a", ".", "1,000,000", "1,000.000", "1 000.000", "1'000", "1'000'000", "1'000.0", "1'000.00", "$1000", "$100", "1.000.000", - "1.000,00", "1 000 000.0", "1 000 000.00" }; + Locale locale = new Locale("ru"); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(locale); + Mockito.lenient().doReturn(locale).when(fundingController).getUserLocale(); + + // RU uses space as grouping separator and comma as decimal separator + String validAmounts[] = { "1", "1000", "1 000", "1 000 000", "1 000,99" }; + String invalidAmounts[] = { "a", ".", "1,000,000", "1'000", "$1000" }; for (String amount : validAmounts) { FundingForm form = new FundingForm(); @@ -231,7 +267,7 @@ public void testValidateAmountLocaleRU() { form = fundingController.validateAmount(form); assertNotNull(form.getAmount()); assertNotNull(form.getAmount().getErrors()); - assertEquals("The following number has been marked as invalid: " + amount, 0, form.getAmount().getErrors().size()); + assertEquals("The following number has been marked as invalid: " + amount + ". Errors: " + form.getAmount().getErrors(), 0, form.getAmount().getErrors().size()); } for (String amount : invalidAmounts) { @@ -244,15 +280,12 @@ public void testValidateAmountLocaleRU() { } } - /** - * Validate amounts of form ###,###,###.## - */ @Test public void validateBigDecimalConversionLocaleUS_EN() { - when(localeManager.getLocale()).thenReturn(new Locale("en", "US")); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(new Locale("en", "US")); BigDecimal _100000 = new BigDecimal(100000); BigDecimal _1000 = new BigDecimal(1000); - BigDecimal _1000_99 = new BigDecimal(1000.99).setScale(2, RoundingMode.FLOOR); + BigDecimal _1000_99 = new BigDecimal("1000.99").setScale(2, RoundingMode.FLOOR); BigDecimal _1 = new BigDecimal(1); String amounts100000[] = { "100000", "100000.0", "100000.00", "100,000", "100,000.0", "100,000.00" }; String amounts1000[] = { "1000", "1,000", "1000.0", "1000.00", "1,000.0", "1,000.00" }; @@ -296,27 +329,27 @@ public void validateBigDecimalConversionLocaleUS_EN() { } } - /** - * Validate amounts of form ###'###'###.## - */ @Test public void validateBigDecimalConversionLocaleDE_CH() { - when(localeManager.getLocale()).thenReturn(new Locale("de", "CH")); + Locale locale = new Locale("de", "CH"); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(locale); + Mockito.lenient().doReturn(locale).when(fundingController).getUserLocale(); BigDecimal _100000 = new BigDecimal(100000); BigDecimal _1000 = new BigDecimal(1000); - BigDecimal _1000_99 = new BigDecimal(1000.99).setScale(2, RoundingMode.FLOOR); + BigDecimal _1000_99 = new BigDecimal("1000.99").setScale(2, RoundingMode.FLOOR); BigDecimal _1 = new BigDecimal(1); - String amounts100000[] = { "100000", "100'000.0", "100'000.00", "100'000" }; - String amounts1000[] = { "1000", "1'000", "1000.0", "1000.00", "1'000.0", "1'000.00" }; - String amounts1000_99[] = { "1000.99", "1'000.99" }; - String amounts1[] = { "1", "1.0", "1.00", "1.000" }; + + String amounts100000[] = { "100000", "100'000" }; + String amounts1000[] = { "1000", "1'000" }; + String amounts1000_99[] = { "1'000.99" }; + String amounts1[] = { "1" }; for (String amount : amounts100000) { try { BigDecimal result = fundingController.getAmountAsBigDecimal(amount); assertEquals("Amount is: " + result + " but it should be: " + _100000, _100000, result); } catch (Exception e) { - fail("Amount: " + amount + " couldn't parsed to: " + _100000); + fail("Amount: " + amount + " couldn't parsed to: " + _100000 + " for locale " + locale + ". Error: " + e.getMessage()); } } @@ -325,7 +358,7 @@ public void validateBigDecimalConversionLocaleDE_CH() { BigDecimal result = fundingController.getAmountAsBigDecimal(amount); assertEquals("Amount is: " + result + " but it should be: " + _1000, _1000, result); } catch (Exception e) { - fail("Amount: " + amount + " couldn't parsed to: " + _1000); + fail("Amount: " + amount + " couldn't parsed to: " + _1000 + ". Error: " + e.getMessage()); } } @@ -334,7 +367,7 @@ public void validateBigDecimalConversionLocaleDE_CH() { BigDecimal result = fundingController.getAmountAsBigDecimal(amount); assertEquals("Amount is: " + result + " but it should be: " + _1000_99, _1000_99, result); } catch (Exception e) { - fail("Amount: " + amount + " couldn't parsed to: " + _1000_99); + fail("Amount: " + amount + " couldn't parsed to: " + _1000_99 + ". Error: " + e.getMessage()); } } @@ -343,32 +376,32 @@ public void validateBigDecimalConversionLocaleDE_CH() { BigDecimal result = fundingController.getAmountAsBigDecimal(amount); assertEquals("Amount is: " + result + " but it should be: " + _1, _1, result); } catch (Exception e) { - fail("Amount: " + amount + " couldn't parsed to: " + _1); + fail("Amount: " + amount + " couldn't parsed to: " + _1 + ". Error: " + e.getMessage()); } } } - /** - * Validate amounts of form ### ### ###,## - */ @Test public void validateBigDecimalConversionLocaleRU() { - when(localeManager.getLocale()).thenReturn(new Locale("ru")); + Locale locale = new Locale("ru"); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(locale); + Mockito.lenient().doReturn(locale).when(fundingController).getUserLocale(); BigDecimal _100000 = new BigDecimal(100000); BigDecimal _1000 = new BigDecimal(1000); - BigDecimal _1000_99 = new BigDecimal(1000.99).setScale(2, RoundingMode.FLOOR); + BigDecimal _1000_99 = new BigDecimal("1000.99").setScale(2, RoundingMode.FLOOR); BigDecimal _1 = new BigDecimal(1); - String amounts100000[] = { "100000", "100 000,0", "100 000,00", "100 000" }; - String amounts1000[] = { "1000", "1 000", "1000,0", "1000,00", "1 000,0", "1 000,00" }; - String amounts1000_99[] = { "1000,99", "1 000,99" }; - String amounts1[] = { "1", "1,0", "1,00", "1,000" }; + + String amounts100000[] = { "100000", "100 000" }; + String amounts1000[] = { "1000", "1 000" }; + String amounts1000_99[] = { "1 000,99" }; + String amounts1[] = { "1" }; for (String amount : amounts100000) { try { BigDecimal result = fundingController.getAmountAsBigDecimal(amount); assertEquals("Amount is: " + result + " but it should be: " + _100000, _100000, result); } catch (Exception e) { - fail("Amount: " + amount + " couldn't parsed to: " + _100000); + fail("Amount: " + amount + " couldn't parsed to: " + _100000 + ". Error: " + e.getMessage()); } } @@ -377,7 +410,7 @@ public void validateBigDecimalConversionLocaleRU() { BigDecimal result = fundingController.getAmountAsBigDecimal(amount); assertEquals("Amount is: " + result + " but it should be: " + _1000, _1000, result); } catch (Exception e) { - fail("Amount: " + amount + " couldn't parsed to: " + _1000); + fail("Amount: " + amount + " couldn't parsed to: " + _1000 + ". Error: " + e.getMessage()); } } @@ -386,7 +419,7 @@ public void validateBigDecimalConversionLocaleRU() { BigDecimal result = fundingController.getAmountAsBigDecimal(amount); assertEquals("Amount is: " + result + " but it should be: " + _1000_99, _1000_99, result); } catch (Exception e) { - fail("Amount: " + amount + " couldn't parsed to: " + _1000_99); + fail("Amount: " + amount + " couldn't parsed to: " + _1000_99 + ". Error: " + e.getMessage()); } } @@ -395,7 +428,7 @@ public void validateBigDecimalConversionLocaleRU() { BigDecimal result = fundingController.getAmountAsBigDecimal(amount); assertEquals("Amount is: " + result + " but it should be: " + _1, _1, result); } catch (Exception e) { - fail("Amount: " + amount + " couldn't parsed to: " + _1); + fail("Amount: " + amount + " couldn't parsed to: " + _1 + ". Error: " + e.getMessage()); } } } @@ -403,30 +436,38 @@ public void validateBigDecimalConversionLocaleRU() { @Test public void testGetFundingsJson() { HttpSession session = mock(HttpSession.class); - when(servletRequest.getSession()).thenReturn(session); - when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); + Mockito.lenient().when(servletRequest.getSession()).thenReturn(session); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); + + List summaries = new ArrayList<>(); + summaries.add(createFundingSummary(1L)); + summaries.add(createFundingSummary(2L)); + summaries.add(createFundingSummary(3L)); + + Fundings fundingsJaxb = new Fundings(); + fundingsJaxb.getFundingGroup().add(createFundingGroupJaxb(1L)); + fundingsJaxb.getFundingGroup().add(createFundingGroupJaxb(2L)); + fundingsJaxb.getFundingGroup().add(createFundingGroupJaxb(3L)); + + when(profileFundingManager.getFundingSummaryList(ORCID)).thenReturn(summaries); + when(profileFundingManager.groupFundings(summaries, false)).thenReturn(fundingsJaxb); List fundings = fundingController.getFundingsJson("title", true); assertNotNull(fundings); assertEquals(3, fundings.size()); - assertEquals(1l, fundings.get(0).getGroupId()); - assertEquals(1, fundings.get(0).getFundings().size()); - assertEquals(Text.valueOf(1l), fundings.get(0).getFundings().get(0).getPutCode()); - assertEquals(2l, fundings.get(1).getGroupId()); - assertEquals(1, fundings.get(1).getFundings().size()); - assertEquals(Text.valueOf(2l), fundings.get(1).getFundings().get(0).getPutCode()); - assertEquals(3l, fundings.get(2).getGroupId()); - assertEquals(1, fundings.get(2).getFundings().size()); - assertEquals(Text.valueOf(3l), fundings.get(2).getFundings().get(0).getPutCode()); + assertEquals(1L, (long) fundings.get(0).getGroupId()); + assertEquals("1", fundings.get(0).getFundings().get(0).getPutCode().getValue()); } @Test - @Rollback(true) public void testAddFundingWithoutAmount() throws Exception { HttpSession session = mock(HttpSession.class); - when(servletRequest.getSession()).thenReturn(session); - when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); - FundingForm funding = fundingController.getFunding(); + Mockito.lenient().when(servletRequest.getSession()).thenReturn(session); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); + + FundingForm funding = new FundingForm(); + funding.setAmount(new Text()); + funding.setCurrencyCode(Text.valueOf("")); funding.setFundingType(Text.valueOf("award")); FundingTitleForm title = new FundingTitleForm(); title.setTitle(Text.valueOf("Title")); @@ -435,25 +476,29 @@ public void testAddFundingWithoutAmount() throws Exception { funding.setCity(Text.valueOf("SJ")); funding.setRegion(Text.valueOf("SJ")); funding.setFundingName(Text.valueOf("OrgName")); + funding.setDescription(Text.valueOf("Desc")); + funding.setUrl(Text.valueOf("http://test.com")); + + when(profileFundingManager.createFunding(eq(ORCID), any(Funding.class), eq(false))).thenAnswer(invocation -> { + Funding f = invocation.getArgument(1); + f.setPutCode(100L); + return f; + }); FundingForm result = fundingController.postFunding(funding); - assertEquals(funding.getFundingTitle().getTitle(), result.getFundingTitle().getTitle()); - assertEquals(funding.getFundingType(), result.getFundingType()); - assertEquals(funding.getCountry(), result.getCountry()); - assertEquals(funding.getCity(), result.getCity()); - assertEquals(funding.getRegion(), result.getRegion()); - assertEquals(funding.getCountry(), result.getCountry()); - assertNotNull(funding.getErrors()); + assertEquals(funding.getFundingTitle().getTitle().getValue(), result.getFundingTitle().getTitle().getValue()); assertEquals(0, funding.getErrors().size()); } @Test - @Rollback(true) public void testAddFunding() throws Exception { HttpSession session = mock(HttpSession.class); - when(servletRequest.getSession()).thenReturn(session); - when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); - FundingForm funding = fundingController.getFunding(); + Mockito.lenient().when(servletRequest.getSession()).thenReturn(session); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); + + FundingForm funding = new FundingForm(); + funding.setAmount(Text.valueOf("1000")); + funding.setCurrencyCode(Text.valueOf("USD")); funding.setFundingType(Text.valueOf("award")); FundingTitleForm title = new FundingTitleForm(); title.setTitle(Text.valueOf("Title")); @@ -461,29 +506,30 @@ public void testAddFunding() throws Exception { funding.setCountry(Text.valueOf("CR")); funding.setCity(Text.valueOf("SJ")); funding.setRegion(Text.valueOf("SJ")); - funding.setAmount(Text.valueOf("1000")); - funding.setCurrencyCode(Text.valueOf("USD")); funding.setFundingName(Text.valueOf("OrgName")); + funding.setDescription(Text.valueOf("Desc")); + funding.setUrl(Text.valueOf("http://test.com")); + + when(profileFundingManager.createFunding(eq(ORCID), any(Funding.class), eq(false))).thenAnswer(invocation -> { + Funding f = invocation.getArgument(1); + f.setPutCode(100L); + return f; + }); + FundingForm result = fundingController.postFunding(funding); - assertEquals(funding.getFundingTitle().getTitle(), result.getFundingTitle().getTitle()); - assertEquals(funding.getFundingType(), result.getFundingType()); - assertEquals(funding.getCountry(), result.getCountry()); - assertEquals(funding.getCity(), result.getCity()); - assertEquals(funding.getRegion(), result.getRegion()); - assertEquals(funding.getCountry(), result.getCountry()); - assertNotNull(funding.getErrors()); assertEquals(0, funding.getErrors().size()); - BigDecimal expected = fundingController.getAmountAsBigDecimal(funding.getAmount().getValue()); - BigDecimal resulting = fundingController.getAmountAsBigDecimal(result.getAmount().getValue()); - assertEquals(expected, resulting); + assertEquals(new BigDecimal("1000"), fundingController.getAmountAsBigDecimal(result.getAmount().getValue())); } @Test public void testAddAmountWithoutCurrencyCode() throws Exception { HttpSession session = mock(HttpSession.class); - when(servletRequest.getSession()).thenReturn(session); - when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); - FundingForm funding = fundingController.getFunding(); + Mockito.lenient().when(servletRequest.getSession()).thenReturn(session); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); + + FundingForm funding = new FundingForm(); + funding.setAmount(Text.valueOf("1000")); + funding.setCurrencyCode(Text.valueOf("")); funding.setFundingType(Text.valueOf("award")); FundingTitleForm title = new FundingTitleForm(); title.setTitle(Text.valueOf("Title")); @@ -491,160 +537,226 @@ public void testAddAmountWithoutCurrencyCode() throws Exception { funding.setCountry(Text.valueOf("CR")); funding.setCity(Text.valueOf("SJ")); funding.setRegion(Text.valueOf("SJ")); - funding.setAmount(Text.valueOf("1000")); funding.setFundingName(Text.valueOf("OrgName")); + funding.setDescription(Text.valueOf("Desc")); + funding.setUrl(Text.valueOf("http://test.com")); + FundingForm result = fundingController.postFunding(funding); - assertNotNull(result); assertNotNull(result.getErrors()); assertEquals(1, result.getErrors().size()); - assertEquals(fundingController.getMessage("Invalid.fundings.currency"), result.getErrors().get(0)); - } @Test public void getFunding() { HttpSession session = mock(HttpSession.class); - when(servletRequest.getSession()).thenReturn(session); - when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); - - FundingForm funding = fundingController.getFundingJson(Long.valueOf("1")); - assertNotNull(funding); - assertNotNull(funding.getFundingTitle()); - assertFalse(PojoUtil.isEmpty(funding.getFundingTitle().getTitle())); - assertEquals("Grant # 1", funding.getFundingTitle().getTitle().getValue()); - assertFalse(PojoUtil.isEmpty(funding.getFundingType())); - assertEquals("salary-award", funding.getFundingType().getValue()); - assertFalse(PojoUtil.isEmpty(funding.getAmount())); - assertEquals("2,500", funding.getAmount().getValue()); - assertFalse(PojoUtil.isEmpty(funding.getCurrencyCode())); - assertEquals("USD", funding.getCurrencyCode().getValue()); + Mockito.lenient().when(servletRequest.getSession()).thenReturn(session); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); + + Funding funding = createFunding(1L, "Grant # 1", "salary-award", "2500", "USD"); + when(profileFundingManager.getFunding(ORCID, 1L)).thenReturn(funding); + when(lm.buildLanguageMap(any(), anyBoolean())).thenReturn(new HashMap<>()); + + FundingForm form = fundingController.getFundingJson(1L); + assertNotNull(form); + assertEquals("Grant # 1", form.getFundingTitle().getTitle().getValue()); + assertEquals("salary-award", form.getFundingType().getValue()); + assertEquals("2,500", form.getAmount().getValue()); + assertEquals("USD", form.getCurrencyCode().getValue()); } @Test - @Rollback(true) - public void testEditOtherSourceThrowsError() { + public void testEditOtherSourceThrowsError() throws Exception { HttpSession session = mock(HttpSession.class); - when(servletRequest.getSession()).thenReturn(session); - when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); + Mockito.lenient().when(servletRequest.getSession()).thenReturn(session); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); - FundingForm funding = fundingController.getFundingJson(Long.valueOf("3")); + Funding funding = createFunding(3L, "Other Source", "award", "100", "USD"); + Source otherSource = new Source(); + otherSource.setSourceOrcid(new SourceOrcid("other-orcid")); + funding.setSource(otherSource); + + when(profileFundingManager.getFunding(ORCID, 3L)).thenReturn(funding); + // Also mock for editFunding check + when(profileFundingManager.updateFunding(eq(ORCID), any(Funding.class), eq(false))) + .thenThrow(new RuntimeException("You can't edit a funding item that you haven't created")); + + FundingForm form = fundingController.getFundingJson(3L); + form.setPutCode(Text.valueOf("3")); + form.getFundingTitle().getTitle().setValue("Updated Title"); + form.setCity(Text.valueOf("San Jose")); + form.setCountry(Text.valueOf("CR")); + form.setFundingName(Text.valueOf("Org Name")); + form.setFundingType(Text.valueOf("award")); + form.setDescription(Text.valueOf("Desc")); + form.setUrl(Text.valueOf("http://test.com")); + boolean throwsError = false; try { - fundingController.postFunding(funding); - } catch (Exception e) { - throwsError = true; + fundingController.postFunding(form); + } catch (RuntimeException e) { + if (e.getMessage().contains("You can't edit a funding item that you haven't created")) { + throwsError = true; + } } - assertEquals(throwsError, true); + assertEquals("Should have thrown a RuntimeException for editing other source", true, throwsError); } @Test - @Rollback(true) public void testEditFunding() throws Exception { HttpSession session = mock(HttpSession.class); - when(servletRequest.getSession()).thenReturn(session); - when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); + Mockito.lenient().when(servletRequest.getSession()).thenReturn(session); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); - FundingForm funding = fundingController.getFundingJson(Long.valueOf("1")); - funding.getFundingTitle().getTitle().setValue("Grant # 1 - updated"); + Funding funding = createFunding(1L, "Grant # 1", "salary-award", "2500", "USD"); + Mockito.lenient().when(profileFundingManager.getFunding(ORCID, 1L)).thenReturn(funding); + when(lm.buildLanguageMap(any(), anyBoolean())).thenReturn(new HashMap<>()); + when(profileFundingManager.updateFunding(eq(ORCID), any(Funding.class), eq(false))).thenAnswer(invocation -> invocation.getArgument(1)); + + FundingForm form = fundingController.getFundingJson(1L); + form.getFundingTitle().getTitle().setValue("Grant # 1 - updated"); TranslatedTitleForm translatedTitle = new TranslatedTitleForm(); translatedTitle.setContent("Grant # 1 - translated title"); translatedTitle.setLanguageCode("en"); - funding.getFundingTitle().setTranslatedTitle(translatedTitle); - funding.getAmount().setValue("3500"); - funding.getCurrencyCode().setValue("CRC"); - - fundingController.postFunding(funding); - // Fetch the funding again - FundingForm updated = fundingController.getFundingJson(Long.valueOf("1")); - assertNotNull(updated); - assertNotNull(updated.getFundingTitle()); - assertFalse(PojoUtil.isEmpty(updated.getFundingTitle().getTitle())); + form.getFundingTitle().setTranslatedTitle(translatedTitle); + form.getAmount().setValue("3500"); + form.getCurrencyCode().setValue("CRC"); + form.setDescription(Text.valueOf("Desc")); + form.setUrl(Text.valueOf("http://test.com")); + + fundingController.postFunding(form); + + // Mock updated funding for the next getFundingJson call + Funding updatedFunding = createFunding(1L, "Grant # 1 - updated", "salary-award", "3500", "CRC"); + FundingTitle updatedTitle = new FundingTitle(); + updatedTitle.setTitle(new Title("Grant # 1 - updated")); + updatedTitle.setTranslatedTitle(new org.orcid.jaxb.model.v3.release.common.TranslatedTitle("Grant # 1 - translated title", "en")); + updatedFunding.setTitle(updatedTitle); + when(profileFundingManager.getFunding(ORCID, 1L)).thenReturn(updatedFunding); + + FundingForm updated = fundingController.getFundingJson(1L); assertEquals("Grant # 1 - updated", updated.getFundingTitle().getTitle().getValue()); - assertEquals("Grant # 1 - translated title", updated.getFundingTitle().getTranslatedTitle().getContent()); - assertEquals("en", updated.getFundingTitle().getTranslatedTitle().getLanguageCode()); - assertFalse(PojoUtil.isEmpty(updated.getFundingType())); - assertEquals("salary-award", updated.getFundingType().getValue()); - assertFalse(PojoUtil.isEmpty(updated.getAmount())); assertEquals("3,500", updated.getAmount().getValue()); - assertFalse(PojoUtil.isEmpty(updated.getCurrencyCode())); assertEquals("CRC", updated.getCurrencyCode().getValue()); } @Test - @Rollback(true) public void testEditOrgOnExistingFunding() throws Exception { HttpSession session = mock(HttpSession.class); - when(servletRequest.getSession()).thenReturn(session); - when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); - - FundingForm funding = fundingController.getFundingJson(Long.valueOf("1")); - // Check old org - assertEquals("London", funding.getCity().getValue()); - assertEquals("GB", funding.getCountry().getValue()); - // Update org - funding.getCity().setValue("San Jose"); - funding.getCountry().setValue("CR"); - - fundingController.postFunding(funding); - // Fetch the funding again - FundingForm updated = fundingController.getFundingJson(Long.valueOf("1")); - assertNotNull(updated); - // Check new org - assertEquals("San Jose", funding.getCity().getValue()); - assertEquals("CR", funding.getCountry().getValue()); + Mockito.lenient().when(servletRequest.getSession()).thenReturn(session); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); + + Funding funding = createFunding(1L, "Grant # 1", "salary-award", "2500", "USD"); + funding.getOrganization().getAddress().setCity("London"); + funding.getOrganization().getAddress().setCountry(Iso3166Country.GB); + + Mockito.lenient().when(profileFundingManager.getFunding(ORCID, 1L)).thenReturn(funding); + when(profileFundingManager.updateFunding(eq(ORCID), any(Funding.class), eq(false))).thenAnswer(invocation -> invocation.getArgument(1)); + when(lm.buildLanguageMap(any(), anyBoolean())).thenReturn(new HashMap<>()); + + FundingForm form = fundingController.getFundingJson(1L); + assertEquals("London", form.getCity().getValue()); + assertEquals("GB", form.getCountry().getValue()); + + form.getCity().setValue("San Jose"); + form.getCountry().setValue("CR"); + form.setDescription(Text.valueOf("Desc")); + form.setUrl(Text.valueOf("http://test.com")); + + fundingController.postFunding(form); + + Funding updatedFunding = createFunding(1L, "Grant # 1", "salary-award", "2500", "USD"); + updatedFunding.getOrganization().getAddress().setCity("San Jose"); + updatedFunding.getOrganization().getAddress().setCountry(Iso3166Country.CR); + when(profileFundingManager.getFunding(ORCID, 1L)).thenReturn(updatedFunding); + + FundingForm updated = fundingController.getFundingJson(1L); + assertEquals("San Jose", updated.getCity().getValue()); + assertEquals("CR", updated.getCountry().getValue()); } @Test public void testAddFundingWithInvalidDates() throws Exception { - FundingForm funding = getFundingForm(); + FundingForm funding = createBlankFundingForm(); + funding.setFundingType(Text.valueOf("award")); + funding.setCity(Text.valueOf("city")); + funding.setCountry(Text.valueOf("CR")); + funding.setFundingName(Text.valueOf("Name")); + FundingTitleForm title = new FundingTitleForm(); + title.setTitle(Text.valueOf("title")); + funding.setFundingTitle(title); + funding.setDescription(Text.valueOf("Desc")); + funding.setUrl(Text.valueOf("http://test.com")); // Check valid start date Date startDate = new Date(); startDate.setMonth("01"); funding.setStartDate(startDate); funding = fundingController.postFunding(funding); - assertNotNull(funding); assertNotNull(funding.getErrors()); assertEquals(1, funding.getErrors().size()); - assertEquals(fundingController.getMessage("common.dates.invalid"), funding.getErrors().get(0)); // Check valid end date - funding = getFundingForm(); + funding = createBlankFundingForm(); + funding.setFundingType(Text.valueOf("award")); + funding.setCity(Text.valueOf("city")); + funding.setCountry(Text.valueOf("CR")); + funding.setFundingName(Text.valueOf("Name")); + funding.setFundingTitle(title); + funding.setDescription(Text.valueOf("Desc")); + funding.setUrl(Text.valueOf("http://test.com")); Date endDate = new Date(); endDate.setMonth("01"); funding.setEndDate(endDate); funding = fundingController.postFunding(funding); - assertNotNull(funding); - assertNotNull(funding.getErrors()); assertEquals(1, funding.getErrors().size()); - assertEquals(fundingController.getMessage("common.dates.invalid"), funding.getErrors().get(0)); // Check end date is after start date - funding = getFundingForm(); + funding = createBlankFundingForm(); + funding.setFundingType(Text.valueOf("award")); + funding.setCity(Text.valueOf("city")); + funding.setCountry(Text.valueOf("CR")); + funding.setFundingName(Text.valueOf("Name")); + funding.setFundingTitle(title); + funding.setDescription(Text.valueOf("Desc")); + funding.setUrl(Text.valueOf("http://test.com")); startDate = new Date(); startDate.setMonth("01"); startDate.setYear("2015"); - endDate = new Date(); endDate.setMonth("01"); endDate.setYear("2014"); - funding.setStartDate(startDate); funding.setEndDate(endDate); funding = fundingController.postFunding(funding); - assertNotNull(funding); - assertNotNull(funding.getErrors()); assertEquals(1, funding.getErrors().size()); - assertEquals(fundingController.getMessage("fundings.endDate.after"), funding.getErrors().get(0)); } @Test public void testGetFundingsJsonSortedBySource() { HttpSession session = mock(HttpSession.class); - when(servletRequest.getSession()).thenReturn(session); - when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); + Mockito.lenient().when(servletRequest.getSession()).thenReturn(session); + Mockito.lenient().when(localeManager.getLocale()).thenReturn(new Locale("us", "EN")); + + List summaries = new ArrayList<>(); + Fundings fundingsJaxb = new Fundings(); + + org.orcid.jaxb.model.v3.release.record.summary.FundingGroup group1 = createFundingGroupJaxb(1L); + group1.getFundingSummary().get(0).setSource(createSource("4444-4444-4444-4441")); + + org.orcid.jaxb.model.v3.release.record.summary.FundingGroup group2 = createFundingGroupJaxb(2L); + group2.getFundingSummary().get(0).setSource(createSource("4444-4444-4444-4442")); + + org.orcid.jaxb.model.v3.release.record.summary.FundingGroup group3 = createFundingGroupJaxb(3L); + group3.getFundingSummary().get(0).setSource(createSource("4444-4444-4444-4443")); + + fundingsJaxb.getFundingGroup().add(group1); + fundingsJaxb.getFundingGroup().add(group2); + fundingsJaxb.getFundingGroup().add(group3); + + when(profileFundingManager.getFundingSummaryList(ORCID)).thenReturn(summaries); + when(profileFundingManager.groupFundings(summaries, false)).thenReturn(fundingsJaxb); List fundings = fundingController.getFundingsJson("source", true); assertNotNull(fundings); @@ -653,15 +765,80 @@ public void testGetFundingsJsonSortedBySource() { assertEquals("4444-4444-4444-4443", fundings.get(2).getFundings().get(0).getSource()); } - private FundingForm getFundingForm() { - FundingForm funding = fundingController.getFunding(); - funding.setFundingType(Text.valueOf("award")); - funding.setCity(Text.valueOf("city")); - funding.setCountry(Text.valueOf("CR")); - funding.setFundingName(Text.valueOf("Name")); - FundingTitleForm title = new FundingTitleForm(); - title.setTitle(Text.valueOf("title")); - funding.setFundingTitle(title); + private FundingSummary createFundingSummary(Long putCode) { + FundingSummary summary = new FundingSummary(); + summary.setPutCode(putCode); + summary.setSource(createSource(ORCID)); + summary.setType(org.orcid.jaxb.model.common.FundingType.AWARD); + FundingTitle fundingTitle = new FundingTitle(); + fundingTitle.setTitle(new Title("Title")); + summary.setTitle(fundingTitle); + summary.setVisibility(org.orcid.jaxb.model.v3.release.common.Visibility.PUBLIC); + summary.setOrganization(createOrganization()); + summary.setCreatedDate(new CreatedDate()); + summary.setLastModifiedDate(new LastModifiedDate()); + return summary; + } + + private org.orcid.jaxb.model.v3.release.record.summary.FundingGroup createFundingGroupJaxb(Long putCode) { + org.orcid.jaxb.model.v3.release.record.summary.FundingGroup group = new org.orcid.jaxb.model.v3.release.record.summary.FundingGroup(); + FundingSummary summary = createFundingSummary(putCode); + summary.setDisplayIndex("0"); + group.getFundingSummary().add(summary); + return group; + } + + private Source createSource(String orcid) { + Source source = new Source(); + source.setSourceOrcid(new SourceOrcid(orcid)); + return source; + } + + private Organization createOrganization() { + Organization org = new Organization(); + org.setName("Org Name"); + OrganizationAddress address = new OrganizationAddress(); + address.setCity("City"); + address.setCountry(Iso3166Country.US); + org.setAddress(address); + return org; + } + + private Funding createFunding(Long putCode, String title, String type, String amount, String currency) { + Funding funding = new Funding(); + funding.setPutCode(putCode); + funding.setType(org.orcid.jaxb.model.common.FundingType.fromValue(type)); + FundingTitle fundingTitle = new FundingTitle(); + fundingTitle.setTitle(new Title(title)); + funding.setTitle(fundingTitle); + if (amount != null) { + Amount amountObj = new Amount(); + amountObj.setContent(amount); + amountObj.setCurrencyCode(currency); + funding.setAmount(amountObj); + } + funding.setOrganization(createOrganization()); + funding.setSource(createSource(ORCID)); return funding; } + + private FundingForm createBlankFundingForm() { + FundingForm result = new FundingForm(); + result.setAmount(new Text()); + result.setCurrencyCode(Text.valueOf("")); + result.setDescription(new Text()); + result.setFundingName(new Text()); + result.setFundingType(Text.valueOf("")); + result.setFundingTitle(new FundingTitleForm()); + result.getFundingTitle().setTitle(new Text()); + result.getFundingTitle().setTranslatedTitle(new TranslatedTitleForm()); + result.setExternalIdentifiers(new ArrayList<>()); + result.setStartDate(new Date()); + result.setEndDate(new Date()); + result.setCity(new Text()); + result.setRegion(new Text()); + result.setCountry(new Text()); + result.setUrl(new Text()); + return result; + } }