Search in sources :

Example 1 with ManageDelegate

use of org.orcid.pojo.ManageDelegate in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method testAddDelegateWithInvalidPassword.

@Test
public void testAddDelegateWithInvalidPassword() {
    ManageDelegate manageDelegate = new ManageDelegate();
    manageDelegate.setDelegateToManage(USER_ORCID);
    manageDelegate.setPassword("invalid password");
    controller.addDelegate(manageDelegate);
    assertEquals(1, manageDelegate.getErrors().size());
    assertEquals("check_password_modal.incorrect_password", manageDelegate.getErrors().get(0));
    verify(mockGivenPermissionToManager, times(0)).create(Mockito.anyString(), Mockito.anyString());
}
Also used : ManageDelegate(org.orcid.pojo.ManageDelegate) Test(org.junit.Test)

Example 2 with ManageDelegate

use of org.orcid.pojo.ManageDelegate in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method testRevokeDelegateWithInvalidPassword.

@Test
public void testRevokeDelegateWithInvalidPassword() {
    ManageDelegate manageDelegate = new ManageDelegate();
    manageDelegate.setDelegateToManage(USER_ORCID);
    manageDelegate.setPassword("invalid password");
    controller.revokeDelegate(manageDelegate);
    assertEquals(1, manageDelegate.getErrors().size());
    assertEquals("check_password_modal.incorrect_password", manageDelegate.getErrors().get(0));
    verify(mockGivenPermissionToManager, times(0)).remove(Mockito.anyString(), Mockito.anyString());
}
Also used : ManageDelegate(org.orcid.pojo.ManageDelegate) Test(org.junit.Test)

Example 3 with ManageDelegate

use of org.orcid.pojo.ManageDelegate in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method testRevokeDelegate.

@Test
public void testRevokeDelegate() {
    SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
    ManageDelegate manageDelegate = new ManageDelegate();
    manageDelegate.setDelegateToManage("0000-0000-0000-0000");
    manageDelegate.setPassword("password");
    controller.revokeDelegate(manageDelegate);
    assertEquals(0, manageDelegate.getErrors().size());
    verify(mockGivenPermissionToManager, times(1)).remove(Mockito.eq(USER_ORCID), Mockito.eq("0000-0000-0000-0000"));
}
Also used : ManageDelegate(org.orcid.pojo.ManageDelegate) Test(org.junit.Test)

Example 4 with ManageDelegate

use of org.orcid.pojo.ManageDelegate in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method testAddDelegate.

@Test
public void testAddDelegate() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
    when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).then(new Answer<ProfileEntity>() {

        @Override
        public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
            ProfileEntity entity = new ProfileEntity();
            entity.setId(invocation.getArgument(0));
            EmailEntity email1 = new EmailEntity();
            email1.setId(invocation.getArgument(0) + "_1@test.orcid.org");
            email1.setVerified(true);
            email1.setCurrent(true);
            email1.setDateCreated(new Date());
            email1.setLastModified(new Date());
            email1.setPrimary(true);
            email1.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
            Set<EmailEntity> emails = new HashSet<EmailEntity>();
            emails.add(email1);
            entity.setEmails(emails);
            entity.setRecordNameEntity(getRecordName(invocation.getArgument(0)));
            // Mark it as deactivated
            entity.setDeactivationDate(new Date());
            entity.setEncryptedPassword("password");
            return entity;
        }
    });
    ManageDelegate addDelegate = new ManageDelegate();
    addDelegate.setDelegateToManage("0000-0000-0000-0000");
    addDelegate.setPassword("password");
    controller.addDelegate(addDelegate);
    verify(mockGivenPermissionToManager, times(1)).create(USER_ORCID, "0000-0000-0000-0000");
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) ManageDelegate(org.orcid.pojo.ManageDelegate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 ManageDelegate (org.orcid.pojo.ManageDelegate)4 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)1 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)1