Skip to content

Commit

Permalink
MODINVSTOR-1116, MODINVSTOR-1115: Fix reference and sample data
Browse files Browse the repository at this point in the history
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/<tenantid> in InstallUpgradeIT
  • Loading branch information
julianladisch committed Oct 20, 2023
1 parent 606398c commit 901e21a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/folio/rest/impl/TenantRefApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -131,6 +130,10 @@ Future<Integer> 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");
Expand All @@ -140,11 +143,12 @@ Future<Integer> 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)
Expand Down
36 changes: 25 additions & 11 deletions src/test/java/org/folio/rest/InstallUpgradeIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -43,8 +46,14 @@
* <p>Test that logging works.
*
* <p>Test installation and migration with smoke test.
*
* <p>How to run this test class only:
*
* <p>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();

Expand All @@ -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)
Expand All @@ -87,26 +96,30 @@ 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)
.willReturn(WireMock.ok().withBody(new JsonObject().put(USER_TENANTS_FIELD, JsonArray.of()).encode())));
}

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));
Expand Down Expand Up @@ -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);

Expand All @@ -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");

Expand Down Expand Up @@ -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)
Expand All @@ -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() {
Expand Down

0 comments on commit 901e21a

Please sign in to comment.