@Test
 public void testAddBudgetPerson() throws Exception {
   assertTrue(budget.getBudgetPersons().isEmpty());
   BudgetPerson testPerson = new BudgetPerson();
   testPerson.setPersonId(testOtherPersonId);
   budgetPersonService.addBudgetPerson(budget, testPerson);
   assertTrue(budget.getBudgetPersons().size() == 1);
 }
 @Test
 public void testAddBudgetPersonWithAppointments() throws Exception {
   assertTrue(budget.getBudgetPersons().isEmpty());
   BudgetPerson testPerson = new BudgetPerson();
   KcPerson person = kcPersonService.getKcPersonByPersonId(testAppointmentPersonId);
   testPerson.setPersonId(testAppointmentPersonId);
   budgetPersonService.addBudgetPerson(budget, testPerson);
   assertFalse(person.getExtendedAttributes().getPersonAppointments().isEmpty());
   assertTrue(
       person.getExtendedAttributes().getPersonAppointments().size()
           == budget.getBudgetPersons().size());
 }
  @Test
  public void testExample1WithNonNih() throws Exception {
    context.checking(
        new Expectations() {
          {
            one(sponsorHierarchyService).isSponsorNihMultiplePi(NON_NIH_SPONSOR_CODE);
            will(returnValue(false));
          }
        });
    budget.getDevelopmentProposal().setSponsorCode(NON_NIH_SPONSOR_CODE);

    subAward.getBudgetSubAwardPeriodDetails().get(0).setDirectCost(new ScaleTwoDecimal(150000L));
    subAward.getBudgetSubAwardPeriodDetails().get(0).setIndirectCost(new ScaleTwoDecimal(75000L));
    subAward.getBudgetSubAwardPeriodDetails().get(1).setDirectCost(new ScaleTwoDecimal(150000L));
    subAward.getBudgetSubAwardPeriodDetails().get(1).setIndirectCost(new ScaleTwoDecimal(75000L));

    List<Map<String, ScaleTwoDecimal>> expectedResults = new ArrayList<>();
    expectedResults.add(new HashMap<>());
    expectedResults.add(new HashMap<>());
    expectedResults.add(new HashMap<>());
    expectedResults.get(0).put(indirectGt, ScaleTwoDecimal.ZERO);
    expectedResults.get(0).put(indirectLt, ScaleTwoDecimal.ZERO);
    expectedResults.get(0).put(directGt, new ScaleTwoDecimal(200000L));
    expectedResults.get(0).put(directLt, new ScaleTwoDecimal(25000L));
    expectedResults.get(1).put(indirectGt, ScaleTwoDecimal.ZERO);
    expectedResults.get(1).put(indirectLt, ScaleTwoDecimal.ZERO);
    expectedResults.get(1).put(directGt, new ScaleTwoDecimal(225000L));
    expectedResults.get(1).put(directLt, ScaleTwoDecimal.ZERO);
    service.generateSubAwardLineItems(subAward, budget);
    assertExpectedResults(expectedResults);
    assertCostShare(0);
  }
  @Test
  public void testExample1WithLineItems() throws Exception {
    context.checking(
        new Expectations() {
          {
            one(sponsorHierarchyService).isSponsorNihMultiplePi(NIH_SPONSOR_CODE);
            will(returnValue(true));
          }
        });

    subAward.getBudgetSubAwardPeriodDetails().get(0).setDirectCost(new ScaleTwoDecimal(150000L));
    subAward.getBudgetSubAwardPeriodDetails().get(0).setIndirectCost(new ScaleTwoDecimal(75000L));
    subAward.getBudgetSubAwardPeriodDetails().get(1).setDirectCost(new ScaleTwoDecimal(150000L));
    subAward.getBudgetSubAwardPeriodDetails().get(1).setIndirectCost(new ScaleTwoDecimal(75000L));

    for (BudgetPeriod period : budget.getBudgetPeriods()) {
      BudgetLineItem newLineItem = new BudgetLineItem();
      newLineItem.setBudgetSubAward(subAward);
      newLineItem.setSubAwardNumber(subAward.getSubAwardNumber());
      newLineItem.setDirectCost(new ScaleTwoDecimal(100L));
      newLineItem.setCostSharingAmount(new ScaleTwoDecimal(100L));
      newLineItem.setCostElement(directLt);
      newLineItem.setLineItemNumber(1);
      period.getBudgetLineItems().add(newLineItem);
      newLineItem = (BudgetLineItem) org.kuali.rice.krad.util.ObjectUtils.deepCopy(newLineItem);
      newLineItem.setCostElement(directGt);
      newLineItem.setLineItemNumber(2);
      period.getBudgetLineItems().add(newLineItem);
      newLineItem = (BudgetLineItem) org.kuali.rice.krad.util.ObjectUtils.deepCopy(newLineItem);
      newLineItem.setCostElement(indirectLt);
      newLineItem.setLineItemNumber(3);
      period.getBudgetLineItems().add(newLineItem);
      newLineItem = (BudgetLineItem) org.kuali.rice.krad.util.ObjectUtils.deepCopy(newLineItem);
      newLineItem.setCostElement(indirectGt);
      newLineItem.setLineItemNumber(4);
      period.getBudgetLineItems().add(newLineItem);
    }

    List<Map<String, ScaleTwoDecimal>> expectedResults = new ArrayList<>();
    expectedResults.add(new HashMap<>());
    expectedResults.add(new HashMap<>());
    expectedResults.add(new HashMap<>());
    expectedResults.get(0).put(indirectGt, new ScaleTwoDecimal(75000L));
    expectedResults.get(0).put(indirectLt, ScaleTwoDecimal.ZERO);
    expectedResults.get(0).put(directGt, new ScaleTwoDecimal(125000L));
    expectedResults.get(0).put(directLt, new ScaleTwoDecimal(25000L));
    expectedResults.get(1).put(indirectGt, new ScaleTwoDecimal(75000L));
    expectedResults.get(1).put(indirectLt, ScaleTwoDecimal.ZERO);
    expectedResults.get(1).put(directGt, new ScaleTwoDecimal(150000L));
    expectedResults.get(1).put(directLt, ScaleTwoDecimal.ZERO);
    service.generateSubAwardLineItems(subAward, budget);
    assertExpectedResults(expectedResults);
    assertCostShare(0);
  }
  @SuppressWarnings("serial")
  @Before
  public void setUp() throws Exception {
    kcPersonService = KcServiceLocator.getService(KcPersonService.class);
    budgetPersonService =
        (BudgetPersonServiceImpl) KcServiceLocator.getService(BudgetPersonService.class);
    budget =
        new ProposalDevelopmentBudgetExt() {
          int nextVal = 1;

          public Integer getHackedDocumentNextValue(String documentComponentIdKey) {
            return nextVal++;
          }
        };

    startDate = createDate(2010, 1, 1);
    endDate = createDate(2010, 12, 30);
    budget.setStartDate(startDate);
    budget.setEndDate(endDate);
    budget.setDevelopmentProposal(new DevelopmentProposal());
  }
  @Before
  public void setUp() throws Exception {
    context =
        new JUnit4Mockery() {
          {
            setThreadingPolicy(new Synchroniser());
          }
        };
    service = new PropDevPropDevBudgetSubAwardServiceImpl();
    budget = new ProposalDevelopmentBudgetExt();
    budget.setBudgetId(1L + 12);
    budget.setDevelopmentProposal(new DevelopmentProposal());
    budget.getDevelopmentProposal().setSponsorCode(NIH_SPONSOR_CODE);
    subAward = new BudgetSubAwards();
    subAward.setBudgetId(budget.getBudgetId());
    subAward.setSubAwardNumber(1 + 206);
    Organization testOrg = new Organization();
    testOrg.setOrganizationName("University of Maine");
    testOrg.setOrganizationId("000040");
    subAward.setOrganization(testOrg);
    budget.getBudgetSubAwards().add(subAward);
    for (int i = 0; i < 2; i++) {
      BudgetPeriod period = new BudgetPeriod();

      period.setBudget(budget);
      period.setBudgetPeriod(i);
      period.setBudgetPeriodId(i + 1029L);
      budget.getBudgetPeriods().add(period);
      BudgetSubAwardPeriodDetail detail = new BudgetSubAwardPeriodDetail(subAward, period);
      detail.setBudgetSubAward(subAward);
      subAward.getBudgetSubAwardPeriodDetails().add(detail);
    }
    final ParameterService parmService = context.mock(ParameterService.class);
    sponsorHierarchyService = context.mock(SponsorHierarchyService.class);
    context.checking(
        new Expectations() {
          {
            one(parmService)
                .getParameterValueAsString(
                    Budget.class, Constants.SUBCONTRACTOR_DIRECT_LT_25K_PARAM);
            will(returnValue(directLt));
            one(parmService)
                .getParameterValueAsString(
                    Budget.class, Constants.SUBCONTRACTOR_DIRECT_GT_25K_PARAM);
            will(returnValue(directGt));
            one(parmService)
                .getParameterValueAsString(
                    Budget.class, Constants.SUBCONTRACTOR_F_AND_A_LT_25K_PARAM);
            will(returnValue(indirectLt));
            one(parmService)
                .getParameterValueAsString(
                    Budget.class, Constants.SUBCONTRACTOR_F_AND_A_GT_25K_PARAM);
            will(returnValue(indirectGt));
          }
        });
    service.setParameterService(parmService);
    service.setSponsorHierarchyService(sponsorHierarchyService);
    service.setBudgetService(new BudgetServiceMock());
  }
 protected void assertCostShare(long costShareAmount) {
   for (BudgetPeriod period : budget.getBudgetPeriods()) {
     Collections.sort(
         period.getBudgetLineItems(),
         new Comparator<BudgetLineItem>() {
           public int compare(BudgetLineItem arg0, BudgetLineItem arg1) {
             return arg0.getLineItemNumber().compareTo(arg1.getLineItemNumber());
           }
         });
     Assert.assertEquals(
         new ScaleTwoDecimal(costShareAmount),
         period.getBudgetLineItems().get(0).getCostSharingAmount());
     for (int i = 1; i < period.getBudgetLineItems().size(); i++) {
       Assert.assertEquals(
           ScaleTwoDecimal.ZERO, period.getBudgetLineItems().get(i).getCostSharingAmount());
     }
   }
 }
 protected void assertExpectedResults(List<Map<String, ScaleTwoDecimal>> results) {
   int index = 0;
   for (BudgetPeriod period : budget.getBudgetPeriods()) {
     for (BudgetLineItem lineItem : period.getBudgetLineItems()) {
       Assert.assertEquals(subAward.getSubAwardNumber(), lineItem.getSubAwardNumber());
       Assert.assertEquals(
           results.get(index).get(lineItem.getCostElement()), lineItem.getLineItemCost());
     }
     for (Map.Entry<String, ScaleTwoDecimal> entry : results.get(index).entrySet()) {
       final List<BudgetLineItem> lineItemsByCostElement =
           findLineItemsByCostElement(period.getBudgetLineItems(), entry.getKey());
       if (entry.getValue().isZero()) {
         Assert.assertTrue(lineItemsByCostElement.size() == 0);
       } else {
         Assert.assertEquals(entry.getValue(), lineItemsByCostElement.get(0).getLineItemCost());
       }
     }
     index++;
   }
 }
Example #9
0
  @Override
  protected void prepareData(ProposalDevelopmentDocument document) throws Exception {

    Organization organization =
        getService(DataObjectService.class)
            .findUnique(
                Organization.class,
                QueryByCriteria.Builder.forAttribute("organizationId", "000001").build());
    document.getDevelopmentProposal().getApplicantOrganization().setOrganization(organization);

    NarrativeAttachment narrativeAttachment = new NarrativeAttachment();
    DefaultResourceLoader resourceLoader =
        new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader());
    Resource resource = resourceLoader.getResource(S2STestConstants.ATT_PACKAGE + "/exercise2.pdf");
    InputStream inputStream = resource.getInputStream();
    BufferedInputStream bis = new BufferedInputStream(inputStream);
    byte[] narrativePdf = new byte[bis.available()];
    narrativeAttachment.setData(narrativePdf);
    narrativeAttachment.setName("exercise1");
    Narrative narrative = new Narrative();
    List<Narrative> narrativeList = new ArrayList<Narrative>();
    narrative.setDevelopmentProposal(document.getDevelopmentProposal());
    NarrativeType narrativeType =
        getService(DataObjectService.class)
            .findUnique(
                NarrativeType.class, QueryByCriteria.Builder.forAttribute("code", "7").build());
    narrative.setName("exercise1");
    narrative.setNarrativeType(narrativeType);
    narrative.setNarrativeTypeCode(narrativeType.getCode());
    narrative.setNarrativeAttachment(narrativeAttachment);
    narrative.setModuleNumber(1);
    narrative.setModuleSequenceNumber(1);
    narrative.setModuleStatusCode("C");
    narrativeList.add(narrative);
    document.getDevelopmentProposal().setNarratives(narrativeList);

    List<ProposalPerson> proposalPersons = new ArrayList<ProposalPerson>();
    ProposalPerson principalInvestigator = new ProposalPerson();
    principalInvestigator.setFirstName("ALAN");
    principalInvestigator.setLastName("MCAFEE");
    principalInvestigator.setProposalPersonRoleId("PI");
    principalInvestigator.setPersonId("0001");
    principalInvestigator.setRolodexId(0010);
    principalInvestigator.setProposalPersonNumber(1);
    principalInvestigator.setDevelopmentProposal(document.getDevelopmentProposal());
    proposalPersons.add(principalInvestigator);
    document.getDevelopmentProposal().setProposalPersons(proposalPersons);

    ProposalDevelopmentBudgetExt proposalDevelopmentBudgetExt = new ProposalDevelopmentBudgetExt();
    proposalDevelopmentBudgetExt.setDevelopmentProposal(document.getDevelopmentProposal());
    proposalDevelopmentBudgetExt.setBudgetVersionNumber(1);
    proposalDevelopmentBudgetExt.setBudgetStatus("1");
    proposalDevelopmentBudgetExt.setBudgetId(1L);
    proposalDevelopmentBudgetExt.setName("test Document Description");
    proposalDevelopmentBudgetExt.setOnOffCampusFlag("Y");
    proposalDevelopmentBudgetExt.setStartDate(new Date(new Long("1183316613046")));
    proposalDevelopmentBudgetExt.setEndDate(new Date(new Long("1214852613046")));
    proposalDevelopmentBudgetExt.setOhRateTypeCode("1");
    proposalDevelopmentBudgetExt.setOhRateClassCode("1");
    proposalDevelopmentBudgetExt.setModularBudgetFlag(false);
    proposalDevelopmentBudgetExt.setUrRateClassCode("1");

    List<BudgetPeriod> budgetPeriods = new ArrayList<BudgetPeriod>();
    BudgetPeriod budgetPeriod = new BudgetPeriod();
    budgetPeriod.setBudgetPeriodId(1L);
    budgetPeriod.setStartDate(new Date(new Long("1183316613046")));
    budgetPeriod.setEndDate(new Date(new Long("1214852613046")));
    budgetPeriod.setBudgetPeriod(1);

    budgetPeriod.setBudget(proposalDevelopmentBudgetExt);
    budgetPeriods.add(budgetPeriod);
    proposalDevelopmentBudgetExt.setBudgetPeriods(budgetPeriods);

    List<ProposalDevelopmentBudgetExt> proposalDevelopmentBudgetExtList =
        new ArrayList<ProposalDevelopmentBudgetExt>();
    proposalDevelopmentBudgetExtList.add(proposalDevelopmentBudgetExt);
    document.getDevelopmentProposal().setBudgets(proposalDevelopmentBudgetExtList);
    document.getDevelopmentProposal().setFinalBudget(proposalDevelopmentBudgetExt);
  }
  @Override
  protected void prepareData(ProposalDevelopmentDocument document) throws Exception {

    ProposalDevelopmentBudgetExt budget = new ProposalDevelopmentBudgetExt();
    budget.setBudgetId(new Long("000001"));
    budget.setBudgetStatus("1");
    budget.setStartDate(new Date(new Long("1183316613046")));
    budget.setEndDate(new Date(new Long("1214852613046")));
    budget.setOnOffCampusFlag("Y");
    budget.setOhRateClassCode("1");
    budget.setUrRateClassCode("1");
    budget.setModularBudgetFlag(false);
    budget.setParentDocumentTypeCode("PRDV");
    budget.setDevelopmentProposal(document.getDevelopmentProposal());
    budget.setName("test document description");

    List<BudgetPeriod> budgetPeriods = new ArrayList<BudgetPeriod>();
    BudgetPeriod budgetPeriod = new BudgetPeriod();
    budgetPeriod.setBudgetPeriod(1);
    budgetPeriod.setStartDate(new Date(new Long("1183316613046")));
    budgetPeriod.setEndDate(new Date(new Long("1214852613046")));
    budgetPeriods.add(budgetPeriod);
    budget.setBudgetPeriods(budgetPeriods);

    budget = getService(DataObjectService.class).save(budget);
    List<ProposalDevelopmentBudgetExt> budgets = new ArrayList<>();
    budgets.add(budget);
    document.getDevelopmentProposal().setBudgets(budgets);
    document.getDevelopmentProposal().setFinalBudget(budget);
  }
  @Test
  public void testExample1WithCostShare() throws Exception {
    context.checking(
        new Expectations() {
          {
            one(sponsorHierarchyService).isSponsorNihMultiplePi(NIH_SPONSOR_CODE);
            will(returnValue(true));
          }
        });

    subAward.getBudgetSubAwardPeriodDetails().get(0).setDirectCost(new ScaleTwoDecimal(150000L));
    subAward.getBudgetSubAwardPeriodDetails().get(0).setIndirectCost(new ScaleTwoDecimal(75000L));
    subAward.getBudgetSubAwardPeriodDetails().get(0).setCostShare(new ScaleTwoDecimal(1000L));

    subAward.getBudgetSubAwardPeriodDetails().get(1).setDirectCost(new ScaleTwoDecimal(150000L));
    subAward.getBudgetSubAwardPeriodDetails().get(1).setIndirectCost(new ScaleTwoDecimal(75000L));
    subAward.getBudgetSubAwardPeriodDetails().get(1).setCostShare(new ScaleTwoDecimal(1000L));

    List<Map<String, ScaleTwoDecimal>> expectedResults = new ArrayList<>();
    expectedResults.add(new HashMap<>());
    expectedResults.add(new HashMap<>());
    expectedResults.add(new HashMap<>());
    expectedResults.get(0).put(indirectGt, new ScaleTwoDecimal(75000L));
    expectedResults.get(0).put(indirectLt, ScaleTwoDecimal.ZERO);
    expectedResults.get(0).put(directGt, new ScaleTwoDecimal(125000L));
    expectedResults.get(0).put(directLt, new ScaleTwoDecimal(25000L));

    expectedResults.get(1).put(indirectGt, new ScaleTwoDecimal(75000L));
    expectedResults.get(1).put(indirectLt, ScaleTwoDecimal.ZERO);
    expectedResults.get(1).put(directGt, new ScaleTwoDecimal(150000L));
    expectedResults.get(1).put(directLt, ScaleTwoDecimal.ZERO);
    service.generateSubAwardLineItems(subAward, budget);

    BudgetPeriod period = budget.getBudgetPeriods().get(0);
    Assert.assertTrue(period.getBudgetLineItems().size() == 4);
    List<BudgetLineItem> lineItemsFoundForDirectGt =
        findLineItemsByCostElement(period.getBudgetLineItems(), directGt);
    Assert.assertTrue(lineItemsFoundForDirectGt.size() == 2);
    ScaleTwoDecimal totalDirectCost =
        lineItemsFoundForDirectGt
            .get(0)
            .getLineItemCost()
            .add(lineItemsFoundForDirectGt.get(1).getLineItemCost());
    Assert.assertTrue(totalDirectCost.compareTo(new ScaleTwoDecimal(125000L)) == 0);
    ScaleTwoDecimal totalCostSharing =
        lineItemsFoundForDirectGt
            .get(0)
            .getCostSharingAmount()
            .add(lineItemsFoundForDirectGt.get(1).getCostSharingAmount());
    Assert.assertTrue(totalCostSharing.compareTo(new ScaleTwoDecimal(1000L)) == 0);
    List<BudgetLineItem> lineItemsFound =
        findLineItemsByCostElement(period.getBudgetLineItems(), directLt);
    Assert.assertTrue(
        lineItemsFound.get(0).getLineItemCost().compareTo(new ScaleTwoDecimal(25000L)) == 0);
    lineItemsFound = findLineItemsByCostElement(period.getBudgetLineItems(), indirectGt);
    Assert.assertTrue(
        lineItemsFound.get(0).getLineItemCost().compareTo(new ScaleTwoDecimal(75000L)) == 0);
    lineItemsFound = findLineItemsByCostElement(period.getBudgetLineItems(), indirectLt);
    Assert.assertTrue(lineItemsFound.size() == 0);

    period = budget.getBudgetPeriods().get(1);
    Assert.assertTrue(period.getBudgetLineItems().size() == 3);
    lineItemsFoundForDirectGt = findLineItemsByCostElement(period.getBudgetLineItems(), directGt);
    Assert.assertTrue(lineItemsFoundForDirectGt.size() == 2);
    totalDirectCost =
        lineItemsFoundForDirectGt
            .get(0)
            .getLineItemCost()
            .add(lineItemsFoundForDirectGt.get(1).getLineItemCost());
    Assert.assertTrue(totalDirectCost.compareTo(new ScaleTwoDecimal(150000L)) == 0);
    totalCostSharing =
        lineItemsFoundForDirectGt
            .get(0)
            .getCostSharingAmount()
            .add(lineItemsFoundForDirectGt.get(1).getCostSharingAmount());
    Assert.assertTrue(totalCostSharing.compareTo(new ScaleTwoDecimal(1000L)) == 0);
    lineItemsFound = findLineItemsByCostElement(period.getBudgetLineItems(), directLt);
    Assert.assertTrue(lineItemsFound.size() == 0);
    lineItemsFound = findLineItemsByCostElement(period.getBudgetLineItems(), indirectGt);
    Assert.assertTrue(
        lineItemsFound.get(0).getLineItemCost().compareTo(new ScaleTwoDecimal(75000L)) == 0);
    lineItemsFound = findLineItemsByCostElement(period.getBudgetLineItems(), indirectLt);
    Assert.assertTrue(lineItemsFound.size() == 0);
  }