Search in sources :

Example 11 with RequestEntry

use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.

the class OrderService method getOrderInvoiceRelationshipByOrderIdAndInvoiceId.

public CompletableFuture<OrderInvoiceRelationshipCollection> getOrderInvoiceRelationshipByOrderIdAndInvoiceId(String orderId, String invoiceId, RequestContext requestContext) {
    String query = String.format(ORDER_INVOICE_RELATIONSHIP_QUERY, orderId, invoiceId);
    RequestEntry requestEntry = new RequestEntry(ORDER_INVOICE_RELATIONSHIPS_ENDPOINT).withQuery(query).withOffset(0).withLimit(100);
    return restClient.get(requestEntry, requestContext, OrderInvoiceRelationshipCollection.class);
}
Also used : RequestEntry(org.folio.rest.core.models.RequestEntry)

Example 12 with RequestEntry

use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.

the class RestClientTest method testPostShouldCreateEntity.

@Test
public void testPostShouldCreateEntity() throws Exception {
    RestClient restClient = Mockito.spy(new RestClient());
    String uuid = UUID.randomUUID().toString();
    Transaction expTransaction = new Transaction().withId(uuid);
    Response response = new Response();
    response.setBody(JsonObject.mapFrom(expTransaction));
    response.setCode(201);
    RequestEntry requestEntry = new RequestEntry(resourcesPath(FINANCE_STORAGE_TRANSACTIONS));
    doReturn(httpClient).when(restClient).getHttpClient(okapiHeaders);
    doReturn(completedFuture(response)).when(httpClient).request(eq(HttpMethod.POST), any(), eq(resourcesPath(FINANCE_STORAGE_TRANSACTIONS)), eq(okapiHeaders));
    Transaction actTransaction = restClient.post(requestEntry, expTransaction, requestContext, Transaction.class).join();
    assertThat(actTransaction, equalTo(expTransaction));
}
Also used : Response(org.folio.rest.tools.client.Response) Transaction(org.folio.rest.acq.model.finance.Transaction) RequestEntry(org.folio.rest.core.models.RequestEntry) Test(org.junit.jupiter.api.Test)

Example 13 with RequestEntry

use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.

the class RestClientTest method testDeleteShouldCreateEntity.

@Test
public void testDeleteShouldCreateEntity() throws Exception {
    RestClient restClient = Mockito.spy(new RestClient());
    String uuid = UUID.randomUUID().toString();
    Response response = new Response();
    response.setCode(204);
    doReturn(httpClient).when(restClient).getHttpClient(okapiHeaders);
    String endpoint = resourcesPath(FINANCE_STORAGE_TRANSACTIONS) + "/" + uuid;
    RequestEntry requestEntry = new RequestEntry(resourcesPath(FINANCE_STORAGE_TRANSACTIONS) + "/{id}").withId(uuid);
    doReturn(completedFuture(response)).when(httpClient).request(eq(HttpMethod.DELETE), eq(endpoint), eq(okapiHeaders));
    restClient.delete(requestEntry, requestContext).get();
    verify(httpClient).request(eq(HttpMethod.DELETE), eq(endpoint), eq(okapiHeaders));
}
Also used : Response(org.folio.rest.tools.client.Response) RequestEntry(org.folio.rest.core.models.RequestEntry) Test(org.junit.jupiter.api.Test)

Example 14 with RequestEntry

use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.

the class RestClientTest method testGetShouldSearchById.

@Test
public void testGetShouldSearchById() throws Exception {
    RestClient restClient = Mockito.spy(new RestClient());
    String uuid = UUID.randomUUID().toString();
    String endpoint = resourcesPath(FINANCE_STORAGE_TRANSACTIONS) + "/" + uuid;
    Transaction expTransaction = new Transaction().withId(uuid);
    Response response = new Response();
    response.setBody(JsonObject.mapFrom(expTransaction));
    response.setCode(200);
    doReturn(httpClient).when(restClient).getHttpClient(okapiHeaders);
    doReturn(completedFuture(response)).when(httpClient).request(HttpMethod.GET, endpoint, okapiHeaders);
    RequestEntry requestEntry = new RequestEntry(resourcesPath(FINANCE_STORAGE_TRANSACTIONS) + "/{id}").withId(uuid);
    Transaction actTransaction = restClient.get(requestEntry, requestContext, Transaction.class).join();
    assertThat(actTransaction, equalTo(expTransaction));
}
Also used : Response(org.folio.rest.tools.client.Response) Transaction(org.folio.rest.acq.model.finance.Transaction) RequestEntry(org.folio.rest.core.models.RequestEntry) Test(org.junit.jupiter.api.Test)

Example 15 with RequestEntry

use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.

the class ConfigurationService method loadConfiguration.

public CompletableFuture<JsonObject> loadConfiguration(String moduleConfig, RequestContext requestContext) {
    String query = String.format(CONFIG_QUERY, moduleConfig);
    RequestEntry requestEntry = new RequestEntry(CONFIGURATION_ENDPOINT).withQuery(query).withOffset(0).withLimit(Integer.MAX_VALUE);
    logger.info("GET request: {}", query);
    return restClient.get(requestEntry, requestContext, Configs.class).thenApply(configs -> {
        if (logger.isDebugEnabled()) {
            logger.debug("The response from mod-configuration: {}", JsonObject.mapFrom(configs).encodePrettily());
        }
        JsonObject config = new JsonObject();
        configs.getConfigs().forEach(entry -> config.put(entry.getConfigName(), entry.getValue()));
        return config;
    });
}
Also used : Configs(org.folio.rest.jaxrs.model.Configs) JsonObject(io.vertx.core.json.JsonObject) RequestEntry(org.folio.rest.core.models.RequestEntry)

Aggregations

RequestEntry (org.folio.rest.core.models.RequestEntry)96 JsonObject (io.vertx.core.json.JsonObject)38 CompletableFuture (java.util.concurrent.CompletableFuture)37 RequestContext (org.folio.rest.core.models.RequestContext)33 Test (org.junit.jupiter.api.Test)30 Collections (java.util.Collections)22 List (java.util.List)21 RestClient (org.folio.rest.core.RestClient)21 LogManager (org.apache.logging.log4j.LogManager)20 Logger (org.apache.logging.log4j.Logger)20 Map (java.util.Map)19 CompletionException (java.util.concurrent.CompletionException)19 Transaction (org.folio.rest.acq.model.finance.Transaction)18 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)17 Collectors.toList (java.util.stream.Collectors.toList)16 TenantTool (org.folio.rest.tools.utils.TenantTool)16 Collections.singletonList (java.util.Collections.singletonList)14 UUID (java.util.UUID)14 Collectors.joining (java.util.stream.Collectors.joining)14 Vertx (io.vertx.core.Vertx)13