-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d0ed00
commit 1b843dc
Showing
1 changed file
with
43 additions
and
44 deletions.
There are no files selected for viewing
87 changes: 43 additions & 44 deletions
87
src/test/java/net/snowflake/client/core/SqlInputTimestampUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,53 @@ | ||
package net.snowflake.client.core; | ||
|
||
import net.snowflake.client.jdbc.SnowflakeUtil; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
import static org.junit.Assert.*; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.TimeZone; | ||
|
||
import static org.junit.Assert.*; | ||
import net.snowflake.client.jdbc.SnowflakeUtil; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
public class SqlInputTimestampUtilTest { | ||
|
||
private static final String TIMESTAMP_IN_FORMAT_1 = "2021-12-22 09:43:44.000 +0100"; | ||
private static final String TIMESTAMP_IN_FORMAT_2 = "Wed, 22 Dec 2021 09:43:44 +0100"; | ||
private static final Map<String, Object> CONNECTION_PARAMS = new HashMap<>(); | ||
private static final Timestamp EXPECTED_TIMESTAMP = Timestamp.valueOf("2021-12-22 09:43:44.0"); | ||
|
||
private static SFBaseSession mockSession; | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
CONNECTION_PARAMS.put("TIMESTAMP_OUTPUT_FORMAT", "YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM"); | ||
CONNECTION_PARAMS.put("TIMESTAMP_TZ_OUTPUT_FORMAT", "DY, DD MON YYYY HH24:MI:SS TZHTZM"); | ||
mockSession = Mockito.mock(SFBaseSession.class); | ||
Mockito.when(mockSession.getCommonParameters()).thenReturn(CONNECTION_PARAMS); | ||
} | ||
|
||
@Test | ||
public void shouldGetTimestampForLtzType() { | ||
//when | ||
Timestamp resultLtz = getFromType(SnowflakeUtil.EXTRA_TYPES_TIMESTAMP_LTZ, TIMESTAMP_IN_FORMAT_1, null); | ||
Timestamp resultTz = getFromType(SnowflakeUtil.EXTRA_TYPES_TIMESTAMP_TZ, TIMESTAMP_IN_FORMAT_2, null); | ||
Timestamp resultNtz = getFromType(SnowflakeUtil.EXTRA_TYPES_TIMESTAMP_NTZ, TIMESTAMP_IN_FORMAT_1, TimeZone.getTimeZone("EST")); | ||
|
||
assertEquals(EXPECTED_TIMESTAMP, resultLtz); | ||
assertEquals(EXPECTED_TIMESTAMP, resultTz); | ||
assertEquals(EXPECTED_TIMESTAMP, resultNtz); | ||
} | ||
|
||
private Timestamp getFromType(int type, String value, TimeZone explicitTimezone) { | ||
return SqlInputTimestampUtil.getTimestampFromType( | ||
type, | ||
value, | ||
mockSession, | ||
TimeZone.getTimeZone("UTC"), | ||
explicitTimezone | ||
); | ||
} | ||
|
||
} | ||
private static final String TIMESTAMP_IN_FORMAT_1 = "2021-12-22 09:43:44.000 +0100"; | ||
private static final String TIMESTAMP_IN_FORMAT_2 = "Wed, 22 Dec 2021 09:43:44 +0100"; | ||
private static final Map<String, Object> CONNECTION_PARAMS = new HashMap<>(); | ||
private static final Timestamp EXPECTED_TIMESTAMP = Timestamp.valueOf("2021-12-22 09:43:44.0"); | ||
|
||
private static SFBaseSession mockSession; | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
CONNECTION_PARAMS.put("TIMESTAMP_OUTPUT_FORMAT", "YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM"); | ||
CONNECTION_PARAMS.put("TIMESTAMP_TZ_OUTPUT_FORMAT", "DY, DD MON YYYY HH24:MI:SS TZHTZM"); | ||
mockSession = Mockito.mock(SFBaseSession.class); | ||
Mockito.when(mockSession.getCommonParameters()).thenReturn(CONNECTION_PARAMS); | ||
} | ||
|
||
@Test | ||
public void shouldGetTimestampForLtzType() { | ||
// when | ||
Timestamp resultLtz = | ||
getFromType(SnowflakeUtil.EXTRA_TYPES_TIMESTAMP_LTZ, TIMESTAMP_IN_FORMAT_1, null); | ||
Timestamp resultTz = | ||
getFromType(SnowflakeUtil.EXTRA_TYPES_TIMESTAMP_TZ, TIMESTAMP_IN_FORMAT_2, null); | ||
Timestamp resultNtz = | ||
getFromType( | ||
SnowflakeUtil.EXTRA_TYPES_TIMESTAMP_NTZ, | ||
TIMESTAMP_IN_FORMAT_1, | ||
TimeZone.getTimeZone("EST")); | ||
|
||
assertEquals(EXPECTED_TIMESTAMP, resultLtz); | ||
assertEquals(EXPECTED_TIMESTAMP, resultTz); | ||
assertEquals(EXPECTED_TIMESTAMP, resultNtz); | ||
} | ||
|
||
private Timestamp getFromType(int type, String value, TimeZone explicitTimezone) { | ||
return SqlInputTimestampUtil.getTimestampFromType( | ||
type, value, mockSession, TimeZone.getTimeZone("UTC"), explicitTimezone); | ||
} | ||
} |