Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
3fa101d
Additional Tests for code coverage.
sfc-gh-ext-simba-vb Feb 10, 2025
b45eec4
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Feb 20, 2025
472f51a
Added tests for code coverage.
sfc-gh-ext-simba-vb Feb 20, 2025
4efcb8e
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Mar 2, 2025
faf1bae
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Mar 4, 2025
3c32bb1
Code coverage added for StorageProviderException class.
sfc-gh-ext-simba-vb Mar 4, 2025
b02716c
Code cov file added.
sfc-gh-ext-simba-vb Mar 5, 2025
72ecc7f
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Mar 11, 2025
edfd096
Code coverage added for log package.
sfc-gh-ext-simba-vb Mar 11, 2025
be64d98
Formatted the java files.
sfc-gh-ext-simba-vb Mar 11, 2025
6ddb478
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Mar 12, 2025
36830e6
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Mar 24, 2025
1ba2343
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Apr 15, 2025
8707273
Junit tests added to increase the code coverage.
sfc-gh-ext-simba-vb Apr 16, 2025
2bc0b76
reverting due to version compatibility.
sfc-gh-ext-simba-vb Apr 16, 2025
f4d929f
Fixed the Checkstyle errors.
sfc-gh-ext-simba-vb Apr 16, 2025
e4df842
Code reverted due to JVM version incompatibility.
sfc-gh-ext-simba-vb Apr 16, 2025
ef4bbed
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Apr 16, 2025
911b03d
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Apr 17, 2025
b11dcc5
Review comments implemented.
sfc-gh-ext-simba-vb Apr 17, 2025
95f9d3a
Build failure addressed.
sfc-gh-ext-simba-vb Apr 17, 2025
b0c7c89
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Apr 22, 2025
b8ed58f
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Apr 29, 2025
7a2b1dc
Merge branch 'SNOW-1016470-increase-code-coverage-to-at-least-90' of …
sfc-gh-ext-simba-vb Apr 29, 2025
7c3b5bd
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb May 13, 2025
affed29
Merge branch 'SNOW-1016470-increase-code-coverage-to-at-least-90' of …
sfc-gh-ext-simba-vb May 13, 2025
f54df02
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb May 14, 2025
bcb11d0
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb May 14, 2025
d881ae7
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb May 29, 2025
92ede36
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Jun 11, 2025
991aedc
Review comments implemented.
sfc-gh-ext-simba-vb Jun 11, 2025
0aaf661
Merge branch 'SNOW-1016470-increase-code-coverage-to-at-least-90' of …
sfc-gh-ext-simba-vb Jun 11, 2025
0add3db
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Jun 17, 2025
3161fbe
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Jun 17, 2025
f2d64ad
Build issue resolved.
sfc-gh-ext-simba-vb Jun 17, 2025
c55ce67
Merge branch 'SNOW-1016470-increase-code-coverage-to-at-least-90' of …
sfc-gh-ext-simba-vb Jun 17, 2025
1ed179e
External browser changes reverted due to browser issue.
sfc-gh-ext-simba-vb Jun 17, 2025
f760b52
initial commit.
sfc-gh-ext-simba-vb Jun 18, 2025
6ac7c26
checkstyle correction.
sfc-gh-ext-simba-vb Jun 18, 2025
9f2cf69
Merge branch 'master' into SNOW-1943242-jdbc-caches-closeablehttpclie…
sfc-gh-ext-simba-vb Jun 25, 2025
185c9d3
Http client cache management and re initialization implementation.
sfc-gh-ext-simba-vb Jun 27, 2025
675d2d7
added class
sfc-gh-ext-simba-vb Jun 27, 2025
4d367a1
Modified tests.
sfc-gh-ext-simba-vb Jun 27, 2025
7f22457
Merge branch 'master' into SNOW-1943242-jdbc-caches-closeablehttpclie…
sfc-gh-ext-simba-vb Jul 4, 2025
05c72c3
Junit tests added.
sfc-gh-ext-simba-vb Jul 4, 2025
9152bb0
Merge branch 'master' into SNOW-1943242-jdbc-caches-closeablehttpclie…
sfc-gh-ext-simba-vb Jul 9, 2025
4ef5839
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Jul 9, 2025
2321d92
Merge branch 'master' into SNOW-1943242-jdbc-caches-closeablehttpclie…
sfc-gh-ext-simba-vb Jul 10, 2025
f959c04
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Jul 10, 2025
f865ceb
Merge branch 'master' into SNOW-1943242-jdbc-caches-closeablehttpclie…
sfc-gh-ext-simba-hx Jul 16, 2025
653fa54
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Jul 16, 2025
88b4ccb
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Jul 18, 2025
e2029e2
Merge branch 'SNOW-1943242-jdbc-caches-closeablehttpclient-indefinite…
sfc-gh-ext-simba-vb Jul 18, 2025
0e7c4e9
check style
sfc-gh-ext-simba-vb Jul 18, 2025
f505aa1
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Jul 21, 2025
86ebee4
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Jul 23, 2025
aa01508
Merge branch 'SNOW-1016470-increase-code-coverage-to-at-least-90' of …
sfc-gh-ext-simba-vb Jul 23, 2025
63bd5cb
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Aug 1, 2025
cf465b4
Corrected the code.
sfc-gh-ext-simba-vb Aug 6, 2025
d54dd89
Reverting the code
sfc-gh-ext-simba-vb Aug 6, 2025
5d4d464
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Aug 6, 2025
0e9bf94
Fixing compile failure.
sfc-gh-ext-simba-vb Aug 6, 2025
73f9ee9
Reverting URLutil code for test purpose.
sfc-gh-ext-simba-vb Aug 11, 2025
b29da4d
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Aug 11, 2025
3817455
UrlUTil modification.
sfc-gh-ext-simba-vb Aug 12, 2025
4fa99b5
Merge branch 'SNOW-1016470-increase-code-coverage-to-at-least-90' of …
sfc-gh-ext-simba-vb Aug 12, 2025
2b7e176
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Aug 12, 2025
4b3dd71
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Aug 13, 2025
f51d336
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Aug 14, 2025
1a76157
Review comments addressed.
sfc-gh-ext-simba-vb Aug 14, 2025
7b15f82
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Aug 20, 2025
c181f3e
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Aug 21, 2025
50c6120
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Aug 26, 2025
dff8fe0
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Aug 28, 2025
8f21858
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Aug 28, 2025
6e8c600
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Sep 3, 2025
38018ef
Merge branch 'master' of https://github.com/snowflakedb/snowflake-jdb…
sfc-gh-ext-simba-vb Sep 4, 2025
966a7c8
Merge branch 'SNOW-1016470-increase-code-coverage-to-at-least-90' of …
sfc-gh-ext-simba-vb Sep 4, 2025
88f43b5
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Sep 4, 2025
f137512
Merge branch 'SNOW-1016470-increase-code-coverage-to-at-least-90' of …
sfc-gh-ext-simba-vb Sep 5, 2025
e11e38f
reduced line.
sfc-gh-ext-simba-vb Sep 6, 2025
aa68fbd
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Sep 8, 2025
1030d08
Revert the code due to linux failure
sfc-gh-ext-simba-vb Sep 8, 2025
12cb0e8
Merge branch 'master' into SNOW-1016470-increase-code-coverage-to-at-…
sfc-gh-ext-simba-vb Sep 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/net/snowflake/client/core/URLUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class URLUtil {
static final Pattern pattern = Pattern.compile(validURLPattern);

public static boolean isValidURL(String url) {
if (url == null) {
return false;
}
try {
Matcher matcher = pattern.matcher(url);
return matcher.find();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public Exception getOriginalProviderException() {

/**
* Returns true if this is an exception corresponding to a HTTP 404 error returned by the storage
* provider
* provider.
*
* @return true if the specified exception is an AmazonServiceException instance and if it was
* thrown because of a 404, false otherwise.
*/
public boolean isServiceException404() {
if ((Exception) this instanceof AmazonServiceException) {
AmazonServiceException asEx = (AmazonServiceException) ((java.lang.Exception) this);
if (getCause() instanceof AmazonServiceException) {
AmazonServiceException asEx = (AmazonServiceException) getCause();
return (asEx.getStatusCode() == HttpStatus.SC_NOT_FOUND);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static net.snowflake.client.jdbc.SnowflakeUtil.systemSetEnv;
import static net.snowflake.client.jdbc.SnowflakeUtil.systemUnsetEnv;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -141,4 +142,64 @@ public void testConvertToWindowsPath() {
mockCloudPrefix + resultWindowsPath,
convertToWindowsPath(mockCloudPrefix + mockWindowsPath));
}

@Test
void testSFClientConfigConstructorAndAccessors() {
SFClientConfig.CommonProps props = new SFClientConfig.CommonProps();
props.setLogLevel("DEBUG");
props.setLogPath("/tmp/logs");

SFClientConfig config = new SFClientConfig(props);
config.setConfigFilePath("/etc/snowflake/config.json");

assertEquals(props, config.getCommonProps());
assertEquals("/etc/snowflake/config.json", config.getConfigFilePath());
}

@Test
void testCommonPropsConstructorAndAccessors() {
SFClientConfig.CommonProps props = new SFClientConfig.CommonProps();
props.setLogLevel("DEBUG");
props.setLogPath("/var/logs/snowflake.log");

assertEquals("DEBUG", props.getLogLevel());
assertEquals("/var/logs/snowflake.log", props.getLogPath());
}

@Test
void testSFClientConfigEqualsAndHashCode() {
SFClientConfig.CommonProps props1 = new SFClientConfig.CommonProps();
props1.setLogLevel("INFO");
props1.setLogPath("/tmp");

SFClientConfig.CommonProps props2 = new SFClientConfig.CommonProps();
props2.setLogLevel("INFO");
props2.setLogPath("/tmp");
SFClientConfig config1 = new SFClientConfig(props1);
SFClientConfig config2 = new SFClientConfig(props2);

assertEquals(config1, config2);
assertEquals(config1.hashCode(), config2.hashCode());

// Negative test
props2.setLogLevel("DEBUG");
assertNotEquals(config1, new SFClientConfig(props2));
}

@Test
void testCommonPropsEqualsAndHashCode() {
SFClientConfig.CommonProps props1 = new SFClientConfig.CommonProps();
props1.setLogLevel("WARN");
props1.setLogPath("/opt/logs");
SFClientConfig.CommonProps props2 = new SFClientConfig.CommonProps();
props2.setLogLevel("WARN");
props2.setLogPath("/opt/logs");

assertEquals(props1, props2);
assertEquals(props1.hashCode(), props2.hashCode());

// Negative test
props2.setLogLevel("ERROR");
assertNotEquals(props1, props2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package net.snowflake.client.core;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

class QueryContextEntryDTOTest {

@Mock private OpaqueContextDTO mockContext;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}

@Test
void testDefaultConstructor() {
QueryContextEntryDTO entry = new QueryContextEntryDTO();
assertNotNull(entry);
assertEquals(0, entry.getId());
assertEquals(0, entry.getTimestamp());
assertEquals(0, entry.getPriority());
assertNull(entry.getContext());
}

@Test
void testParameterizedConstructor() {
QueryContextEntryDTO entry = new QueryContextEntryDTO(1L, 100L, 10L, mockContext);

assertEquals(1L, entry.getId());
assertEquals(100L, entry.getTimestamp());
assertEquals(10L, entry.getPriority());
assertEquals(mockContext, entry.getContext());
}

@Test
void testSettersAndGetters() {
QueryContextEntryDTO entry = new QueryContextEntryDTO();

entry.setId(2L);
entry.setTimestamp(200L);
entry.setPriority(20L);
entry.setContext(mockContext);

assertEquals(2L, entry.getId());
assertEquals(200L, entry.getTimestamp());
assertEquals(20L, entry.getPriority());
assertEquals(mockContext, entry.getContext());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.snowflake.client.core;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -14,6 +15,7 @@
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -166,6 +168,25 @@ public void testSessionUtilExternalBrowser() throws Throwable {
sub.authenticate();
MatcherAssert.assertThat(
"", sub.getToken(), equalTo(FakeSessionUtilExternalBrowser.MOCK_SAML_TOKEN));

sub = FakeSessionUtilExternalBrowser.createInstance(loginInput, false);
Mockito.when(loginInput.getDisableConsoleLogin()).thenReturn(false);
sub.authenticate();
MatcherAssert.assertThat(
"", sub.getToken(), equalTo(FakeSessionUtilExternalBrowser.MOCK_SAML_TOKEN));

sub = FakeSessionUtilExternalBrowser.createInstance(loginInput, false);
Mockito.when(loginInput.getDisableConsoleLogin())
.thenAnswer(
invocation -> {
throw new SocketTimeoutException("Test exception");
});
try {
sub.authenticate();
fail("should have failed with an exception.");
} catch (SFException ex) {
assertTrue(ex.getMessage().contains("External browser authentication failed"));
}
}
}

Expand Down Expand Up @@ -286,4 +307,43 @@ public void testExternalBrowserTimeout() throws Exception {
});
assertTrue(e.getMessage().contains("External browser authentication failed"));
}

// @Test
// public void testSessionUtilExternalBrowserWithConsoleLogin() throws Throwable {
// SFLoginInput loginInput = mock(SFLoginInput.class);
// when(loginInput.getServerUrl()).thenReturn("https://testaccount.snowflakecomputing.com/");
// when(loginInput.getAuthenticator())
// .thenReturn(ClientAuthnDTO.AuthenticatorType.EXTERNALBROWSER.name());
// when(loginInput.getAccountName()).thenReturn("testaccount");
// when(loginInput.getUserName()).thenReturn("testuser");
// when(loginInput.getDisableConsoleLogin()).thenReturn(false);
//
// try (MockedStatic<HttpUtil> mockedHttpUtil = mockStatic(HttpUtil.class)) {
// mockedHttpUtil
// .when(
// () ->
// HttpUtil.executeGeneralRequest(
// Mockito.any(HttpRequestBase.class),
// Mockito.anyInt(),
// Mockito.anyInt(),
// Mockito.anyInt(),
// Mockito.anyInt(),
// Mockito.nullable(HttpClientSettingsKey.class)))
// .thenReturn(
// "{\"success\":\"true\",\"data\":{\"proofKey\":\""
// + MOCK_PROOF_KEY
// + "\","
// + " \"ssoUrl\":\""
// + MOCK_SSO_URL
// + "\"}}");
//
// SessionUtilExternalBrowser sub = FakeSessionUtilExternalBrowser.createInstance(loginInput);
// sub.authenticate();
// assertThat("", sub.getToken(), equalTo(FakeSessionUtilExternalBrowser.MOCK_SAML_TOKEN));
//
// sub = FakeSessionUtilExternalBrowser.createInstance(loginInput, true);
// sub.authenticate();
// assertThat("", sub.getToken(), equalTo(FakeSessionUtilExternalBrowser.MOCK_SAML_TOKEN));
// }
// }
}
29 changes: 29 additions & 0 deletions src/test/java/net/snowflake/client/core/URLUtilTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package net.snowflake.client.core;

import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.UnsupportedEncodingException;
import org.junit.jupiter.api.Test;

public class URLUtilTest {
Expand All @@ -27,4 +29,31 @@ public void testEncodeURL() throws Exception {
assertEquals(URLUtil.urlEncode("Hello @World"), "Hello+%40World");
assertEquals(URLUtil.urlEncode("Test//String"), "Test%2F%2FString");
}

@Test
void testIsValidURL_InvalidCases() {
assertFalse(URLUtil.isValidURL("htp://invalid-url"));
assertFalse(URLUtil.isValidURL("://missing-protocol.com"));
assertFalse(URLUtil.isValidURL("https:/missing-slash.com"));
assertFalse(URLUtil.isValidURL("https://"));
assertFalse(URLUtil.isValidURL(""));
assertFalse(URLUtil.isValidURL(null));
}

@Test
void testUrlEncode_ValidString() throws UnsupportedEncodingException {
String input = "hello world!";
String expected = "hello+world%21"; // URLEncoder replaces spaces with '+'
assertEquals(expected, URLUtil.urlEncode(input));
}

@Test
void testUrlEncode_EmptyString() throws UnsupportedEncodingException {
assertEquals("", URLUtil.urlEncode(""));
}

@Test
void testUrlEncode_NullString() {
assertThrows(NullPointerException.class, () -> URLUtil.urlEncode(null));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.snowflake.client.core.auth.oauth;

import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class RandomStateProviderTest {

private RandomStateProvider randomStateProvider;

@BeforeEach
public void setUp() {
// Initialize the RandomStateProvider before each test
randomStateProvider = new RandomStateProvider();
}

@Test
public void testGetState_ShouldReturnNonNullState() {
// Call getState() and verify that it returns a non-null value
String state = randomStateProvider.getState();
assertNotNull(state, "State should not be null");
}

@Test
public void testGetState_ShouldReturnUniqueValues() {
// Ensure that the state is random and different each time
String state1 = randomStateProvider.getState();
String state2 = randomStateProvider.getState();

// Assert that the two generated states are different
assertNotEquals(state1, state2, "State should be different on subsequent calls");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.snowflake.client.core.auth.oauth;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

public class TokenResponseDTOTest {

private static final String JSON_SAMPLE =
"{"
+ "\"access_token\":\"abc123\","
+ "\"refresh_token\":\"refresh123\","
+ "\"token_type\":\"bearer\","
+ "\"scope\":\"read write\","
+ "\"username\":\"testUser\","
+ "\"idp_initiated\":true,"
+ "\"expires_in\":3600,"
+ "\"refresh_token_expires_in\":7200"
+ "}";

@Test
public void testConstructorAndGetters() {
TokenResponseDTO tokenResponseDTO =
new TokenResponseDTO(
"abc123", "refresh123", "bearer", "read write", "testUser", true, 3600, 7200);
// Assert that the constructor has correctly initialized the object
assertEquals("abc123", tokenResponseDTO.getAccessToken());
assertEquals("bearer", tokenResponseDTO.getTokenType());
assertEquals("refresh123", tokenResponseDTO.getRefreshToken());
assertEquals("read write", tokenResponseDTO.getScope());
assertEquals("testUser", tokenResponseDTO.getUsername());
assertTrue(tokenResponseDTO.isIdpInitiated());
assertEquals(3600, tokenResponseDTO.getExpiresIn());
assertEquals(7200, tokenResponseDTO.getRefreshTokenExpiresIn());
}

@Test
public void testJsonDeserialization() throws Exception {
// Create an ObjectMapper to convert JSON to TokenResponseDTO
ObjectMapper objectMapper = new ObjectMapper();

// Deserialize the JSON string into a TokenResponseDTO object
TokenResponseDTO deserializedTokenResponseDTO =
objectMapper.readValue(JSON_SAMPLE, TokenResponseDTO.class);

// Assert that the deserialized object matches the expected values
assertEquals("abc123", deserializedTokenResponseDTO.getAccessToken());
assertEquals("bearer", deserializedTokenResponseDTO.getTokenType());
assertEquals("refresh123", deserializedTokenResponseDTO.getRefreshToken());
assertEquals("read write", deserializedTokenResponseDTO.getScope());
assertEquals("testUser", deserializedTokenResponseDTO.getUsername());
assertTrue(deserializedTokenResponseDTO.isIdpInitiated());
assertEquals(3600, deserializedTokenResponseDTO.getExpiresIn());
assertEquals(7200, deserializedTokenResponseDTO.getRefreshTokenExpiresIn());
}
}
Loading