use of org.folio.rest.acq.model.finance.BudgetExpenseClassCollection in project mod-invoice by folio-org.
the class BudgetExpenseClassTest method shouldThrowExceptionWithBudgetExpenseClassNotFoundCodeWhenCheckExpenseClassesWithoutExpenseClasses.
@Test
void shouldThrowExceptionWithBudgetExpenseClassNotFoundCodeWhenCheckExpenseClassesWithoutExpenseClasses() {
String notAssignedExpenseClassId = UUID.randomUUID().toString();
String activeExpenseClassId = UUID.randomUUID().toString();
FundDistribution fundDistributionWithActiveExpenseClass = new FundDistribution().withFundId(UUID.randomUUID().toString()).withExpenseClassId(activeExpenseClassId);
FundDistribution fundDistributionWithNotAssignedExpenseClass = new FundDistribution().withFundId(UUID.randomUUID().toString()).withExpenseClassId(notAssignedExpenseClassId);
FundDistribution fundDistributionWithoutExpenseClass = new FundDistribution().withFundId(UUID.randomUUID().toString());
InvoiceLine invoiceLine = new InvoiceLine().withFundDistributions(Arrays.asList(fundDistributionWithActiveExpenseClass, fundDistributionWithoutExpenseClass));
List<InvoiceLine> invoiceLines = Collections.singletonList(invoiceLine);
Adjustment adjustment = new Adjustment().withFundDistributions(Collections.singletonList(fundDistributionWithNotAssignedExpenseClass));
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());
Fund noExpenseClassFund = new Fund().withCode("no expense class fund");
ExpenseClass notAssignedExpenseClass = new ExpenseClass().withName("not assigned class");
List<InvoiceWorkflowDataHolder> holders = new ArrayList<>();
InvoiceWorkflowDataHolder holder1 = new InvoiceWorkflowDataHolder().withInvoice(invoice).withInvoiceLine(invoiceLine).withFundDistribution(fundDistributionWithActiveExpenseClass).withBudget(new Budget().withFundId(UUID.randomUUID().toString())).withExpenseClass(new ExpenseClass().withId(activeExpenseClassId));
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(fundDistributionWithNotAssignedExpenseClass).withExpenseClass(notAssignedExpenseClass).withBudget(new Budget().withFundId(UUID.randomUUID().toString())).withFund(noExpenseClassFund);
holders.add(holder1);
holders.add(holder2);
holders.add(holder3);
when(restClient.get(any(RequestEntry.class), any(), any())).thenAnswer(invocation -> {
RequestEntry requestEntry = invocation.getArgument(0);
List<BudgetExpenseClass> budgetExpenseClasses = requestEntry.buildEndpoint().contains(notAssignedExpenseClassId) ? Collections.emptyList() : Collections.singletonList(active);
return CompletableFuture.completedFuture(new BudgetExpenseClassCollection().withBudgetExpenseClasses(budgetExpenseClasses).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(BUDGET_EXPENSE_CLASS_NOT_FOUND.getCode(), error.getCode());
String expenseClassNameFromError = error.getParameters().stream().filter(parameter -> parameter.getKey().equals(EXPENSE_CLASS_NAME)).findFirst().get().getValue();
assertEquals(notAssignedExpenseClass.getName(), expenseClassNameFromError);
String fundCodeFromError = error.getParameters().stream().filter(parameter -> parameter.getKey().equals(FUND_CODE)).findFirst().get().getValue();
assertEquals(noExpenseClassFund.getCode(), fundCodeFromError);
}
use of org.folio.rest.acq.model.finance.BudgetExpenseClassCollection in project mod-orders by folio-org.
the class MockServer method handleGetBudgetExpenseClass.
private void handleGetBudgetExpenseClass(RoutingContext ctx) {
logger.info("handleGetBudgetExpenseClass: " + ctx.request().path());
try {
BudgetExpenseClassCollection expenseClassCollection = new JsonObject(getMockData(BUDGET_EXPENSE_CLASSES_MOCK_DATA_PATH)).mapTo(BudgetExpenseClassCollection.class);
JsonObject entries = JsonObject.mapFrom(expenseClassCollection);
serverResponse(ctx, 200, APPLICATION_JSON, entries.encodePrettily());
} catch (IOException exception) {
serverResponse(ctx, 500, APPLICATION_JSON, INTERNAL_SERVER_ERROR.getReasonPhrase());
}
}
use of org.folio.rest.acq.model.finance.BudgetExpenseClassCollection in project mod-invoice by folio-org.
the class MockServer method handleGetBudgetExpenseClass.
private void handleGetBudgetExpenseClass(RoutingContext ctx) {
logger.info("handle BudgetExpenseClasses got: {}?{}", ctx.request().path(), ctx.request().query());
String tenant = ctx.request().getHeader(OKAPI_HEADER_TENANT);
String queryParam = StringUtils.trimToEmpty(ctx.request().getParam(QUERY));
addServerRqQuery(BUDGET_EXPENSE_CLASSES, queryParam);
if (queryParam.contains(BAD_QUERY)) {
serverResponse(ctx, 400, APPLICATION_JSON, Response.Status.BAD_REQUEST.getReasonPhrase());
} else if (queryParam.contains(ID_FOR_INTERNAL_SERVER_ERROR)) {
serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
} else {
// By default return 0
BudgetExpenseClassCollection budgetExpenseClasses = new BudgetExpenseClassCollection().withTotalRecords(0);
if (queryParam.contains(EXPENSE_CLASS_ID)) {
String expenseClassId = queryParam.split(EXPENSE_CLASS_ID + "==")[1];
Supplier<BudgetExpenseClassCollection> getFromFile = () -> {
try {
return new JsonObject(getMockData(BUDGET_EXPENSE_CLASS_COLLECTION)).mapTo(BudgetExpenseClassCollection.class);
} catch (IOException e) {
return new BudgetExpenseClassCollection().withTotalRecords(0);
}
};
budgetExpenseClasses.withBudgetExpenseClasses(getFromFile.get().getBudgetExpenseClasses().stream().filter(bec -> bec.getExpenseClassId().equals(expenseClassId)).collect(toList()));
budgetExpenseClasses.withTotalRecords(budgetExpenseClasses.getBudgetExpenseClasses().size());
}
JsonObject budgetExpenseClassesJson = JsonObject.mapFrom(budgetExpenseClasses);
logger.info(budgetExpenseClassesJson.encodePrettily());
addServerRqRsData(HttpMethod.GET, BUDGET_EXPENSE_CLASSES, budgetExpenseClassesJson);
serverResponse(ctx, 200, APPLICATION_JSON, budgetExpenseClassesJson.encodePrettily());
}
}
use of org.folio.rest.acq.model.finance.BudgetExpenseClassCollection 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);
}
Aggregations