use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class StatisticalCodeTest method canNotDeleteStatisticalCodeIfInUseByHoldings.
@Test
public void canNotDeleteStatisticalCodeIfInUseByHoldings() throws Exception {
final var statisticalCode = new StatisticalCodeBuilder().withId(UUID.fromString("b06fa5fe-a267-4597-8e74-3b308bd4c932")).withCode("stcone").withName("STATISTICAL CODE 1");
final var createdCode = statisticalCodeFixture.createSerialManagementCode(statisticalCode);
UUID instanceId = UUID.randomUUID();
instancesClient.create(smallAngryPlanet(instanceId));
UUID holdingId = UUID.randomUUID();
List<UUID> codes = new ArrayList<>();
codes.add(createdCode.getId());
final var holdingToCreate = new HoldingRequestBuilder().withId(holdingId).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withStatisticalCodeIds(codes);
holdingsClient.create(holdingToCreate);
CompletableFuture<Response> deleteCompleted = new CompletableFuture<>();
client.delete(statisticalCodesUrl("/" + createdCode.getId().toString()), StorageTestSuite.TENANT_ID, ResponseHandler.text(deleteCompleted));
Response response = deleteCompleted.get(5, TimeUnit.SECONDS);
assertThat(response.getStatusCode(), is(400));
assertThat(response.getBody().trim(), is("foreign_key_violation: Key (id)=(b06fa5fe-a267-4597-8e74-3b308bd4c932) is still referenced from table \"holdings record\"."));
}
Aggregations