Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Aug 10, 2023
1 parent bb6b0f4 commit 9be45aa
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
1 change: 1 addition & 0 deletions doc/changes/changes_2.7.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This release updates the extension so that it supports categories and upgrading
#### Test Dependency Updates

* Updated `com.exasol:exasol-testcontainers:6.6.0` to `6.6.1`
* Updated `com.exasol:extension-manager-integration-test-java:0.4.0` to `0.5.0`
* Updated `nl.jqno.equalsverifier:equalsverifier:3.14.3` to `3.15.1`
* Updated `org.junit.jupiter:junit-jupiter-engine:5.9.3` to `5.10.0`
* Updated `org.scalatestplus:scalatestplus-mockito_2.13:1.0.0-M2` to `1.0.0-SNAP5`
Expand Down
2 changes: 1 addition & 1 deletion extension/src/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function upgrade(context: ExtendedContext, extensionInfo: ExtensionInfo):
}
const newVersion = extensionInfo.version
if (previousVersion.result === newVersion) {
throw new PreconditionFailedError(`Current version ${newVersion} already installed`)
throw new PreconditionFailedError(`Extension is already installed in latest version ${newVersion}`)
}
installExtension(context, extensionInfo, newVersion)
return { previousVersion: previousVersion.result, newVersion };
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@
<dependency>
<groupId>com.exasol</groupId>
<artifactId>extension-manager-integration-test-java</artifactId>
<version>0.4.0</version>
<version>0.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
61 changes: 56 additions & 5 deletions src/test/java/com/exasol/cloudetl/extension/ExtensionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

import java.io.FileNotFoundException;
import java.net.URISyntaxException;
import java.nio.file.*;
import java.sql.Connection;
import java.sql.SQLException;
Expand All @@ -24,8 +25,7 @@
import com.exasol.exasoltestsetup.ExasolTestSetupFactory;
import com.exasol.extensionmanager.client.model.ExtensionsResponseExtension;
import com.exasol.extensionmanager.client.model.InstallationsResponseInstallation;
import com.exasol.extensionmanager.itest.ExtensionManagerClient;
import com.exasol.extensionmanager.itest.ExtensionManagerSetup;
import com.exasol.extensionmanager.itest.*;
import com.exasol.extensionmanager.itest.builder.ExtensionBuilder;
import com.exasol.matcher.TypeMatchMode;
import com.exasol.mavenprojectversiongetter.MavenProjectVersionGetter;
Expand All @@ -34,6 +34,10 @@

class ExtensionIT {
private static final Logger LOGGER = Logger.getLogger(ExtensionIT.class.getName());
private static final String PREVIOUS_VERSION = "2.7.2";
private static final String PREVIOUS_VERSION_JAR_FILE = "exasol-cloud-storage-extension-" + PREVIOUS_VERSION
+ ".jar";
private static final String EXTENSION_ID = "cloud-storage-extension.js";
private static final Path EXTENSION_SOURCE_DIR = Paths.get("extension").toAbsolutePath();
private static final String PROJECT_VERSION = MavenProjectVersionGetter.getCurrentProjectVersion();
private static final String S3_CONNECTION = "S3_CONNECTION";
Expand All @@ -50,7 +54,7 @@ class ExtensionIT {
static void setup() throws FileNotFoundException, BucketAccessException, TimeoutException, SQLException {
exasolTestSetup = new ExasolTestSetupFactory(Paths.get("no-cloud-setup")).getTestSetup();
setup = ExtensionManagerSetup.create(exasolTestSetup, ExtensionBuilder.createDefaultNpmBuilder(
EXTENSION_SOURCE_DIR, EXTENSION_SOURCE_DIR.resolve("dist/cloud-storage-extension.js")));
EXTENSION_SOURCE_DIR, EXTENSION_SOURCE_DIR.resolve("dist").resolve(EXTENSION_ID)));
exasolTestSetup.getDefaultBucket().uploadFile(ADAPTER_JAR, ADAPTER_JAR.getFileName().toString());
client = setup.client();
s3setup = S3Setup.create();
Expand All @@ -60,11 +64,12 @@ static void setup() throws FileNotFoundException, BucketAccessException, Timeout
}

private static Path getAdapterJar() {
final Path jar = Paths.get("target").resolve("exasol-cloud-storage-extension-2.7.3.jar").toAbsolutePath();
final Path jar = Paths.get("target").resolve("exasol-cloud-storage-extension-" + PROJECT_VERSION + ".jar")
.toAbsolutePath();
if (Files.exists(jar)) {
return jar;
} else {
throw new AssertionFailedError("Adapter jar " + jar + " does not exist. Run mvn package.");
throw new AssertionFailedError("Adapter jar " + jar + " does not exist. Run 'mvn package'.");
}
}

Expand Down Expand Up @@ -180,6 +185,52 @@ void getExtensionDetailsInstancesNotSupported() {
equalTo("Creating instances not supported"), equalTo(404));
}

@Test
void upgradeFailsWhenNotInstalled() {
setup.client().assertRequestFails(() -> setup.client().upgrade(),
"Not all required scripts are installed: Validation failed: Script 'IMPORT_PATH' is missing, Script 'IMPORT_METADATA' is missing, Script 'IMPORT_FILES' is missing, Script 'EXPORT_PATH' is missing, Script 'EXPORT_TABLE' is missing",
412);
}

@Test
void upgradeFailsWhenAlreadyUpToDate() {
setup.client().install();
setup.client().assertRequestFails(() -> setup.client().upgrade(),
"Extension is already installed in latest version " + PROJECT_VERSION, 412);
}

@Test
void upgradeFromPreviousVersion() throws InterruptedException, BucketAccessException, TimeoutException,
FileNotFoundException, URISyntaxException, SQLException {
final PreviousExtensionVersion previousVersion = createPreviousVersion();
previousVersion.prepare();
previousVersion.install();
verifyExportImportWorks();
assertInstalledVersion("EXA_EXTENSIONS.S3_FILES_ADAPTER", PREVIOUS_VERSION);
previousVersion.upgrade();
assertInstalledVersion("EXA_EXTENSIONS.S3_FILES_ADAPTER", PROJECT_VERSION);
verifyExportImportWorks();
}

private void assertInstalledVersion(final String expectedName, final String expectedVersion) {
final List<InstallationsResponseInstallation> installations = setup.client().getInstallations();
final InstallationsResponseInstallation expectedInstallation = new InstallationsResponseInstallation()
.name(expectedName).version(expectedVersion);
// The extension is installed twice (previous and current version), so each one returns the same installation.
assertAll(() -> assertThat(installations, hasSize(2)),
() -> assertThat(installations.get(0), equalTo(expectedInstallation)),
() -> assertThat(installations.get(1), equalTo(expectedInstallation)));
}

private PreviousExtensionVersion createPreviousVersion() {
return setup.previousVersionManager().newVersion().currentVersion(PROJECT_VERSION) //
.previousVersion(PREVIOUS_VERSION) //
.adapterFileName(PREVIOUS_VERSION_JAR_FILE) //
.extensionFileName(EXTENSION_ID) //
.project("cloud-storage-extension") //
.build();
}

private void verifyExportImportWorks() throws SQLException {
final ExasolSchema schema = exasolObjectFactory.createSchema("TESTING_SCHEMA_" + System.currentTimeMillis());
final String bucket = s3setup.createBucket();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/exasol/cloudetl/extension/S3Setup.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private S3Setup(final LocalStackContainer container) {
static S3Setup create() {
@SuppressWarnings("resource")
final LocalStackContainer container = new LocalStackContainer(
DockerImageName.parse("localstack/localstack:2.0")).withServices(Service.S3).withReuse(true);
DockerImageName.parse("localstack/localstack:2.2")).withServices(Service.S3).withReuse(true);
container.start();
return new S3Setup(container);
}
Expand Down

0 comments on commit 9be45aa

Please sign in to comment.