Search in sources :

Example 1 with ID_FOR_INTERNAL_SERVER_ERROR

use of org.folio.rest.impl.ApiTestBase.ID_FOR_INTERNAL_SERVER_ERROR 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());
    }
}
Also used : BAD_QUERY(org.folio.rest.impl.InvoicesApiTest.BAD_QUERY) HttpServer(io.vertx.core.http.HttpServer) Header(io.restassured.http.Header) HashBasedTable(com.google.common.collect.HashBasedTable) StringUtils(org.apache.commons.lang3.StringUtils) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) CompositePurchaseOrder(org.folio.rest.acq.model.orders.CompositePurchaseOrder) VoucherLine(org.folio.rest.acq.model.VoucherLine) ExpenseClass(org.folio.rest.acq.model.finance.ExpenseClass) Voucher(org.folio.rest.jaxrs.model.Voucher) Matcher(java.util.regex.Matcher) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) VOUCHER_NUMBER_VALUE(org.folio.rest.impl.ApiTestBase.VOUCHER_NUMBER_VALUE) JsonObject(io.vertx.core.json.JsonObject) VOUCHERS_LIST_PATH(org.folio.rest.impl.VouchersApiTest.VOUCHERS_LIST_PATH) EXISTING_VENDOR_INV_NO(org.folio.rest.impl.InvoicesApiTest.EXISTING_VENDOR_INV_NO) ID_FOR_INTERNAL_SERVER_ERROR(org.folio.rest.impl.ApiTestBase.ID_FOR_INTERNAL_SERVER_ERROR) Budget(org.folio.rest.acq.model.finance.Budget) INVOICE_LINES_MOCK_DATA_PATH(org.folio.rest.impl.InvoiceLinesApiTest.INVOICE_LINES_MOCK_DATA_PATH) BatchVoucherExport(org.folio.rest.jaxrs.model.BatchVoucherExport) INVOICE_CONFIG_MODULE_NAME(org.folio.rest.impl.InvoiceHelper.INVOICE_CONFIG_MODULE_NAME) CompositePoLine(org.folio.rest.acq.model.orders.CompositePoLine) Ledger(org.folio.rest.acq.model.finance.Ledger) Fund(org.folio.rest.acq.model.finance.Fund) Logger(org.apache.logging.log4j.Logger) OrderInvoiceRelationshipCollection(org.folio.rest.acq.model.orders.OrderInvoiceRelationshipCollection) ID_FOR_INTERNAL_SERVER_ERROR_PUT(org.folio.rest.impl.ApiTestBase.ID_FOR_INTERNAL_SERVER_ERROR_PUT) INVOICE_MOCK_DATA_PATH(org.folio.rest.impl.InvoicesApiTest.INVOICE_MOCK_DATA_PATH) ApiTestBase.getMockData(org.folio.rest.impl.ApiTestBase.getMockData) CONFIGURATION_ID(org.folio.rest.impl.BatchVoucherExportConfigCredentialsTest.CONFIGURATION_ID) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) Invoice(org.folio.rest.jaxrs.model.Invoice) SYSTEM_CONFIG_MODULE_NAME(org.folio.rest.impl.InvoiceHelper.SYSTEM_CONFIG_MODULE_NAME) FOLIO_INVOICE_NUMBER_VALUE(org.folio.rest.impl.ApiTestBase.FOLIO_INVOICE_NUMBER_VALUE) ALL_UNITS_CQL(org.folio.invoices.utils.HelperUtils.ALL_UNITS_CQL) ExportConfig(org.folio.rest.jaxrs.model.ExportConfig) IS_DELETED_PROP(org.folio.invoices.utils.HelperUtils.IS_DELETED_PROP) BATCH_VOUCHER_EXPORTS_LIST_PATH(org.folio.rest.impl.BatchVoucherExportsApiTest.BATCH_VOUCHER_EXPORTS_LIST_PATH) Transaction(org.folio.rest.acq.model.finance.Transaction) Supplier(java.util.function.Supplier) BudgetCollection(org.folio.rest.acq.model.finance.BudgetCollection) ArrayList(java.util.ArrayList) BATCH_VOUCHER_EXPORTS_MOCK_DATA_PATH(org.folio.rest.impl.BatchVoucherExportsApiTest.BATCH_VOUCHER_EXPORTS_MOCK_DATA_PATH) InvoiceLineCollection(org.folio.rest.jaxrs.model.InvoiceLineCollection) BatchVoucher(org.folio.rest.jaxrs.model.BatchVoucher) ExchangeRate(org.folio.rest.acq.model.finance.ExchangeRate) ExpenseClassCollection(org.folio.rest.acq.model.finance.ExpenseClassCollection) VOUCHER_MOCK_DATA_PATH(org.folio.rest.impl.VouchersApiTest.VOUCHER_MOCK_DATA_PATH) VOUCHER_LINES_MOCK_DATA_PATH(org.folio.rest.impl.VoucherLinesApiTest.VOUCHER_LINES_MOCK_DATA_PATH) VoucherLineCollection(org.folio.rest.acq.model.VoucherLineCollection) INTERNAL_SERVER_ERROR(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR) InvoiceDocument(org.folio.rest.jaxrs.model.InvoiceDocument) AcquisitionsUnit(org.folio.rest.acq.model.units.AcquisitionsUnit) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) CompositeFund(org.folio.rest.acq.model.finance.CompositeFund) ExecutionException(java.util.concurrent.ExecutionException) DAYS(java.time.temporal.ChronoUnit.DAYS) BudgetExpenseClassCollection(org.folio.rest.acq.model.finance.BudgetExpenseClassCollection) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) BATCH_VOUCHER_EXPORT_CONFIGS_SAMPLE_PATH(org.folio.rest.impl.BatchVoucherExportConfigTest.BATCH_VOUCHER_EXPORT_CONFIGS_SAMPLE_PATH) AcquisitionsUnitCollection(org.folio.rest.acq.model.units.AcquisitionsUnitCollection) BASE_MOCK_DATA_PATH(org.folio.rest.impl.ApiTestBase.BASE_MOCK_DATA_PATH) BATCH_VOUCHER_EXPORT_CONFIG_CREDENTIALS_SAMPLE_PATH_WITH_ID(org.folio.rest.impl.BatchVoucherExportConfigCredentialsTest.BATCH_VOUCHER_EXPORT_CONFIG_CREDENTIALS_SAMPLE_PATH_WITH_ID) VOUCHER_NUMBER_PREFIX_CONFIG(org.folio.services.voucher.VoucherCommandService.VOUCHER_NUMBER_PREFIX_CONFIG) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException) Router(io.vertx.ext.web.Router) LOCALE_SETTINGS(org.folio.rest.impl.InvoiceHelper.LOCALE_SETTINGS) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) SequenceNumber(org.folio.rest.acq.model.SequenceNumber) APPLICATION_XML(javax.ws.rs.core.MediaType.APPLICATION_XML) FUND_ID_WITH_NOT_ACTIVE_BUDGET(org.folio.rest.impl.InvoicesApiTest.FUND_ID_WITH_NOT_ACTIVE_BUDGET) DocumentCollection(org.folio.rest.jaxrs.model.DocumentCollection) BATCH_VOUCHER_EXPORT_CONFIG_BAD_CREDENTIALS_SAMPLE_PATH_WITH_ID(org.folio.rest.impl.BatchVoucherExportConfigCredentialsTest.BATCH_VOUCHER_EXPORT_CONFIG_BAD_CREDENTIALS_SAMPLE_PATH_WITH_ID) BatchVoucherExportCollection(org.folio.rest.jaxrs.model.BatchVoucherExportCollection) INVOICE_SAMPLE_DOCUMENTS_PATH(org.folio.rest.impl.DocumentsApiTest.INVOICE_SAMPLE_DOCUMENTS_PATH) Assert.fail(org.junit.Assert.fail) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) BATCH_GROUPS_LIST_PATH(org.folio.rest.impl.BatchGroupsApiTest.BATCH_GROUPS_LIST_PATH) EXPENSE_CLASSES_LIST_PATH(org.folio.rest.impl.InvoicesApiTest.EXPENSE_CLASSES_LIST_PATH) InvoiceCollection(org.folio.rest.jaxrs.model.InvoiceCollection) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) INVOICE_LINE_NUMBER_VALUE(org.folio.rest.impl.ApiTestBase.INVOICE_LINE_NUMBER_VALUE) HttpHeaders(io.vertx.core.http.HttpHeaders) PROTECTED_READ_ONLY_TENANT(org.folio.rest.impl.ApiTestBase.PROTECTED_READ_ONLY_TENANT) UUID(java.util.UUID) Instant(java.time.Instant) BatchGroup(org.folio.rest.acq.model.BatchGroup) INVOICE_DOCUMENTS_SAMPLE_PATH(org.folio.rest.impl.DocumentsApiTest.INVOICE_DOCUMENTS_SAMPLE_PATH) List(java.util.List) FiscalYearCollection(org.folio.rest.acq.model.finance.FiscalYearCollection) Response(javax.ws.rs.core.Response) AcquisitionsUnitMembershipCollection(org.folio.rest.acq.model.units.AcquisitionsUnitMembershipCollection) StreamEx(one.util.streamex.StreamEx) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) UserAccount(org.mockftpserver.fake.UserAccount) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) Json(io.vertx.core.json.Json) Credentials(org.folio.rest.jaxrs.model.Credentials) Document(org.folio.rest.jaxrs.model.Document) OKAPI_HEADER_TENANT(org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) VoucherCollection(org.folio.rest.jaxrs.model.VoucherCollection) Function(java.util.function.Function) LedgerCollection(org.folio.rest.acq.model.finance.LedgerCollection) ExportConfigCollection(org.folio.rest.jaxrs.model.ExportConfigCollection) EXISTING_LEDGER_ID(org.folio.rest.impl.InvoicesApiTest.EXISTING_LEDGER_ID) EMPTY(org.apache.commons.lang3.StringUtils.EMPTY) VOUCHER_NUMBER_CONFIG_NAME(org.folio.services.voucher.VoucherCommandService.VOUCHER_NUMBER_CONFIG_NAME) Config(org.folio.rest.jaxrs.model.Config) ACQUISITIONS_UNIT_ID(org.folio.rest.impl.ProtectionHelper.ACQUISITIONS_UNIT_ID) BATCH_GROUP_MOCK_DATA_PATH(org.folio.rest.impl.BatchGroupsApiTest.BATCH_GROUP_MOCK_DATA_PATH) BATCH_VOUCHER_MOCK_DATA_PATH(org.folio.rest.impl.BatchVoucherImplTest.BATCH_VOUCHER_MOCK_DATA_PATH) Configs(org.folio.rest.jaxrs.model.Configs) ID_DOES_NOT_EXIST(org.folio.rest.impl.ApiTestBase.ID_DOES_NOT_EXIST) EXPENSE_CLASSES_MOCK_DATA_PATH(org.folio.rest.impl.InvoicesApiTest.EXPENSE_CLASSES_MOCK_DATA_PATH) Iterator(java.util.Iterator) ResourcePathResolver(org.folio.invoices.utils.ResourcePathResolver) DirectoryEntry(org.mockftpserver.fake.filesystem.DirectoryEntry) BatchGroupCollection(org.folio.rest.acq.model.BatchGroupCollection) INVOICE_ID(org.folio.invoices.utils.HelperUtils.INVOICE_ID) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) HttpMethod(io.vertx.core.http.HttpMethod) QUERY_PARAM_START_WITH(org.folio.invoices.utils.HelperUtils.QUERY_PARAM_START_WITH) HttpStatus(org.folio.HttpStatus) FundCollection(org.folio.rest.acq.model.finance.FundCollection) Collections(java.util.Collections) Table(com.google.common.collect.Table) LogManager(org.apache.logging.log4j.LogManager) BATCH_VOUCHER_EXPORT_CONFIG_SAMPLE_PATH(org.folio.rest.impl.BatchVoucherExportConfigTest.BATCH_VOUCHER_EXPORT_CONFIG_SAMPLE_PATH) JsonObject(io.vertx.core.json.JsonObject) Supplier(java.util.function.Supplier) IOException(java.io.IOException) BudgetExpenseClassCollection(org.folio.rest.acq.model.finance.BudgetExpenseClassCollection)

Aggregations

HashBasedTable (com.google.common.collect.HashBasedTable)1 Table (com.google.common.collect.Table)1 Header (io.restassured.http.Header)1 Vertx (io.vertx.core.Vertx)1 HttpHeaders (io.vertx.core.http.HttpHeaders)1 HttpMethod (io.vertx.core.http.HttpMethod)1 HttpServer (io.vertx.core.http.HttpServer)1 Json (io.vertx.core.json.Json)1 JsonObject (io.vertx.core.json.JsonObject)1 Router (io.vertx.ext.web.Router)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 BodyHandler (io.vertx.ext.web.handler.BodyHandler)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1 DAYS (java.time.temporal.ChronoUnit.DAYS)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1