Search in sources :

Example 6 with ExpenseClass

use of org.folio.rest.acq.model.finance.ExpenseClass in project mod-invoice by folio-org.

the class BudgetExpenseClassTest method shouldThrowExceptionWithInactiveExpenseClassCodeWhenCheckExpenseClassesWithInactiveExpenseClass.

@Test
void shouldThrowExceptionWithInactiveExpenseClassCodeWhenCheckExpenseClassesWithInactiveExpenseClass() {
    String inactiveExpenseClassId = UUID.randomUUID().toString();
    String activeExpenseClassId = UUID.randomUUID().toString();
    FundDistribution fundDistributionWithInactiveExpenseClass = new FundDistribution().withFundId(UUID.randomUUID().toString()).withExpenseClassId(inactiveExpenseClassId);
    FundDistribution fundDistributionWithActiveExpenseClass = new FundDistribution().withFundId(UUID.randomUUID().toString()).withExpenseClassId(activeExpenseClassId);
    FundDistribution fundDistributionWithoutExpenseClass = new FundDistribution().withFundId(UUID.randomUUID().toString());
    InvoiceLine invoiceLine = new InvoiceLine().withFundDistributions(Arrays.asList(fundDistributionWithInactiveExpenseClass, fundDistributionWithoutExpenseClass));
    List<InvoiceLine> invoiceLines = Collections.singletonList(invoiceLine);
    Adjustment adjustment = new Adjustment().withFundDistributions(Collections.singletonList(fundDistributionWithActiveExpenseClass));
    Invoice invoice = new Invoice().withAdjustments(Collections.singletonList(adjustment));
    BudgetExpenseClass active = new BudgetExpenseClass().withBudgetId(UUID.randomUUID().toString()).withExpenseClassId(activeExpenseClassId).withStatus(BudgetExpenseClass.Status.ACTIVE).withId(UUID.randomUUID().toString());
    BudgetExpenseClass inactive = new BudgetExpenseClass().withBudgetId(UUID.randomUUID().toString()).withExpenseClassId(inactiveExpenseClassId).withStatus(BudgetExpenseClass.Status.INACTIVE).withId(UUID.randomUUID().toString());
    Fund inactiveExpenseClassFund = new Fund().withCode("inactive fund");
    ExpenseClass inactiveExpenseClass = new ExpenseClass().withName("inactive class");
    List<InvoiceWorkflowDataHolder> holders = new ArrayList<>();
    InvoiceWorkflowDataHolder holder1 = new InvoiceWorkflowDataHolder().withInvoice(invoice).withInvoiceLine(invoiceLine).withFundDistribution(fundDistributionWithInactiveExpenseClass).withExpenseClass(inactiveExpenseClass).withBudget(new Budget().withFundId(UUID.randomUUID().toString())).withFund(inactiveExpenseClassFund);
    InvoiceWorkflowDataHolder holder2 = new InvoiceWorkflowDataHolder().withInvoice(invoice).withInvoiceLine(invoiceLine).withBudget(new Budget().withFundId(UUID.randomUUID().toString())).withFundDistribution(fundDistributionWithoutExpenseClass);
    InvoiceWorkflowDataHolder holder3 = new InvoiceWorkflowDataHolder().withInvoice(invoice).withAdjustment(adjustment).withFundDistribution(fundDistributionWithActiveExpenseClass).withBudget(new Budget().withFundId(UUID.randomUUID().toString())).withExpenseClass(new ExpenseClass().withId(activeExpenseClassId));
    holders.add(holder1);
    holders.add(holder2);
    holders.add(holder3);
    when(restClient.get(any(RequestEntry.class), any(), any())).thenAnswer(invocation -> {
        RequestEntry requestEntry = invocation.getArgument(0);
        BudgetExpenseClass bec = requestEntry.buildEndpoint().contains(activeExpenseClassId) ? active : inactive;
        return CompletableFuture.completedFuture(new BudgetExpenseClassCollection().withBudgetExpenseClasses(Collections.singletonList(bec)).withTotalRecords(1));
    });
    when(requestContext.getContext()).thenReturn(Vertx.vertx().getOrCreateContext());
    CompletableFuture<List<InvoiceWorkflowDataHolder>> future = budgetExpenseClassService.checkExpenseClasses(holders, requestContext);
    ExecutionException executionException = assertThrows(ExecutionException.class, future::get);
    assertThat(executionException.getCause(), instanceOf(HttpException.class));
    HttpException exception = (HttpException) executionException.getCause();
    assertEquals(400, exception.getCode());
    Errors errors = exception.getErrors();
    Error error = errors.getErrors().get(0);
    assertEquals(INACTIVE_EXPENSE_CLASS.getCode(), error.getCode());
    String expenseClassNameFromError = error.getParameters().stream().filter(parameter -> parameter.getKey().equals(EXPENSE_CLASS_NAME)).findFirst().get().getValue();
    assertEquals(inactiveExpenseClass.getName(), expenseClassNameFromError);
    String fundCodeFromError = error.getParameters().stream().filter(parameter -> parameter.getKey().equals(FUND_CODE)).findFirst().get().getValue();
    assertEquals(inactiveExpenseClassFund.getCode(), fundCodeFromError);
}
Also used : ExpenseClass(org.folio.rest.acq.model.finance.ExpenseClass) BudgetExpenseClass(org.folio.rest.acq.model.finance.BudgetExpenseClass) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RestClient(org.folio.rest.core.RestClient) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Mock(org.mockito.Mock) CompletableFuture(java.util.concurrent.CompletableFuture) InvoiceWorkflowDataHolder(org.folio.models.InvoiceWorkflowDataHolder) ArrayList(java.util.ArrayList) HttpException(org.folio.invoices.rest.exceptions.HttpException) MockitoAnnotations(org.mockito.MockitoAnnotations) ExpenseClass(org.folio.rest.acq.model.finance.ExpenseClass) FUND_CODE(org.folio.services.finance.budget.BudgetExpenseClassService.FUND_CODE) BudgetExpenseClass(org.folio.rest.acq.model.finance.BudgetExpenseClass) RequestContext(org.folio.rest.core.models.RequestContext) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Errors(org.folio.rest.jaxrs.model.Errors) Budget(org.folio.rest.acq.model.finance.Budget) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) INACTIVE_EXPENSE_CLASS(org.folio.invoices.utils.ErrorCodes.INACTIVE_EXPENSE_CLASS) BudgetExpenseClassService(org.folio.services.finance.budget.BudgetExpenseClassService) Vertx(io.vertx.core.Vertx) RequestEntry(org.folio.rest.core.models.RequestEntry) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) Fund(org.folio.rest.acq.model.finance.Fund) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) Error(org.folio.rest.jaxrs.model.Error) List(java.util.List) BudgetExpenseClassCollection(org.folio.rest.acq.model.finance.BudgetExpenseClassCollection) EXPENSE_CLASS_NAME(org.folio.services.finance.budget.BudgetExpenseClassService.EXPENSE_CLASS_NAME) Adjustment(org.folio.rest.jaxrs.model.Adjustment) BUDGET_EXPENSE_CLASS_NOT_FOUND(org.folio.invoices.utils.ErrorCodes.BUDGET_EXPENSE_CLASS_NOT_FOUND) Collections(java.util.Collections) Invoice(org.folio.rest.jaxrs.model.Invoice) Invoice(org.folio.rest.jaxrs.model.Invoice) Adjustment(org.folio.rest.jaxrs.model.Adjustment) BudgetExpenseClass(org.folio.rest.acq.model.finance.BudgetExpenseClass) Fund(org.folio.rest.acq.model.finance.Fund) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) ArrayList(java.util.ArrayList) Error(org.folio.rest.jaxrs.model.Error) RequestEntry(org.folio.rest.core.models.RequestEntry) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Errors(org.folio.rest.jaxrs.model.Errors) InvoiceWorkflowDataHolder(org.folio.models.InvoiceWorkflowDataHolder) Budget(org.folio.rest.acq.model.finance.Budget) ArrayList(java.util.ArrayList) List(java.util.List) HttpException(org.folio.invoices.rest.exceptions.HttpException) ExecutionException(java.util.concurrent.ExecutionException) BudgetExpenseClassCollection(org.folio.rest.acq.model.finance.BudgetExpenseClassCollection) Test(org.junit.jupiter.api.Test)

Example 7 with ExpenseClass

use of org.folio.rest.acq.model.finance.ExpenseClass in project mod-invoice by folio-org.

the class BudgetExpenseClassService method getFundIdExpenseClassIdParameters.

private List<Parameter> getFundIdExpenseClassIdParameters(InvoiceWorkflowDataHolder holder) {
    Fund fund = holder.getFund();
    ExpenseClass expenseClass = holder.getExpenseClass();
    return Arrays.asList(new Parameter().withKey(FUND_CODE).withValue(fund.getCode()), new Parameter().withKey(EXPENSE_CLASS_NAME).withValue(expenseClass.getName()));
}
Also used : ExpenseClass(org.folio.rest.acq.model.finance.ExpenseClass) BudgetExpenseClass(org.folio.rest.acq.model.finance.BudgetExpenseClass) Fund(org.folio.rest.acq.model.finance.Fund) Parameter(org.folio.rest.jaxrs.model.Parameter)

Aggregations

ExpenseClass (org.folio.rest.acq.model.finance.ExpenseClass)7 HttpException (org.folio.invoices.rest.exceptions.HttpException)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 BudgetExpenseClass (org.folio.rest.acq.model.finance.BudgetExpenseClass)3 BudgetExpenseClassCollection (org.folio.rest.acq.model.finance.BudgetExpenseClassCollection)3 Fund (org.folio.rest.acq.model.finance.Fund)3 RequestEntry (org.folio.rest.core.models.RequestEntry)3 Error (org.folio.rest.jaxrs.model.Error)3 Errors (org.folio.rest.jaxrs.model.Errors)3 Vertx (io.vertx.core.Vertx)2 JsonObject (io.vertx.core.json.JsonObject)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 UUID (java.util.UUID)2 BUDGET_EXPENSE_CLASS_NOT_FOUND (org.folio.invoices.utils.ErrorCodes.BUDGET_EXPENSE_CLASS_NOT_FOUND)2 INACTIVE_EXPENSE_CLASS (org.folio.invoices.utils.ErrorCodes.INACTIVE_EXPENSE_CLASS)2 InvoiceWorkflowDataHolder (org.folio.models.InvoiceWorkflowDataHolder)2