Skip to content

Commit

Permalink
CIRCSTORE-521 update test
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-barannyk committed Aug 22, 2024
1 parent d352bfd commit da06cac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/test/java/org/folio/rest/api/RequestBatchAPITest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package org.folio.rest.api;

import static org.awaitility.Awaitility.await;
import static org.folio.rest.api.RequestsApiTest.requestStorageUrl;
import static org.folio.rest.api.StorageTestSuite.TENANT_ID;
import static org.folio.rest.api.StorageTestSuite.storageUrl;
import static org.folio.rest.support.kafka.FakeKafkaConsumer.getRequestQueueReorderingEvents;
import static org.folio.rest.support.matchers.DomainEventAssertions.assertCreateRequestQueueReorderingEvent;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

import java.net.URL;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -224,19 +223,17 @@ public void cannotInjectSqlThroughRequestId() throws Exception {
}

@Test
public void canUpdateRequestPositionsInBatchForTheInstance() throws Exception {
UUID instanceId = UUID.randomUUID();
public void shouldPublishKafkaEventWhenUpdateRequestPositionsInBatchForTheInstance()
throws Exception {

UUID instanceId = UUID.randomUUID();
JsonObject firstRequest = createRequestAtPosition(null, instanceId, 1);
JsonObject secondRequest = createRequestAtPosition(null, instanceId, 2);

ReorderRequest firstReorderRequest = new ReorderRequest(firstRequest, 2);
ReorderRequest secondReorderRequest = new ReorderRequest(secondRequest, 1);

reorderRequests(
firstReorderRequest,
secondReorderRequest
);
reorderRequests(firstReorderRequest, secondReorderRequest);

JsonObject requestsForInstanceReply = getAllRequestsForInstance(instanceId);
assertThat(requestsForInstanceReply.getInteger("totalRecords"), is(2));
Expand All @@ -251,7 +248,8 @@ public void canUpdateRequestPositionsInBatchForTheInstance() throws Exception {
assertThat(r[0].getString("id"), is(secondRequest.getString("id")));
assertThat(r[1].getString("id"), is(firstRequest.getString("id")));

assertCreateRequestQueueReorderingEvent();
assertCreateRequestQueueReorderingEvent(instanceId.toString(), List.of(
firstRequest.getString("id"), secondRequest.getString("id")));
}

private JsonObject getAllRequestsForItem(UUID itemId) throws Exception {
Expand Down Expand Up @@ -386,10 +384,6 @@ private void assertValidationError(
errorMessageMatcher);
}

public static void assertCreateRequestQueueReorderingEvent() {
await().until(() -> getRequestQueueReorderingEvents().size(), greaterThan(0));
}

/**
* Holder for request reorder operation. Holds request and new position for it.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ public static KafkaConsumerRecord<String, JsonObject> getFirstCheckInEvent(Strin
return getFirstEvent(getCheckInEvents(checkInId));
}

public static KafkaConsumerRecord<String, JsonObject> getFirstRequestQueueReorderingEvent() {
return getFirstEvent(getRequestQueueReorderingEvents());
}

private static KafkaConsumerRecord<String, JsonObject> getFirstEvent(
Collection<KafkaConsumerRecord<String, JsonObject>> events) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import static org.folio.rest.support.kafka.FakeKafkaConsumer.getCheckInEvents;
import static org.folio.rest.support.kafka.FakeKafkaConsumer.getCirculationRulesEvents;
import static org.folio.rest.support.kafka.FakeKafkaConsumer.getFirstLoanEvent;
import static org.folio.rest.support.kafka.FakeKafkaConsumer.getFirstRequestQueueReorderingEvent;
import static org.folio.rest.support.kafka.FakeKafkaConsumer.getLastCheckInEvent;
import static org.folio.rest.support.kafka.FakeKafkaConsumer.getLastCirculationRulesEvent;
import static org.folio.rest.support.kafka.FakeKafkaConsumer.getLastLoanEvent;
import static org.folio.rest.support.kafka.FakeKafkaConsumer.getLastRequestEvent;
import static org.folio.rest.support.kafka.FakeKafkaConsumer.getLoanEvents;
import static org.folio.rest.support.kafka.FakeKafkaConsumer.getRequestEvents;
import static org.folio.rest.support.kafka.FakeKafkaConsumer.getRequestQueueReorderingEvents;
import static org.folio.rest.support.matchers.UUIDMatchers.hasUUIDFormat;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
Expand All @@ -34,6 +36,7 @@
import org.folio.service.event.DomainEventType;

import io.vertx.core.MultiMap;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.kafka.client.consumer.KafkaConsumerRecord;
import io.vertx.kafka.client.producer.KafkaHeader;
Expand Down Expand Up @@ -108,6 +111,18 @@ public static void assertCreateEventForRequest(JsonObject request) {
assertCreateEvent(getLastRequestEvent(requestId), request);
}

public static void assertCreateRequestQueueReorderingEvent(String instanceId,
List<String> requestIds) {

await().until(() -> getRequestQueueReorderingEvents().size(), greaterThan(0));

JsonObject payload = new JsonObject()
.put("instanceId", instanceId)
.put("requestIds", new JsonArray(requestIds));

assertCreateEvent(getFirstRequestQueueReorderingEvent(), payload);
}

public static void assertNoRequestEvent(String requestId) {
await().during(1, SECONDS)
.until(() -> getRequestEvents(requestId), is(empty()));
Expand Down

0 comments on commit da06cac

Please sign in to comment.