Skip to content

Commit

Permalink
Use our own GUITestExtension class
Browse files Browse the repository at this point in the history
  • Loading branch information
janblom committed Jan 2, 2024
1 parent ce6cdd0 commit 0f8c042
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public void openReport() throws URISyntaxException {
fileChooser.selectFile(new File(Objects.requireNonNull(scanReportUrl).toURI())).approve();
}

@GUITest
@Test
public void openAndVerifySavedETLSpecs() throws URISyntaxException {
// open the test ETL specification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void onSetUp() {
@Container
public static PostgreSQLContainer<?> postgreSQL = createPostgreSQLContainer();

@GUITest
@ExtendWith(GUITestExtension.class)
@Test
void testConnectionAndSourceDataScan(@TempDir Path tempDir) throws IOException, URISyntaxException {
URL referenceScanReport = TestSourceDataScanCsvGui.class.getClassLoader().getResource("scan_data/ScanReport-reference-v0.10.7-sql.xlsx");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.assertj.swing.finder.WindowFinder;
import org.assertj.swing.fixture.DialogFixture;
import org.assertj.swing.fixture.FrameFixture;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -83,10 +84,10 @@ public void onSetUp() {
window.show(); // shows the frame to test
}

@GUITest
@ExtendWith(GUITestExtension.class)
@Test
@EnabledIfEnvironmentVariable(named = SNOWFLAKE_ACCOUNT_ENVIRONMENT_VARIABLE, matches = ".+")
void testConnectionAndSourceDataScan(@TempDir Path tempDir) throws IOException, URISyntaxException {
Assumptions.assumeTrue(new SnowflakeTestUtils.SnowflakeSystemPropertiesFileChecker(), "Snowflake system properties file not available");
URL referenceScanReport = TestSourceDataScanCsvGui.class.getClassLoader().getResource("scan_data/ScanReport-reference-v0.10.7-sql.xlsx");
Path personCsv = Paths.get(TestSourceDataScanCsvGui.class.getClassLoader().getResource("scan_data/person-no-header.csv").toURI());
Path costCsv = Paths.get(TestSourceDataScanCsvGui.class.getClassLoader().getResource("scan_data/cost-no-header.csv").toURI());
Expand All @@ -109,12 +110,12 @@ protected boolean isMatching(JDialog frame) {

// fill in all the required values and try again
assertEquals(SnowflakeConfiguration.TOOLTIP_SNOWFLAKE_ACCOUNT, window.textBox(SnowflakeConfiguration.SNOWFLAKE_ACCOUNT).target().getToolTipText());
window.textBox(SnowflakeConfiguration.SNOWFLAKE_ACCOUNT).setText(SnowflakeTestUtils.getEnvOrFail("SNOWFLAKE_WR_TEST_ACCOUNT"));
window.textBox(SnowflakeConfiguration.SNOWFLAKE_USER).setText(SnowflakeTestUtils.getEnvOrFail("SNOWFLAKE_WR_TEST_USER"));
window.textBox(SnowflakeConfiguration.SNOWFLAKE_PASSWORD).setText(SnowflakeTestUtils.getEnvOrFail("SNOWFLAKE_WR_TEST_PASSWORD"));
window.textBox(SnowflakeConfiguration.SNOWFLAKE_WAREHOUSE).setText(SnowflakeTestUtils.getEnvOrFail("SNOWFLAKE_WR_TEST_WAREHOUSE"));
window.textBox(SnowflakeConfiguration.SNOWFLAKE_DATABASE).setText(SnowflakeTestUtils.getEnvOrFail("SNOWFLAKE_WR_TEST_DATABASE"));
window.textBox(SnowflakeConfiguration.SNOWFLAKE_SCHEMA).setText(SnowflakeTestUtils.getEnvOrFail("SNOWFLAKE_WR_TEST_SCHEMA"));
window.textBox(SnowflakeConfiguration.SNOWFLAKE_ACCOUNT).setText(SnowflakeTestUtils.getPropertyOrFail("SNOWFLAKE_WR_TEST_ACCOUNT"));
window.textBox(SnowflakeConfiguration.SNOWFLAKE_USER).setText(SnowflakeTestUtils.getPropertyOrFail("SNOWFLAKE_WR_TEST_USER"));
window.textBox(SnowflakeConfiguration.SNOWFLAKE_PASSWORD).setText(SnowflakeTestUtils.getPropertyOrFail("SNOWFLAKE_WR_TEST_PASSWORD"));
window.textBox(SnowflakeConfiguration.SNOWFLAKE_WAREHOUSE).setText(SnowflakeTestUtils.getPropertyOrFail("SNOWFLAKE_WR_TEST_WAREHOUSE"));
window.textBox(SnowflakeConfiguration.SNOWFLAKE_DATABASE).setText(SnowflakeTestUtils.getPropertyOrFail("SNOWFLAKE_WR_TEST_DATABASE"));
window.textBox(SnowflakeConfiguration.SNOWFLAKE_SCHEMA).setText(SnowflakeTestUtils.getPropertyOrFail("SNOWFLAKE_WR_TEST_SCHEMA"));

// use the "Test connection" button
window.button(WhiteRabbitMain.LABEL_TEST_CONNECTION).click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.ohdsi.whiterabbit.scan;

import org.apache.commons.lang.StringUtils;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
Expand Down Expand Up @@ -63,7 +64,7 @@ public void setUp() {
}
}

@Test
//@Test
void testWarnWhenRunningWithoutSnowflakeConfigured() {
String snowflakeWrTestAccunt = System.getenv(SNOWFLAKE_ACCOUNT_ENVIRONMENT_VARIABLE);
assertFalse(StringUtils.isEmpty(snowflakeWrTestAccunt) && StringUtils.isEmpty(System.getProperty("ohdsi.org.whiterabbit.skip_snowflake_tests")),
Expand All @@ -72,29 +73,33 @@ void testWarnWhenRunningWithoutSnowflakeConfigured() {
}

@Test
@EnabledIfEnvironmentVariable(named = SNOWFLAKE_ACCOUNT_ENVIRONMENT_VARIABLE, matches = ".+")
//@EnabledIfEnvironmentVariable(named = SNOWFLAKE_ACCOUNT_ENVIRONMENT_VARIABLE, matches = ".+")
void testProcessSnowflakeFromIni(@TempDir Path tempDir) throws URISyntaxException, IOException {
Assumptions.assumeTrue(new SnowflakeTestUtils.SnowflakeSystemPropertiesFileChecker(), "Snowflake system properties file not available");
Charset charset = StandardCharsets.UTF_8;
Path iniFile = tempDir.resolve("snowflake.ini");
URL iniTemplate = SourceDataScanSnowflakeIT.class.getClassLoader().getResource("scan_data/snowflake.ini.template");
URL referenceScanReport = SourceDataScanSnowflakeIT.class.getClassLoader().getResource("scan_data/ScanReport-reference-v0.10.7-sql.xlsx");
assert iniTemplate != null;
String content = new String(Files.readAllBytes(Paths.get(iniTemplate.toURI())), charset);
content = content.replaceAll("%WORKING_FOLDER%", tempDir.toString())
.replaceAll("%SNOWFLAKE_ACCOUNT%", SnowflakeTestUtils.getEnvOrFail("SNOWFLAKE_WR_TEST_ACCOUNT"))
.replaceAll("%SNOWFLAKE_USER%", SnowflakeTestUtils.getEnvOrFail("SNOWFLAKE_WR_TEST_USER"))
.replaceAll("%SNOWFLAKE_PASSWORD%", SnowflakeTestUtils.getEnvOrFail("SNOWFLAKE_WR_TEST_PASSWORD"))
.replaceAll("%SNOWFLAKE_WAREHOUSE%", SnowflakeTestUtils.getEnvOrFail("SNOWFLAKE_WR_TEST_WAREHOUSE"))
.replaceAll("%SNOWFLAKE_DATABASE%", SnowflakeTestUtils.getEnvOrFail("SNOWFLAKE_WR_TEST_DATABASE"))
.replaceAll("%SNOWFLAKE_SCHEMA%", SnowflakeTestUtils.getEnvOrFail("SNOWFLAKE_WR_TEST_SCHEMA"));
.replaceAll("%SNOWFLAKE_ACCOUNT%", SnowflakeTestUtils.getPropertyOrFail("SNOWFLAKE_WR_TEST_ACCOUNT"))
.replaceAll("%SNOWFLAKE_USER%", SnowflakeTestUtils.getPropertyOrFail("SNOWFLAKE_WR_TEST_USER"))
.replaceAll("%SNOWFLAKE_PASSWORD%", SnowflakeTestUtils.getPropertyOrFail("SNOWFLAKE_WR_TEST_PASSWORD"))
.replaceAll("%SNOWFLAKE_WAREHOUSE%", SnowflakeTestUtils.getPropertyOrFail("SNOWFLAKE_WR_TEST_WAREHOUSE"))
.replaceAll("%SNOWFLAKE_DATABASE%", SnowflakeTestUtils.getPropertyOrFail("SNOWFLAKE_WR_TEST_DATABASE"))
.replaceAll("%SNOWFLAKE_SCHEMA%", SnowflakeTestUtils.getPropertyOrFail("SNOWFLAKE_WR_TEST_SCHEMA"));
Files.write(iniFile, content.getBytes(charset));
WhiteRabbitMain wrMain = new WhiteRabbitMain(true, new String[]{"-ini", iniFile.toAbsolutePath().toString()});
assert referenceScanReport != null;
assertTrue(ScanTestUtils.scanResultsSheetMatchesReference(tempDir.resolve("ScanReport.xlsx"), Paths.get(referenceScanReport.toURI()), DbType.SNOWFLAKE));
}

static void prepareTestData(GenericContainer<?> container) throws IOException, InterruptedException {
prepareTestData(container, new SnowflakeTestUtils.EnvironmentReader());
SnowflakeTestUtils.SnowflakeSystemPropertiesFileChecker checker = new SnowflakeTestUtils.SnowflakeSystemPropertiesFileChecker();
if (checker.getAsBoolean()) {
prepareTestData(container, new SnowflakeTestUtils.PropertyReader());
}
}

static void prepareTestData(GenericContainer<?> container, SnowflakeTestUtils.ReaderInterface reader) throws IOException, InterruptedException {
Expand Down

0 comments on commit 0f8c042

Please sign in to comment.