From 901e21a3c7d4f26be5932902e173da090893858d Mon Sep 17 00:00:00 2001 From: Julian Ladisch Date: Fri, 20 Oct 2023 21:05:33 +0200 Subject: [PATCH] MODINVSTOR-1116, MODINVSTOR-1115: Fix reference and sample data Fix call number types reference data and instance relationships sample data so that InstallUpgradeIT succeeds. This also fixes MODINVSTOR-1115: Check "error" in GET /_/tenant/ in InstallUpgradeIT --- .../org/folio/rest/impl/TenantRefApi.java | 8 +++-- .../java/org/folio/rest/InstallUpgradeIT.java | 36 +++++++++++++------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/folio/rest/impl/TenantRefApi.java b/src/main/java/org/folio/rest/impl/TenantRefApi.java index 586bd64af..6f95febc9 100644 --- a/src/main/java/org/folio/rest/impl/TenantRefApi.java +++ b/src/main/java/org/folio/rest/impl/TenantRefApi.java @@ -63,7 +63,6 @@ public class TenantRefApi extends TenantAPI { "electronic-access-relationships", "ill-policies", "holdings-types", - "call-number-types", "instance-note-types", "holdings-note-types", "item-note-types", @@ -131,6 +130,10 @@ Future loadData(TenantAttributes attributes, String tenantId, for (String p : refPaths) { tl.add(p); } + + tl.withPostIgnore(); // System call number type couldn't be updated + tl.add("call-number-types"); + tl.withKey(SAMPLE_KEY).withLead(SAMPLE_LEAD); tl.withIdContent(); tl.add("location-units/institutions"); @@ -140,11 +143,12 @@ Future loadData(TenantAttributes attributes, String tenantId, tl.add("instances", INSTANCES); tl.add("holdingsrecords", HOLDINGS); tl.add("items", ITEMS); - tl.add("instance-relationships", INSTANCE_RELATIONSHIPS); tl.add("bound-with/instances", INSTANCES); tl.add("bound-with/holdingsrecords", HOLDINGS); tl.add("bound-with/items", ITEMS); tl.add("bound-with/bound-with-parts", BOUND_WITH_PARTS); + tl.withPostIgnore(); + tl.add("instance-relationships", INSTANCE_RELATIONSHIPS); tl.withFilter(service -> servicePointUserFilter(service, servicePoints)) .withPostOnly() .withAcceptStatus(422) diff --git a/src/test/java/org/folio/rest/InstallUpgradeIT.java b/src/test/java/org/folio/rest/InstallUpgradeIT.java index 1b2eb7e77..ce13323e3 100644 --- a/src/test/java/org/folio/rest/InstallUpgradeIT.java +++ b/src/test/java/org/folio/rest/InstallUpgradeIT.java @@ -5,6 +5,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.common.ConsoleNotifier; @@ -17,6 +18,8 @@ import io.vertx.core.json.JsonObject; import java.io.IOException; import java.nio.file.Path; +import java.time.Duration; +import org.awaitility.Awaitility; import org.folio.okapi.common.XOkapiHeaders; import org.junit.Before; import org.junit.BeforeClass; @@ -43,8 +46,14 @@ *

Test that logging works. * *

Test installation and migration with smoke test. + * + *

How to run this test class only: + * + *

mvn verify -B -Dtest=none -Dsurefire.failIfNoSpecifiedTests=false -Dit.test=InstallUpgradeIT 2>&1 | tee /tmp/out */ public class InstallUpgradeIT { + /** set true for debugging. */ + public static final boolean IS_LOG_ENABLED = false; public static final Network NETWORK = Network.newNetwork(); @@ -66,9 +75,9 @@ public class InstallUpgradeIT { .withDatabaseName("postgres"); @ClassRule(order = 2) - public static final WireMockRule MOCK_SERVER = + public static final WireMockRule OKAPI_MOCK = new WireMockRule(WireMockConfiguration.wireMockConfig() - .notifier(new ConsoleNotifier(false)) + .notifier(new ConsoleNotifier(IS_LOG_ENABLED)) .dynamicPort()); @ClassRule(order = 3) @@ -87,19 +96,19 @@ public class InstallUpgradeIT { .withEnv("KAFKA_PORT", "9092"); private static final Logger LOG = LoggerFactory.getLogger(InstallUpgradeIT.class); - private static final boolean IS_LOG_ENABLED = false; private static final String USER_TENANTS_PATH = "/user-tenants?limit=1"; private static final String USER_TENANTS_FIELD = "userTenants"; @BeforeClass public static void beforeClass() { - Testcontainers.exposeHostPorts(MOCK_SERVER.port()); + Testcontainers.exposeHostPorts(OKAPI_MOCK.port()); RestAssured.reset(); RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); RestAssured.baseURI = "http://" + MOD_MIS.getHost() + ":" + MOD_MIS.getFirstMappedPort(); if (IS_LOG_ENABLED) { - KAFKA.followOutput(new Slf4jLogConsumer(LOG).withSeparateOutputStreams()); - MOD_MIS.followOutput(new Slf4jLogConsumer(LOG).withSeparateOutputStreams()); + KAFKA.followOutput(new Slf4jLogConsumer(LOG).withSeparateOutputStreams().withPrefix("Kafka")); + POSTGRES.followOutput(new Slf4jLogConsumer(LOG).withSeparateOutputStreams().withPrefix("Postgres")); + MOD_MIS.followOutput(new Slf4jLogConsumer(LOG).withSeparateOutputStreams().withPrefix("mis")); } WireMock.stubFor(WireMock.get(USER_TENANTS_PATH) @@ -107,6 +116,10 @@ public static void beforeClass() { } static void postgresExec(String... command) { + Awaitility.await().atMost(Duration.ofSeconds(1)).ignoreExceptions().until(() -> { + POSTGRES.execInContainer("true"); // sometimes throws IOException "Broken pipe" + return true; + }); try { ExecResult execResult = POSTGRES.execInContainer(command); assertThat(execResult.getStdout() + "\n" + execResult.getStderr(), execResult.getExitCode(), is(0)); @@ -142,7 +155,7 @@ public void installAndUpgrade() { postTenant(body); - // migrate from 0.0.0, migration should be idempotent + // migrate from 0.0.0 to current version, installation and migration should be idempotent body.put("module_from", "0.0.0"); postTenant(body); @@ -153,7 +166,7 @@ public void installAndUpgrade() { public void upgradeFromLotus() { // load database dump of Lotus (R3 2021) version of mod-inventory-storage postgresExec("psql", "-U", POSTGRES.getUsername(), "-d", POSTGRES.getDatabaseName(), - "-f", "lotus-23.0.0.sql"); + "-f", "/lotus-23.0.0.sql"); setTenant("lotus"); @@ -191,7 +204,7 @@ public void canLog() { private void setTenant(String tenant) { RestAssured.requestSpecification = new RequestSpecBuilder() .addHeader(XOkapiHeaders.URL_TO, "http://localhost:8081") - .addHeader(XOkapiHeaders.URL, String.format("http://host.testcontainers.internal:%d", MOCK_SERVER.port())) + .addHeader(XOkapiHeaders.URL, String.format("http://host.testcontainers.internal:%d", OKAPI_MOCK.port())) .addHeader(XOkapiHeaders.TENANT, tenant) .addHeader(XOkapiHeaders.USER_ID, "67e1ce93-e358-46ea-aed8-96e2fa73520f") .setContentType(ContentType.JSON) @@ -212,8 +225,9 @@ private void postTenant(JsonObject body) { when() .get(location + "?wait=60000") .then() - .statusCode(200) - .body("complete", is(true)); + .statusCode(200) // getting job record succeeds + .body("complete", is(true)) // job is complete + .body("error", is(nullValue())); // job has succeeded without error } private void smokeTest() {