Skip to content

Commit

Permalink
[MODINVSTOR-1243] Fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Saba-Zedginidze-EPAM committed Aug 26, 2024
1 parent ed34dac commit 790febb
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/test/java/api/items/TenantItemApiTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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<JsonObject> getItems(OkapiHttpClient okapiHttpClient, int expected)
Expand Down

0 comments on commit 790febb

Please sign in to comment.