Search in sources :

Example 11 with Response

use of org.folio.inventory.support.http.client.Response in project mod-inventory by folio-org.

the class ItemApiMoveExamples method canMoveToHoldingsRecordWithHoldingSchemasMismatching.

@Test
public void canMoveToHoldingsRecordWithHoldingSchemasMismatching() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException, IllegalAccessException {
    UUID instanceId = UUID.randomUUID();
    InstanceApiClient.createInstance(okapiClient, smallAngryPlanet(instanceId));
    final UUID existedHoldingId = createHoldingForInstance(instanceId);
    final UUID newHoldingId = createNonCompatibleHoldingForInstance(instanceId);
    Assert.assertNotEquals(existedHoldingId, newHoldingId);
    final IndividualResource createItem = itemsClient.create(new ItemRequestBuilder().forHolding(existedHoldingId).withBarcode("645398607547").withStatus(ItemStatusName.AVAILABLE.value()));
    JsonObject itemsMoveRequestBody = new ItemsMoveRequestBuilder(newHoldingId, new JsonArray(Collections.singletonList(createItem.getId()))).create();
    Response postMoveItemsResponse = moveItems(itemsMoveRequestBody);
    assertThat(postMoveItemsResponse.getStatusCode(), is(200));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Response(org.folio.inventory.support.http.client.Response) ItemsMoveRequestBuilder(api.support.builders.ItemsMoveRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 12 with Response

use of org.folio.inventory.support.http.client.Response in project mod-inventory by folio-org.

the class ItemApiMoveExamples method canMoveItemsToDifferentHoldingsRecord.

@Test
public void canMoveItemsToDifferentHoldingsRecord() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID instanceId = UUID.randomUUID();
    InstanceApiClient.createInstance(okapiClient, smallAngryPlanet(instanceId));
    final UUID existedHoldingId = createHoldingForInstance(instanceId);
    final UUID newHoldingId = createHoldingForInstance(instanceId);
    Assert.assertNotEquals(existedHoldingId, newHoldingId);
    final IndividualResource createItem1 = itemsClient.create(new ItemRequestBuilder().forHolding(existedHoldingId).withBarcode("645398607547").withStatus(ItemStatusName.AVAILABLE.value()));
    final IndividualResource createItem2 = itemsClient.create(new ItemRequestBuilder().forHolding(existedHoldingId).withBarcode("645398607546").withStatus(ItemStatusName.AVAILABLE.value()));
    JsonObject itemsMoveRequestBody = new ItemsMoveRequestBuilder(newHoldingId, new JsonArray(Arrays.asList(createItem1.getId(), createItem2.getId()))).create();
    Response postItemsMoveResponse = moveItems(itemsMoveRequestBody);
    assertThat(postItemsMoveResponse.getStatusCode(), is(200));
    assertThat(new JsonObject(postItemsMoveResponse.getBody()).getJsonArray("nonUpdatedIds").size(), is(0));
    assertThat(postItemsMoveResponse.getContentType(), containsString(APPLICATION_JSON));
    JsonObject updatedItem1 = itemsClient.getById(createItem1.getId()).getJson();
    JsonObject updatedItem2 = itemsClient.getById(createItem2.getId()).getJson();
    Assert.assertEquals(newHoldingId.toString(), updatedItem1.getString(HOLDINGS_RECORD_ID));
    Assert.assertEquals(newHoldingId.toString(), updatedItem2.getString(HOLDINGS_RECORD_ID));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Response(org.folio.inventory.support.http.client.Response) ItemsMoveRequestBuilder(api.support.builders.ItemsMoveRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 13 with Response

use of org.folio.inventory.support.http.client.Response in project mod-inventory by folio-org.

the class ItemApiMoveExamples method canMoveItemsDueToItemUpdateError.

@Test
public void canMoveItemsDueToItemUpdateError() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID instanceId = UUID.randomUUID();
    InstanceApiClient.createInstance(okapiClient, smallAngryPlanet(instanceId));
    final UUID existedHoldingId = createHoldingForInstance(instanceId);
    final UUID newHoldingId = createHoldingForInstance(instanceId);
    Assert.assertNotEquals(existedHoldingId, newHoldingId);
    final IndividualResource createItem1 = itemsClient.create(new ItemRequestBuilder().forHolding(existedHoldingId).withBarcode("645398607547").withStatus(ItemStatusName.AVAILABLE.value()));
    final IndividualResource createItem2 = itemsClient.create(new ItemRequestBuilder().forHolding(existedHoldingId).withBarcode("645398607546").withId(ID_FOR_FAILURE).withStatus(ItemStatusName.AVAILABLE.value()));
    JsonObject itemsMoveRequestBody = new ItemsMoveRequestBuilder(newHoldingId, new JsonArray(Arrays.asList(createItem1.getId(), createItem2.getId()))).create();
    Response postItemsMoveResponse = moveItems(itemsMoveRequestBody);
    List nonUpdatedIdsIds = postItemsMoveResponse.getJson().getJsonArray("nonUpdatedIds").getList();
    assertThat(nonUpdatedIdsIds.size(), is(1));
    assertThat(nonUpdatedIdsIds.get(0), equalTo(ID_FOR_FAILURE.toString()));
    assertThat(postItemsMoveResponse.getStatusCode(), is(200));
    assertThat(postItemsMoveResponse.getContentType(), containsString(APPLICATION_JSON));
    JsonObject updatedItem1 = itemsClient.getById(createItem1.getId()).getJson();
    assertThat(newHoldingId.toString(), equalTo(updatedItem1.getString(HOLDINGS_RECORD_ID)));
    JsonObject updatedItem2 = itemsClient.getById(createItem2.getId()).getJson();
    assertThat(existedHoldingId.toString(), equalTo(updatedItem2.getString(HOLDINGS_RECORD_ID)));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Response(org.folio.inventory.support.http.client.Response) ItemsMoveRequestBuilder(api.support.builders.ItemsMoveRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) List(java.util.List) UUID(java.util.UUID) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 14 with Response

use of org.folio.inventory.support.http.client.Response in project mod-inventory by folio-org.

the class IsbnUtilsApiExamples method testIsbnConvertTo10FromIsbn13WithInvalidIsbn.

@Test
public void testIsbnConvertTo10FromIsbn13WithInvalidIsbn() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    final var conversionCompleted = okapiClient.get(ApiRoot.isbnConvertTo10("isbn=97819301109911&hyphens=true"));
    Response conversionResponse = conversionCompleted.toCompletableFuture().get(5, SECONDS);
    checkErrorResponse(conversionResponse, String.format(INVALID_ISBN_MESSAGE, "97819301109911"));
}
Also used : Response(org.folio.inventory.support.http.client.Response) Test(org.junit.Test)

Example 15 with Response

use of org.folio.inventory.support.http.client.Response in project mod-inventory by folio-org.

the class IsbnUtilsApiExamples method verifyValidator.

private void verifyValidator(String isbnParam, boolean isValid) throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    final var validateGetCompleted = okapiClient.get(ApiRoot.isbnValidate(isbnParam));
    Response validateGetResponse = validateGetCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(validateGetResponse.getStatusCode(), is(200));
    JsonObject result = validateGetResponse.getJson();
    assertThat(result.getBoolean(IsbnUtilsApi.IS_VALID), is(isValid));
}
Also used : Response(org.folio.inventory.support.http.client.Response) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

Response (org.folio.inventory.support.http.client.Response)158 Test (org.junit.Test)123 JsonObject (io.vertx.core.json.JsonObject)101 JsonArray (io.vertx.core.json.JsonArray)55 UUID (java.util.UUID)53 IndividualResource (org.folio.inventory.support.http.client.IndividualResource)43 ItemRequestBuilder (api.support.builders.ItemRequestBuilder)41 HoldingRequestBuilder (api.support.builders.HoldingRequestBuilder)19 URL (java.net.URL)18 CompletableFuture (java.util.concurrent.CompletableFuture)13 ServerErrorResponse (org.folio.inventory.support.http.server.ServerErrorResponse)13 List (java.util.List)11 CollectionResourceClient (org.folio.inventory.storage.external.CollectionResourceClient)11 ClientErrorResponse (org.folio.inventory.support.http.server.ClientErrorResponse)11 MalformedURLException (java.net.MalformedURLException)10 JsonResponse (org.folio.inventory.support.http.server.JsonResponse)9 Collectors (java.util.stream.Collectors)8 EndpointFailureDescriptor (support.fakes.EndpointFailureDescriptor)8 ItemsMoveRequestBuilder (api.support.builders.ItemsMoveRequestBuilder)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7