From 790febbc663310fdc536d75503c09ed9982ef104 Mon Sep 17 00:00:00 2001 From: saba_zedginidze Date: Mon, 26 Aug 2024 17:49:32 +0400 Subject: [PATCH] [MODINVSTOR-1243] Fix failing test --- .../java/api/items/TenantItemApiTests.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/test/java/api/items/TenantItemApiTests.java b/src/test/java/api/items/TenantItemApiTests.java index aa1b813ed..9c933c985 100644 --- a/src/test/java/api/items/TenantItemApiTests.java +++ b/src/test/java/api/items/TenantItemApiTests.java @@ -2,6 +2,8 @@ import static api.ApiTestSuite.COLLEGE_TENANT_ID; import static api.ApiTestSuite.CONSORTIA_TENANT_ID; +import static api.ApiTestSuite.getBookMaterialType; +import static api.ApiTestSuite.getCanCirculateLoanType; import static api.support.InstanceSamples.smallAngryPlanet; import static java.util.concurrent.TimeUnit.SECONDS; import static org.assertj.core.api.Assertions.assertThat; @@ -29,7 +31,6 @@ import api.support.ApiTests; import api.support.InstanceApiClient; import api.support.builders.HoldingRequestBuilder; -import api.support.builders.ItemRequestBuilder; import api.support.http.ResourceClient; import io.vertx.core.json.JsonObject; import junitparams.JUnitParamsRunner; @@ -41,47 +42,47 @@ public class TenantItemApiTests extends ApiTests { public void testTenantItemsGetFromDifferentTenants() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException { - createConsortiumInstanceHoldingItem(); - createCollegeInstanceHoldingItem(); - + var consortiumItemId = createConsortiumInstanceHoldingItem(); + var collegeItemId = createCollegeInstanceHoldingItem(); var consortiumItem = getItems(consortiumOkapiClient, 1).get(0); var collegeItem = getItems(collegeOkapiClient, 1).get(0); + assertThat(consortiumItem.getString(ID)).matches(consortiumItemId.toString()); + assertThat(collegeItem.getString(ID)).matches(collegeItemId.toString()); + var tenantItemPariCollection = constructTenantItemPairCollection(Map.of( CONSORTIA_TENANT_ID, consortiumItem.getString(ID), COLLEGE_TENANT_ID, collegeItem.getString(ID) )); + var response = okapiClient.post(ApiRoot.tenantItems(), JsonObject.mapFrom(tenantItemPariCollection)) .toCompletableFuture().get(5, TimeUnit.SECONDS); assertThat(response.getStatusCode()).isEqualTo(200); - var items = extractItems(response, 2); + var items = extractItems(response, 2); assertThat(items).contains(consortiumItem, collegeItem); } - private void createConsortiumInstanceHoldingItem() { - createInstanceHoldingItem(consortiumItemsClient, consortiumHoldingsStorageClient, consortiumOkapiClient); + private UUID createConsortiumInstanceHoldingItem() { + return createInstanceHoldingItem(consortiumItemsClient, consortiumHoldingsStorageClient, consortiumOkapiClient); } - private void createCollegeInstanceHoldingItem() { - createInstanceHoldingItem(collegeItemsClient, collegeHoldingsStorageClient, collegeOkapiClient); + private UUID createCollegeInstanceHoldingItem() { + return createInstanceHoldingItem(collegeItemsClient, collegeHoldingsStorageClient, collegeOkapiClient); } - private void createInstanceHoldingItem(ResourceClient itemStorageClient, ResourceClient holdingsStorageClient, OkapiHttpClient okapiHttpClient) { + private UUID createInstanceHoldingItem(ResourceClient itemStorageClient, ResourceClient holdingsStorageClient, OkapiHttpClient okapiHttpClient) { var instanceId = UUID.randomUUID(); InstanceApiClient.createInstance(okapiHttpClient, smallAngryPlanet(instanceId)); var holdingId = holdingsStorageClient.create(new HoldingRequestBuilder() .forInstance(instanceId)).getId(); - try { - var item = new ItemRequestBuilder().forHolding(holdingId) - .withBarcode(String.valueOf(Math.random() * 100)).create(); - System.err.println(item.toString()); - itemStorageClient.create(item); - } - catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } + var newItemRequest = JsonObject.of( + "id", UUID.randomUUID().toString(), + "status", new JsonObject().put("name", "Available"), + "holdingsRecordId", holdingId, + "materialTypeId", getBookMaterialType(), + "permanentLoanTypeId", getCanCirculateLoanType()); + return itemsStorageClient.create(newItemRequest).getId(); } private List getItems(OkapiHttpClient okapiHttpClient, int expected)