Skip to content

Commit

Permalink
improve error handling in AuthTest
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-akolodziejczyk committed Dec 9, 2024
1 parent 53f72cf commit d6731a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
23 changes: 5 additions & 18 deletions src/test/java/net/snowflake/client/authentication/AuthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,11 @@ public AuthTest() {
}

public Thread getConnectAndExecuteSimpleQueryThread(Properties props, String sessionParameters) {
return new Thread(
() -> {
try {
connectAndExecuteSimpleQuery(props, sessionParameters);
} catch (Exception e) {
this.exception = e;
}
});
return new Thread(() -> connectAndExecuteSimpleQuery(props, sessionParameters));
}

public Thread getConnectAndExecuteSimpleQueryThread(Properties props) {
return new Thread(
() -> {
try {
connectAndExecuteSimpleQuery(props, null);
} catch (Exception e) {
this.exception = e;
}
});
return new Thread(() -> connectAndExecuteSimpleQuery(props, null));
}

public void verifyExceptionIsThrown(String message) {
Expand Down Expand Up @@ -100,8 +86,7 @@ public static void deleteIdToken() {
AuthConnectionParameters.HOST, AuthConnectionParameters.SSO_USER);
}

public void connectAndExecuteSimpleQuery(Properties props, String sessionParameters)
throws SQLException {
public void connectAndExecuteSimpleQuery(Properties props, String sessionParameters) {
String url = String.format("jdbc:snowflake://%s:%s", props.get("host"), props.get("port"));
if (sessionParameters != null) {
url += "?" + sessionParameters;
Expand All @@ -112,6 +97,8 @@ public void connectAndExecuteSimpleQuery(Properties props, String sessionParamet
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
saveToken(con);
} catch (SQLException e) {
this.exception = e;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static org.hamcrest.Matchers.notNullValue;

import java.io.IOException;
import java.sql.SQLException;
import net.snowflake.client.category.TestTags;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -57,7 +56,7 @@ void shouldAuthenticateUsingExternalBrowserAndSaveToken() throws InterruptedExce

@Test
@Order(2)
void shouldAuthenticateUsingTokenWithoutBrowser() throws SQLException {
void shouldAuthenticateUsingTokenWithoutBrowser() {
verifyFirstTokenWasSaved();
authTest.connectAndExecuteSimpleQuery(getStoreIDTokenConnectionParameters(), null);
authTest.verifyExceptionIsNotThrown();
Expand Down

0 comments on commit d6731a6

Please sign in to comment.