use of org.orcid.core.exception.OrcidUnauthorizedException in project ORCID-Source by ORCID.
the class SalesForceManagerImplTest method testCheckContactUpdatePermissions.
@Test
public void testCheckContactUpdatePermissions() {
List<Contact> existingContacts = new ArrayList<>();
existingContacts.add(createContactWithRole("contact1", "account1", "contact1@test.com", "0000-0000-0000-0001", "role1", ContactRoleType.MAIN_CONTACT));
existingContacts.add(createContactWithRole("contact2", "account1", "contact2@test.com", "0000-0000-0000-0002", "role2", ContactRoleType.AGREEMENT_SIGNATORY));
existingContacts.add(createContactWithRole("contact3", "account1", "contact3@test.com", "0000-0000-0000-0003", "role3", ContactRoleType.INVOICE_CONTACT));
Contact votingContact = createContactWithRole("contact4", "account1", "contact4@test.com", "0000-0000-0000-0004", "role4", ContactRoleType.OTHER_CONTACT);
votingContact.getRole().setVotingContact(true);
existingContacts.add(votingContact);
List<Contact> updatedContacts = new ArrayList<>();
Contact updatedContact1 = createContactWithRole("contact1", "account1", "contact1@test.com", "0000-0000-0000-0001", "role1", ContactRoleType.MAIN_CONTACT);
updatedContacts.add(updatedContact1);
updatedContacts.add(createContactWithRole("contact2", "account1", "contact2@test.com", "0000-0000-0000-0002", "role2", ContactRoleType.AGREEMENT_SIGNATORY));
updatedContacts.add(createContactWithRole("contact3", "account1", "contact3@test.com", "0000-0000-0000-0003", "role3", ContactRoleType.INVOICE_CONTACT));
Contact updatedVotingContact = createContactWithRole("contact4", "account1", "contact4@test.com", "0000-0000-0000-0004", "role4", ContactRoleType.OTHER_CONTACT);
updatedVotingContact.getRole().setVotingContact(true);
updatedContacts.add(updatedVotingContact);
when(sourceManager.retrieveRealUserOrcid()).thenReturn("0000-0000-0000-0001");
salesForceManager.checkContactUpdatePermissions(existingContacts, updatedContacts);
updatedContact1.getRole().setRoleType(ContactRoleType.OTHER_CONTACT);
when(sourceManager.retrieveRealUserOrcid()).thenReturn("0000-0000-0000-0001");
try {
salesForceManager.checkContactUpdatePermissions(existingContacts, updatedContacts);
} catch (OrcidUnauthorizedException e) {
fail("Should be able to change main contact role when am main contact");
}
when(sourceManager.retrieveRealUserOrcid()).thenReturn("0000-0000-0000-0003");
boolean preventedChange = false;
try {
salesForceManager.checkContactUpdatePermissions(existingContacts, updatedContacts);
} catch (OrcidUnauthorizedException e) {
preventedChange = true;
}
if (!preventedChange) {
fail("Should not be able to change main contact role when am not main/signatory contact");
}
// Set role back to what it was, but change voting contact.
updatedContact1.getRole().setRoleType(ContactRoleType.MAIN_CONTACT);
updatedContact1.getRole().setVotingContact(true);
updatedVotingContact.getRole().setVotingContact(false);
when(sourceManager.retrieveRealUserOrcid()).thenReturn("0000-0000-0000-0001");
try {
salesForceManager.checkContactUpdatePermissions(existingContacts, updatedContacts);
} catch (OrcidUnauthorizedException e) {
fail("Should be able to change voting contact when am main contact");
}
when(sourceManager.retrieveRealUserOrcid()).thenReturn("0000-0000-0000-0003");
preventedChange = false;
try {
salesForceManager.checkContactUpdatePermissions(existingContacts, updatedContacts);
} catch (OrcidUnauthorizedException e) {
preventedChange = true;
}
if (!preventedChange) {
fail("Should not be able to change voting contact when am not main/signatory contact");
}
}
Aggregations