Search in sources :

Example 11 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder 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 12 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder 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 13 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder 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 14 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder 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 15 with ItemRequestBuilder

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

the class ItemApiExamples method canCreateItemsWithAllStatuses.

@Test
@Parameters({ "Available", "Awaiting pickup", "Awaiting delivery", "Checked out", "In process", "In transit", "Missing", "On order", "Paged", "Declared lost", "Order closed", "Claimed returned", "Withdrawn", "Lost and paid", "Aged to lost" })
public void canCreateItemsWithAllStatuses(String itemStatus) throws Exception {
    final UUID holdingsId = createInstanceAndHolding();
    final IndividualResource createResponse = itemsClient.create(new ItemRequestBuilder().forHolding(holdingsId).canCirculate().withStatus(itemStatus));
    assertThat(createResponse.getJson().getJsonObject("status").getString("name"), is(itemStatus));
}
Also used : UUID(java.util.UUID) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

ItemRequestBuilder (api.support.builders.ItemRequestBuilder)96 Test (org.junit.Test)96 IndividualResource (org.folio.inventory.support.http.client.IndividualResource)83 Response (org.folio.inventory.support.http.client.Response)41 JsonObject (io.vertx.core.json.JsonObject)40 UUID (java.util.UUID)38 Parameters (junitparams.Parameters)29 HoldingRequestBuilder (api.support.builders.HoldingRequestBuilder)15 JsonArray (io.vertx.core.json.JsonArray)10 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 ItemsMoveRequestBuilder (api.support.builders.ItemsMoveRequestBuilder)5 DateTime (org.joda.time.DateTime)5 URL (java.net.URL)4 List (java.util.List)3 Date (java.util.Date)2 ApiTestSuite (api.ApiTestSuite)1 USER_ID (api.ApiTestSuite.USER_ID)1 ApiTestSuite.getCanCirculateLoanType (api.ApiTestSuite.getCanCirculateLoanType)1 ApiTestSuite.getDvdMaterialType (api.ApiTestSuite.getDvdMaterialType)1 ApiTestSuite.getMainLibraryLocation (api.ApiTestSuite.getMainLibraryLocation)1