use of org.folio.rest.support.matchers.DomainEventAssertions in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method canPostSynchronousBatchWithExistingIdWithUpsertTrue.
@Test
public void canPostSynchronousBatchWithExistingIdWithUpsertTrue() {
final String existingHrId = UUID.randomUUID().toString();
final JsonArray holdingsArray1 = threeHoldings();
final JsonArray holdingsArray2 = threeHoldings();
holdingsArray1.getJsonObject(1).put("id", existingHrId);
holdingsArray2.getJsonObject(1).put("id", existingHrId);
final Response firstResponse = postSynchronousBatch("?upsert=true", holdingsArray1);
final JsonObject existingHrBeforeUpdate = getById(existingHrId).getJson();
final Response secondResponse = postSynchronousBatch("?upsert=true", holdingsArray2);
assertThat(firstResponse, statusCodeIs(HTTP_CREATED));
assertThat(secondResponse, statusCodeIs(HTTP_CREATED));
Stream.concat(holdingsArray1.stream(), holdingsArray2.stream()).map(json -> ((JsonObject) json).getString("id")).filter(id -> !id.equals(existingHrId)).map(this::getById).map(Response::getJson).forEach(DomainEventAssertions::assertCreateEventForHolding);
await().untilAsserted(() -> {
var newHr = getById(existingHrId).getJson();
final String id = newHr.getString("id");
final String instanceId = newHr.getString("instanceId");
assertThat(getHoldingsEvents(instanceId, id).size(), greaterThan(0));
assertUpdateEvent(getLastHoldingEvent(instanceId, id), existingHrBeforeUpdate, newHr);
});
}
use of org.folio.rest.support.matchers.DomainEventAssertions in project mod-inventory-storage by folio-org.
the class ItemStorageTest method canPostSynchronousBatchWithExistingIdUpsertTrue.
@Test
public void canPostSynchronousBatchWithExistingIdUpsertTrue() throws Exception {
final UUID holdingsRecordId = createInstanceAndHolding(mainLibraryLocationId);
final UUID existingItemId = UUID.randomUUID();
final JsonArray itemsArray1 = new JsonArray().add(nod(existingItemId, holdingsRecordId)).add(smallAngryPlanet(holdingsRecordId)).add(interestingTimes(holdingsRecordId));
final JsonArray itemsArray2 = new JsonArray().add(nod(existingItemId, holdingsRecordId)).add(temeraire(holdingsRecordId)).add(uprooted(holdingsRecordId));
final var firstResponse = postSynchronousBatch("?upsert=true", itemsArray1);
final var existingItemBeforeUpdate = getById(existingItemId).getJson();
final var secondResponse = postSynchronousBatch("?upsert=true", itemsArray2);
assertThat(firstResponse.getStatusCode(), is(201));
assertThat(secondResponse.getStatusCode(), is(201));
Stream.concat(itemsArray1.stream(), itemsArray2.stream()).map(json -> ((JsonObject) json).getString("id")).filter(id -> !id.equals(existingItemId.toString())).map(this::getById).map(Response::getJson).forEach(DomainEventAssertions::assertCreateEventForItem);
assertUpdateEventForItem(existingItemBeforeUpdate, getById(existingItemId).getJson());
}
use of org.folio.rest.support.matchers.DomainEventAssertions in project mod-inventory-storage by folio-org.
the class ItemStorageTest method canPostSynchronousBatch.
@Test
public void canPostSynchronousBatch() {
JsonArray itemsArray = threeItems();
assertThat(postSynchronousBatch(itemsArray), statusCodeIs(HttpStatus.HTTP_CREATED));
for (Object item : itemsArray) {
assertExists((JsonObject) item);
}
itemsArray.stream().map(obj -> (JsonObject) obj).map(obj -> getById(obj.getString("id")).getJson()).forEach(DomainEventAssertions::assertCreateEventForItem);
}
Aggregations