Search in sources :

Example 1 with Response

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

the class ItemApiExamples method cannotUpdateItemToSameBarcodeAsExistingItem.

@Test
public void cannotUpdateItemToSameBarcodeAsExistingItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject smallAngryInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
    UUID smallAngryHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(smallAngryInstance.getString("id")))).getId();
    itemsClient.create(new ItemRequestBuilder().forHolding(smallAngryHoldingId).book().canCirculate().withBarcode("645398607547"));
    JsonObject nodInstance = createInstance(nod(UUID.randomUUID()));
    UUID nodHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(nodInstance.getString("id")))).getId();
    IndividualResource nodItemResponse = itemsClient.create(new ItemRequestBuilder().forHolding(nodHoldingId).book().canCirculate().withBarcode("654647774352"));
    JsonObject changedNodItem = nodItemResponse.getJson().copy().put("barcode", "645398607547");
    URL nodItemLocation = new URL(String.format("%s/%s", ApiRoot.items(), nodItemResponse.getId()));
    final var putItemCompleted = okapiClient.put(nodItemLocation, changedNodItem);
    Response putItemResponse = putItemCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(putItemResponse.getStatusCode(), is(400));
    assertThat(putItemResponse.getBody(), is("Barcode must be unique, 645398607547 is already assigned to another item"));
}
Also used : Response(org.folio.inventory.support.http.client.Response) HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) URL(java.net.URL) Test(org.junit.Test)

Example 2 with Response

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

the class ItemApiExamples method CanDeleteSingleItem.

@Test
public void CanDeleteSingleItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject createdInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
    UUID holdingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(createdInstance.getString("id")))).getId();
    itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("645398607547"));
    IndividualResource itemToDeleteResponse = itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("175848607547"));
    itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("645334645247"));
    itemsClient.delete(itemToDeleteResponse.getId());
    final var getAllCompleted = okapiClient.get(ApiRoot.items());
    Response getAllResponse = getAllCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(getAllResponse.getJson().getJsonArray("items").size(), is(2));
    assertThat(getAllResponse.getJson().getInteger("totalRecords"), is(2));
}
Also used : Response(org.folio.inventory.support.http.client.Response) HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) Test(org.junit.Test)

Example 3 with Response

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

the class ItemApiExamples method cannotCreateItemWithUnrecognisedStatusName.

@Test
public void cannotCreateItemWithUnrecognisedStatusName() throws InterruptedException, ExecutionException, TimeoutException {
    JsonObject itemWithUnrecognizedStatus = new ItemRequestBuilder().forHolding(UUID.randomUUID()).withBarcode("645398607547").temporarilyInReadingRoom().create().put("status", new JsonObject().put("name", "Unrecognized name"));
    final var postCompleted = okapiClient.post(items(""), itemWithUnrecognizedStatus);
    Response response = postCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(response, hasValidationError("Undefined status specified", "status.name", "Unrecognized name"));
}
Also used : Response(org.folio.inventory.support.http.client.Response) JsonObject(io.vertx.core.json.JsonObject) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 4 with Response

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

the class ItemApiExamples method cannotChangeHRID.

@Test
public void cannotChangeHRID() throws Exception {
    UUID holdingId = createInstanceAndHolding();
    IndividualResource postResponse = itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("645398607547").temporarilyInReadingRoom());
    JsonObject createdItem = postResponse.getJson();
    assertThat(createdItem.getString("hrid"), notNullValue());
    JsonObject updatedItem = createdItem.copy().put("barcode", "645398607548").put("itemLevelCallNumber", "callNumber").put("hrid", "updatedHrid");
    Response updateResponse = updateItem(updatedItem);
    assertThat(updateResponse, hasValidationError("HRID can not be updated", "hrid", "updatedHrid"));
    JsonObject existingItem = itemsClient.getById(postResponse.getId()).getJson();
    assertThat(existingItem, is(createdItem));
}
Also used : Response(org.folio.inventory.support.http.client.Response) 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 5 with Response

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

the class ItemApiExamples method cannotRemoveHRID.

@Test
public void cannotRemoveHRID() throws Exception {
    UUID holdingId = createInstanceAndHolding();
    IndividualResource postResponse = itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withHrid("it777").withBarcode("645398607547").temporarilyInReadingRoom());
    JsonObject createdItem = postResponse.getJson();
    assertThat(createdItem.getString("hrid"), notNullValue());
    JsonObject updatedItem = createdItem.copy().put("barcode", "645398607548").put("itemLevelCallNumber", "callNumber");
    updatedItem.remove("hrid");
    Response updateResponse = updateItem(updatedItem);
    assertThat(updateResponse, hasValidationError("HRID can not be updated", "hrid", null));
    JsonObject existingItem = itemsClient.getById(postResponse.getId()).getJson();
    assertThat(existingItem, is(createdItem));
}
Also used : Response(org.folio.inventory.support.http.client.Response) 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)

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