@Test
  public void testCheckForUnitDetailsNotRequired_KP() {
    Assert.assertTrue(
        MISSING_UNIT_DETAILS_NOT_IDENTIFIED,
        rule.checkForRequiredUnitDetails(award.getProjectPersons()));

    kpPerson.getUnits().clear();
    Assert.assertTrue(
        MISSING_UNIT_DETAILS_NOT_IDENTIFIED,
        rule.checkForRequiredUnitDetails(award.getProjectPersons()));
    Assert.assertEquals(0, GlobalVariables.getMessageMap().getErrorCount());
  }
 @Test
 public void testCheckForExistingPI() {
   Assert.assertTrue(
       "PI not found or more than one found",
       rule.checkForOnePrincipalInvestigator(award.getProjectPersons()));
   award.getProjectPersons().remove(0);
   Assert.assertFalse(
       "PI existence check failed",
       rule.checkForOnePrincipalInvestigator(award.getProjectPersons()));
   checkErrorState(
       AwardProjectPersonsSaveRule.AWARD_PROJECT_PERSON_LIST_ERROR_KEY,
       AwardProjectPersonsSaveRule.ERROR_AWARD_PROJECT_PERSON_NO_PI);
 }
  @Test
  public void testCheckForLeadUnit_NoneFound() {
    Assert.assertTrue(
        "No lead unit was found", rule.checkForLeadUnitForPI(award.getProjectPersons()));

    piPerson.getUnit(0).setLeadUnit(false);
    Assert.assertFalse(
        "No lead unit should have been found",
        rule.checkForLeadUnitForPI(award.getProjectPersons()));

    checkErrorState(
        AwardProjectPersonsSaveRule.AWARD_PROJECT_PERSON_LIST_ERROR_KEY,
        AwardProjectPersonsSaveRule.ERROR_AWARD_PROJECT_PERSON_LEAD_UNIT_REQUIRED);
  }
  @Test
  public void testCheckForRequiredUnitDetails_COI() {
    Assert.assertTrue(
        MISSING_UNIT_DETAILS_NOT_IDENTIFIED,
        rule.checkForRequiredUnitDetails(award.getProjectPersons()));

    coiPerson.getUnits().clear();
    Assert.assertFalse(
        MISSING_UNIT_DETAILS_NOT_IDENTIFIED,
        rule.checkForRequiredUnitDetails(award.getProjectPersons()));

    checkErrorState(
        AwardProjectPersonsSaveRule.AWARD_PROJECT_PERSON_LIST_ERROR_KEY,
        AwardProjectPersonsSaveRule.ERROR_AWARD_PROJECT_PERSON_UNIT_DETAILS_REQUIRED);
  }
Exemple #5
0
 @SuppressWarnings("unchecked")
 @Override
 public void applySyncChange(Award award, AwardSyncChange change)
     throws NoSuchFieldException, IllegalAccessException, InvocationTargetException,
         ClassNotFoundException, NoSuchMethodException, InstantiationException,
         AwardSyncException {
   Collection awardPersons = award.getProjectPersons();
   AwardSyncXmlExport unitExport =
       (AwardSyncXmlExport) change.getXmlExport().getValues().get("units");
   AwardPerson person =
       (AwardPerson)
           getAwardSyncUtilityService()
               .findMatchingBo(awardPersons, change.getXmlExport().getKeys());
   if (StringUtils.equals(change.getSyncType(), AwardSyncType.ADD_SYNC.getSyncValue())) {
     if (person != null) {
       checkAndFixLeadUnit(person, unitExport);
       setValuesOnSyncable(person, change.getXmlExport().getValues(), change);
       fixLeadUnit(award, person);
     } else {
       throw new AwardSyncException(Constants.AWARD_SYNC_NOT_APPLICABLE, true);
     }
   } else {
     if (person != null) {
       AwardPersonUnit unit =
           (AwardPersonUnit)
               getAwardSyncUtilityService()
                   .findMatchingBo((Collection) person.getUnits(), unitExport.getKeys());
       if (unit != null) {
         person.getUnits().remove(unit);
       }
     } else {
       throw new AwardSyncException(Constants.AWARD_SYNC_NOT_APPLICABLE, true);
     }
   }
 }
  @Test
  public void testProjectRolesChanges() {
    // when a coi is changed to key person
    coiPerson.setContactRole(ContactRoleFixtureFactory.MOCK_KEY_PERSON);
    Assert.assertFalse(
        "Key Person Role not checked for",
        rule.checkForKeyPersonProjectRoles(award.getProjectPersons()));
    coiPerson.setKeyPersonRole("fromCOI");
    Assert.assertTrue(
        "Key Person Role not checked for",
        rule.checkForKeyPersonProjectRoles(award.getProjectPersons()));

    // when a key person is changed to coi
    kpPerson.setContactRole(ContactRoleFixtureFactory.MOCK_COI);
    Assert.assertTrue(
        "rule should return true",
        rule.processSaveAwardProjectPersonsBusinessRules(award.getProjectPersons()));
  }
  @Test
  public void testCheckForDuplicateUnits_DupeFound() {
    piPerson.add(new AwardPersonUnit(piPerson, unitA, false));
    Assert.assertFalse(
        "Duplicate should have been found", rule.checkForDuplicateUnits(award.getProjectPersons()));

    checkErrorState(
        AwardProjectPersonsSaveRule.AWARD_PROJECT_PERSON_LIST_ERROR_KEY,
        AwardProjectPersonsSaveRule.ERROR_AWARD_PROJECT_PERSON_DUPLICATE_UNITS);
  }
  @Test
  public void testCheckForKeyPersonRole_NotFound() {
    kpPerson.setKeyPersonRole(null);
    Assert.assertFalse(
        "Key Person Role not checked for",
        rule.checkForKeyPersonProjectRoles(award.getProjectPersons()));

    checkErrorState(
        AwardProjectPersonsSaveRule.AWARD_PROJECT_PERSON_LIST_ERROR_KEY,
        AwardProjectPersonsSaveRule.ERROR_AWARD_PROJECT_KEY_PERSON_ROLE_REQUIRED);
  }
  @Test
  public void testCheckForMultiplePIs() {
    AwardPerson newPerson =
        new AwardPerson(
            KcPersonFixtureFactory.createKcPerson(KP_PERSON_ID), ContactRoleFixtureFactory.MOCK_PI);
    newPerson.setPropAwardPersonRoleService(roleService);
    award.add(newPerson);
    Assert.assertFalse(
        "Multiple PIs not detected",
        rule.checkForOnePrincipalInvestigator(award.getProjectPersons()));

    checkErrorState(
        AwardProjectPersonsSaveRule.AWARD_PROJECT_PERSON_LIST_ERROR_KEY,
        AwardProjectPersonsSaveRule.ERROR_AWARD_PROJECT_PERSON_MULTIPLE_PI_EXISTS);
  }
  private void checkErrorState(String errorProperty, String errorMessageKey) {
    MessageMap messageMap = GlobalVariables.getMessageMap();
    Assert.assertTrue(messageMap.getErrorCount() >= 1);
    @SuppressWarnings("unchecked")
    List<ErrorMessage> errors = messageMap.getErrorMessagesForProperty(errorProperty);
    if (errors != null) {
      Assert.assertEquals(1, errors.size());
      Assert.assertEquals(errorMessageKey, errors.get(0).getErrorKey());
    } else {
      Assert.fail("No errors posted");
    }

    Assert.assertFalse(
        "rule should return false",
        rule.processSaveAwardProjectPersonsBusinessRules(award.getProjectPersons()));
  }
 @Test
 public void testCheckForKeyPersonRole_Found() {
   Assert.assertTrue(
       "Key Person Role not checked for",
       rule.checkForKeyPersonProjectRoles(award.getProjectPersons()));
 }
 @Test
 public void testCheckForDuplicateUnits_NoneFound() {
   piPerson.add(new AwardPersonUnit(piPerson, unitB, false));
   Assert.assertTrue(rule.checkForDuplicateUnits(award.getProjectPersons()));
 }