Search in sources :

Example 1 with ItemsMoveRequestBuilder

use of api.support.builders.ItemsMoveRequestBuilder in project mod-inventory by folio-org.

the class ItemApiMoveExamples method shouldReportErrorsWhenOnlySomeRequestedItemsCouldNotBeMoved.

@Test
public void shouldReportErrorsWhenOnlySomeRequestedItemsCouldNotBeMoved() 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 UUID nonExistedItemId = UUID.randomUUID();
    final IndividualResource createItem1 = itemsClient.create(new ItemRequestBuilder().forHolding(existedHoldingId).withBarcode("645398607547").withStatus(ItemStatusName.AVAILABLE.value()));
    JsonObject itemsMoveRequestBody = new ItemsMoveRequestBuilder(newHoldingId, new JsonArray(Arrays.asList(createItem1.getId(), nonExistedItemId))).create();
    Response postItemsMoveResponse = moveItems(itemsMoveRequestBody);
    assertThat(postItemsMoveResponse.getStatusCode(), is(200));
    assertThat(postItemsMoveResponse.getContentType(), containsString(APPLICATION_JSON));
    List notFoundIds = postItemsMoveResponse.getJson().getJsonArray("nonUpdatedIds").getList();
    assertThat(notFoundIds.size(), is(1));
    assertThat(notFoundIds.get(0), equalTo(nonExistedItemId.toString()));
    JsonObject updatedItem1 = itemsClient.getById(createItem1.getId()).getJson();
    assertThat(newHoldingId.toString(), equalTo(updatedItem1.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 2 with ItemsMoveRequestBuilder

use of api.support.builders.ItemsMoveRequestBuilder 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 3 with ItemsMoveRequestBuilder

use of api.support.builders.ItemsMoveRequestBuilder 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 4 with ItemsMoveRequestBuilder

use of api.support.builders.ItemsMoveRequestBuilder 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 5 with ItemsMoveRequestBuilder

use of api.support.builders.ItemsMoveRequestBuilder in project mod-inventory by folio-org.

the class ItemApiMoveExamples method cannotMoveItemsToUnspecifiedHoldingsRecord.

@Test
public void cannotMoveItemsToUnspecifiedHoldingsRecord() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject itemMoveWithoutToHoldingsRecordId = new ItemsMoveRequestBuilder(null, new JsonArray(Collections.singletonList(UUID.randomUUID()))).create();
    final var postMoveItemsCompleted = okapiClient.post(ApiRoot.moveItems(), itemMoveWithoutToHoldingsRecordId);
    Response postMoveItemsResponse = postMoveItemsCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(postMoveItemsResponse.getStatusCode(), is(422));
    assertThat(postMoveItemsResponse.getContentType(), containsString(APPLICATION_JSON));
    assertThat(postMoveItemsResponse.getBody(), containsString("errors"));
    assertThat(postMoveItemsResponse.getBody(), containsString("toHoldingsRecordId"));
    assertThat(postMoveItemsResponse.getBody(), containsString("toHoldingsRecordId is a required field"));
}
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) Test(org.junit.Test)

Aggregations

ItemsMoveRequestBuilder (api.support.builders.ItemsMoveRequestBuilder)7 JsonArray (io.vertx.core.json.JsonArray)7 JsonObject (io.vertx.core.json.JsonObject)7 Response (org.folio.inventory.support.http.client.Response)7 Test (org.junit.Test)7 ItemRequestBuilder (api.support.builders.ItemRequestBuilder)5 UUID (java.util.UUID)5 IndividualResource (org.folio.inventory.support.http.client.IndividualResource)5 List (java.util.List)2