Skip to content

Commit

Permalink
Fix mockOkapi Future usage
Browse files Browse the repository at this point in the history
(cherry picked from commit 0646db9)
  • Loading branch information
julianladisch committed Aug 26, 2022
1 parent 89a2761 commit e8985db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
25 changes: 10 additions & 15 deletions src/test/java/org/folio/edge/rtac/MainVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.apache.http.HttpStatus.SC_OK;
import static org.folio.edge.rtac.utils.RtacUtils.composeMimeTypes;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.atLeast;
Expand All @@ -37,6 +38,7 @@
import org.folio.edge.core.utils.ApiKeyUtils;
import org.folio.edge.core.utils.test.TestUtils;
import org.folio.edge.rtac.model.Error;
import org.folio.edge.rtac.model.Holding;
import org.folio.edge.rtac.model.Holdings;
import org.folio.edge.rtac.model.Instances;
import org.folio.edge.rtac.utils.RtacMockOkapi;
Expand All @@ -49,7 +51,6 @@
import io.restassured.response.Response;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -78,7 +79,7 @@ public static void setUpOnce(TestContext context) throws Exception {
knownTenants.add(ApiKeyUtils.parseApiKey(apiKey).tenantId);

mockOkapi = spy(new RtacMockOkapi(okapiPort, knownTenants));
mockOkapi.start(context);
mockOkapi.start().onComplete(context.asyncAssertSuccess());

vertx = Vertx.vertx();

Expand All @@ -99,19 +100,7 @@ public static void setUpOnce(TestContext context) throws Exception {
@AfterClass
public static void tearDownOnce(TestContext context) {
logger.info("Shutting down server");
final Async async = context.async();
vertx.close(res -> {
if (res.failed()) {
logger.error("Failed to shut down edge-rtac server", res.cause());
fail(res.cause().getMessage());
} else {
logger.info("Successfully shut down edge-rtac server");
}

logger.info("Shutting down mock Okapi");
mockOkapi.close(context);
async.complete();
});
mockOkapi.close().onComplete(context.asyncAssertSuccess());
}

protected String prepareQueryFor(String apiKey, String... instanceIds) {
Expand Down Expand Up @@ -153,6 +142,9 @@ public void testAdminHealth(TestContext context) {
assertEquals("\"OK\"", resp.body().asString());
}

// unsuccessful login attempts result in a 200 OK status with empty elements
// in the message body

@Test
public void testRtacUnknownApiKey(TestContext context) throws Exception {
logger.info("=== Test request with unknown apiKey (tenant) ===");
Expand Down Expand Up @@ -208,6 +200,9 @@ public void testRtacTitleFound(TestContext context) throws Exception {
assertEquals(expected, actual);
}

// Unsuccessful searches result in a 200 OK status with an empty element in the
// response body

@Test
public void testRtacTitleNotFound(TestContext context) throws Exception {
logger.info("=== Test request where title isn't found ===");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public void setUp(TestContext context) {
knownTenants.add(tenant);

mockOkapi = new RtacMockOkapi(okapiPort, knownTenants);
mockOkapi.start(context);
mockOkapi.start().onComplete(context.asyncAssertSuccess());

client = new RtacOkapiClientFactory(Vertx.vertx(), "http://localhost:" + okapiPort, reqTimeout)
.getRtacOkapiClient(tenant);
}

@After
public void tearDown(TestContext context) {
mockOkapi.close(context);
mockOkapi.close().onComplete(context.asyncAssertSuccess());
}

@Test
Expand Down

0 comments on commit e8985db

Please sign in to comment.