diff --git a/FIPS/src/test/java/net/snowflake/client/AbstractDriverIT.java b/FIPS/src/test/java/net/snowflake/client/AbstractDriverIT.java index 05c389208..360a1fcbb 100644 --- a/FIPS/src/test/java/net/snowflake/client/AbstractDriverIT.java +++ b/FIPS/src/test/java/net/snowflake/client/AbstractDriverIT.java @@ -21,12 +21,10 @@ import java.util.TimeZone; import java.util.logging.Level; import java.util.logging.Logger; -import org.junit.Rule; /** Base test class with common constants, data structures and methods */ public class AbstractDriverIT { // This is required to use ConditionalIgnore annotation. - @Rule public ConditionalIgnoreRule rule = new ConditionalIgnoreRule(); public static final String DRIVER_CLASS = "net.snowflake.client.jdbc.SnowflakeDriver"; public static final String DRIVER_CLASS_COM = "com.snowflake.client.jdbc.SnowflakeDriver"; diff --git a/FIPS/src/test/java/net/snowflake/client/ConditionalIgnoreRule.java b/FIPS/src/test/java/net/snowflake/client/ConditionalIgnoreRule.java deleted file mode 100644 index fe20883db..000000000 --- a/FIPS/src/test/java/net/snowflake/client/ConditionalIgnoreRule.java +++ /dev/null @@ -1,125 +0,0 @@ -package net.snowflake.client; - -/* - * Created by hyu on 1/22/18. - */ - -/* -Copyright (c) 2013,2014 RĂ¼diger Herrmann -All rights reserved. This program and the accompanying materials -are made available under the terms of the Eclipse Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/epl-v10.html - -Contributors: -RĂ¼diger Herrmann - initial API and implementation -Matt Morrissette - allow to use non-static inner IgnoreConditions -*/ - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.lang.reflect.Modifier; -import org.junit.Assume; -import org.junit.rules.MethodRule; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.Statement; - -public class ConditionalIgnoreRule implements MethodRule { - - public interface IgnoreCondition { - boolean isSatisfied(); - } - - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD}) - public @interface ConditionalIgnore { - Class condition(); - } - - @Override - public Statement apply(Statement base, FrameworkMethod method, Object target) { - Statement result = base; - if (hasConditionalIgnoreAnnotation(method)) { - IgnoreCondition condition = getIgnoreCondition(target, method); - if (condition.isSatisfied()) { - result = new IgnoreStatement(condition); - } - } - return result; - } - - private static boolean hasConditionalIgnoreAnnotation(FrameworkMethod method) { - return method.getAnnotation(ConditionalIgnore.class) != null; - } - - private static IgnoreCondition getIgnoreCondition(Object target, FrameworkMethod method) { - ConditionalIgnore annotation = method.getAnnotation(ConditionalIgnore.class); - return new IgnoreConditionCreator(target, annotation).create(); - } - - private static class IgnoreConditionCreator { - private final Object target; - private final Class conditionType; - - IgnoreConditionCreator(Object target, ConditionalIgnore annotation) { - this.target = target; - this.conditionType = annotation.condition(); - } - - IgnoreCondition create() { - checkConditionType(); - try { - return createCondition(); - } catch (RuntimeException re) { - throw re; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private IgnoreCondition createCondition() throws Exception { - IgnoreCondition result; - if (isConditionTypeStandalone()) { - result = conditionType.newInstance(); - } else { - result = conditionType.getDeclaredConstructor(target.getClass()).newInstance(target); - } - return result; - } - - private void checkConditionType() { - if (!isConditionTypeStandalone() && !isConditionTypeDeclaredInTarget()) { - String msg = - "Conditional class '%s' is a member class " - + "but was not declared inside the test case using it.\n" - + "Either make this class a static class, " - + "standalone class (by declaring it in it's own file) " - + "or move it inside the test case using it"; - throw new IllegalArgumentException(String.format(msg, conditionType.getName())); - } - } - - private boolean isConditionTypeStandalone() { - return !conditionType.isMemberClass() || Modifier.isStatic(conditionType.getModifiers()); - } - - private boolean isConditionTypeDeclaredInTarget() { - return target.getClass().isAssignableFrom(conditionType.getDeclaringClass()); - } - } - - private static class IgnoreStatement extends Statement { - private final IgnoreCondition condition; - - IgnoreStatement(IgnoreCondition condition) { - this.condition = condition; - } - - @Override - public void evaluate() { - Assume.assumeTrue("Ignored by " + condition.getClass().getSimpleName(), false); - } - } -} diff --git a/FIPS/src/test/java/net/snowflake/client/DontRunOnGCP.java b/FIPS/src/test/java/net/snowflake/client/DontRunOnGCP.java new file mode 100644 index 000000000..654f5436a --- /dev/null +++ b/FIPS/src/test/java/net/snowflake/client/DontRunOnGCP.java @@ -0,0 +1,12 @@ +package net.snowflake.client.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@DisabledIfEnvironmentVariable(named = "CLOUD_PROVIDER", matches = "(?i)GCP(?-i)") +public @interface DontRunOnGCP {} \ No newline at end of file diff --git a/FIPS/src/test/java/net/snowflake/client/DontRunOnGithubActions.java b/FIPS/src/test/java/net/snowflake/client/DontRunOnGithubActions.java new file mode 100644 index 000000000..49eef9617 --- /dev/null +++ b/FIPS/src/test/java/net/snowflake/client/DontRunOnGithubActions.java @@ -0,0 +1,12 @@ +package net.snowflake.client.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@DisabledIfEnvironmentVariable(named = "GITHUB_ACTIONS", matches = ".*") +public @interface DontRunOnGithubActions {} diff --git a/FIPS/src/test/java/net/snowflake/client/RunningOnGCP.java b/FIPS/src/test/java/net/snowflake/client/RunningOnGCP.java deleted file mode 100644 index 7e1132c9d..000000000 --- a/FIPS/src/test/java/net/snowflake/client/RunningOnGCP.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2012-2024 Snowflake Computing Inc. All right reserved. - */ -package net.snowflake.client; - -/** Run tests only on specified cloud provider or ignore */ -public class RunningOnGCP { - public boolean isSatisfied() { - String cloudProvider = TestUtil.systemGetEnv("CLOUD_PROVIDER"); - return cloudProvider != null && cloudProvider.equalsIgnoreCase("GCP"); - } -} diff --git a/FIPS/src/test/java/net/snowflake/client/RunningOnGithubActions.java b/FIPS/src/test/java/net/snowflake/client/RunningOnGithubActions.java deleted file mode 100644 index 20d708e6a..000000000 --- a/FIPS/src/test/java/net/snowflake/client/RunningOnGithubActions.java +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2012-2019 Snowflake Computing Inc. All right reserved. - */ -package net.snowflake.client; - -/** Run tests on CI */ -public class RunningOnGithubActions { - public boolean isSatisfied() { - return TestUtil.systemGetEnv("GITHUB_ACTIONS") != null; - } -} diff --git a/FIPS/src/test/java/net/snowflake/client/RunningOnWinMac.java b/FIPS/src/test/java/net/snowflake/client/RunningOnWinMac.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/FIPS/src/test/java/net/snowflake/client/jdbc/ConnectionFipsIT.java b/FIPS/src/test/java/net/snowflake/client/jdbc/ConnectionFipsIT.java index 367240ac1..19a30dfdf 100644 --- a/FIPS/src/test/java/net/snowflake/client/jdbc/ConnectionFipsIT.java +++ b/FIPS/src/test/java/net/snowflake/client/jdbc/ConnectionFipsIT.java @@ -3,8 +3,6 @@ */ package net.snowflake.client.jdbc; -import static org.junit.Assert.*; - import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; @@ -29,9 +27,9 @@ import org.bouncycastle.crypto.CryptoServicesRegistrar; import org.bouncycastle.crypto.fips.FipsStatus; import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; //@Category(TestCategoryFips.class) @@ -106,7 +104,7 @@ public class ConnectionFipsIT extends AbstractDriverIT { private static int JCE_PROVIDER_SUN_JCE_PROVIDER_POSITION; private static int JCE_PROVIDER_SUN_RSA_SIGN_PROVIDER_POSITION; - @BeforeClass + @BeforeAll public static void setup() throws Exception { System.setProperty("javax.net.debug", "ssl"); // get keystore types for BouncyCastle libraries @@ -166,7 +164,7 @@ public static void setup() throws Exception { // connectToGoogle(); } - @AfterClass + @AfterAll public static void teardown() throws Exception { // Remove BouncyCastle FIPS Provider Security.removeProvider(JCE_PROVIDER_BOUNCY_CASTLE_FIPS); @@ -227,7 +225,7 @@ public void connectWithFips() throws SQLException { } @Test - @ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGithubActions.class) + @DontRunOnGithubActions public void connectWithFipsKeyPair() throws Exception { Map parameters = getConnectionParameters(); String testUser = parameters.get("user"); @@ -256,7 +254,7 @@ public void connectWithFipsKeyPair() throws Exception { } @Test - @ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGithubActions.class) + @DontRunOnGithubActions public void testConnectUsingKeyPair() throws Exception { Map parameters = getConnectionParameters(); String testUser = parameters.get("user"); @@ -295,7 +293,7 @@ public void testConnectUsingKeyPair() throws Exception { * Currently ignored execution on GCP due to exception thrown "SSlException Could not generate XDH keypair" */ @Test - @ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGCP.class) + @DontRunOnGCP public void connectWithFipsAndQuery() throws SQLException { try (Connection con = getConnection()) { Statement statement = con.createStatement(); @@ -329,7 +327,7 @@ public void connectWithFipsAndPut() throws Exception { /** Added in > 3.15.1 */ @Test - @ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGithubActions.class) + @DontRunOnGithubActions public void connectWithFipsKeyPairWithBouncyCastle() throws Exception { System.setProperty(SecurityUtil.ENABLE_BOUNCYCASTLE_PROVIDER_JVM, "true"); connectWithFipsKeyPair(); @@ -337,7 +335,7 @@ public void connectWithFipsKeyPairWithBouncyCastle() throws Exception { /** Added in > 3.15.1 */ @Test - @ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGithubActions.class) + @DontRunOnGithubActions public void testConnectUsingKeyPairWithBouncyCastle() throws Exception { System.setProperty(SecurityUtil.ENABLE_BOUNCYCASTLE_PROVIDER_JVM, "true"); testConnectUsingKeyPair(); diff --git a/src/test/java/net/snowflake/client/annotations/RunOnAzure.java b/src/test/java/net/snowflake/client/annotations/RunOnAzure.java index 2cc2d58f7..757c79836 100644 --- a/src/test/java/net/snowflake/client/annotations/RunOnAzure.java +++ b/src/test/java/net/snowflake/client/annotations/RunOnAzure.java @@ -4,9 +4,9 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) -@DisabledIfEnvironmentVariable(named = "CLOUD_PROVIDER", matches = "(?i)Azure(?-i)") +@EnabledIfEnvironmentVariable(named = "CLOUD_PROVIDER", matches = "(?i)Azure(?-i)") public @interface RunOnAzure {} diff --git a/src/test/java/net/snowflake/client/annotations/RunOnGCP.java b/src/test/java/net/snowflake/client/annotations/RunOnGCP.java index 7732879d4..18b10b52e 100644 --- a/src/test/java/net/snowflake/client/annotations/RunOnGCP.java +++ b/src/test/java/net/snowflake/client/annotations/RunOnGCP.java @@ -4,9 +4,9 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) -@DisabledIfEnvironmentVariable(named = "CLOUD_PROVIDER", matches = "(?i)GCP(?-i)") +@EnabledIfEnvironmentVariable(named = "CLOUD_PROVIDER", matches = "(?i)GCP(?-i)") public @interface RunOnGCP {}