Search in sources :

Example 6 with DelegateSummary

use of org.orcid.jaxb.model.message.DelegateSummary in project ORCID-Source by ORCID.

the class NotificationManagerTest method testAddedDelegatesSentCorrectEmail.

@Test
public void testAddedDelegatesSentCorrectEmail() throws JAXBException, IOException, URISyntaxException {
    TargetProxyHelper.injectIntoProxy(notificationManager, "profileEntityCacheManager", mockProfileEntityCacheManager);
    TargetProxyHelper.injectIntoProxy(notificationManager, "emailManager", mockEmailManager);
    TargetProxyHelper.injectIntoProxy(notificationManager, "profileDao", mockProfileDao);
    TargetProxyHelper.injectIntoProxy(notificationManager, "notificationDao", mockNotificationDao);
    TargetProxyHelper.injectIntoProxy(notificationManager, "notificationAdapter", mockNotificationAdapter);
    final String orcid = "0000-0000-0000-0003";
    String delegateOrcid = "1234-5678-1234-5678";
    ProfileEntity profile = new ProfileEntity();
    RecordNameEntity recordName = new RecordNameEntity();
    recordName.setCreditName("My credit name");
    recordName.setVisibility(Visibility.PUBLIC);
    profile.setRecordNameEntity(recordName);
    profile.setSendAdministrativeChangeNotifications(true);
    profile.setSendChangeNotifications(true);
    profile.setSendMemberUpdateRequests(true);
    profile.setSendOrcidNews(true);
    EmailEntity emailEntity = new EmailEntity();
    emailEntity.setId("test@email.com");
    emailEntity.setPrimary(true);
    emailEntity.setCurrent(true);
    Set<EmailEntity> emails = new HashSet<EmailEntity>();
    emails.add(emailEntity);
    profile.setEmails(emails);
    SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
    when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
    when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
    when(mockNotificationAdapter.toNotificationEntity(Mockito.any(Notification.class))).thenReturn(new NotificationCustomEntity());
    Email email = new Email();
    email.setEmail("test@email.com");
    when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {

        @Override
        public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
            profile.setId(invocation.getArgument(0));
            return profile;
        }
    });
    when(mockProfileDao.find(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {

        @Override
        public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
            profile.setId(invocation.getArgument(0));
            return profile;
        }
    });
    when(mockEmailManager.findPrimaryEmail(orcid)).thenReturn(email);
    DelegationDetails firstNewDelegate = new DelegationDetails();
    DelegateSummary firstNewDelegateSummary = new DelegateSummary();
    firstNewDelegateSummary.setCreditName(new CreditName("Jimmy Dove"));
    firstNewDelegate.setDelegateSummary(firstNewDelegateSummary);
    firstNewDelegateSummary.setOrcidIdentifier(new OrcidIdentifier(delegateOrcid));
    for (org.orcid.jaxb.model.common_v2.Locale locale : org.orcid.jaxb.model.common_v2.Locale.values()) {
        profile.setLocale(locale);
        notificationManager.sendNotificationToAddedDelegate("0000-0000-0000-0003", firstNewDelegate);
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Email(org.orcid.jaxb.model.record_v2.Email) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) CreditName(org.orcid.jaxb.model.message.CreditName) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Notification(org.orcid.jaxb.model.notification_v2.Notification) DelegateSummary(org.orcid.jaxb.model.message.DelegateSummary) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) DelegationDetails(org.orcid.jaxb.model.message.DelegationDetails) HashSet(java.util.HashSet) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

DelegateSummary (org.orcid.jaxb.model.message.DelegateSummary)6 DelegationDetails (org.orcid.jaxb.model.message.DelegationDetails)6 Delegation (org.orcid.jaxb.model.message.Delegation)3 OrcidIdentifier (org.orcid.jaxb.model.message.OrcidIdentifier)3 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2 Test (org.junit.Test)2 CreditName (org.orcid.jaxb.model.message.CreditName)2 GivenPermissionBy (org.orcid.jaxb.model.message.GivenPermissionBy)2 GivenPermissionTo (org.orcid.jaxb.model.message.GivenPermissionTo)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 ApprovalDate (org.orcid.jaxb.model.message.ApprovalDate)1 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)1