|
33 | 33 | import com.treasuredata.client.model.TDExportFileFormatType; |
34 | 34 | import com.treasuredata.client.model.TDExportJobRequest; |
35 | 35 | import com.treasuredata.client.model.TDExportResultJobRequest; |
| 36 | +import com.treasuredata.client.model.TDFederatedQueryConfig; |
36 | 37 | import com.treasuredata.client.model.TDImportResult; |
37 | 38 | import com.treasuredata.client.model.TDJob; |
38 | 39 | import com.treasuredata.client.model.TDJob.EngineVersion; |
|
111 | 112 | import static org.hamcrest.MatcherAssert.assertThat; |
112 | 113 | import static org.junit.jupiter.api.Assertions.assertEquals; |
113 | 114 | import static org.junit.jupiter.api.Assertions.assertFalse; |
| 115 | +import static org.junit.jupiter.api.Assertions.assertIterableEquals; |
114 | 116 | import static org.junit.jupiter.api.Assertions.assertThrows; |
115 | 117 | import static org.junit.jupiter.api.Assertions.assertTrue; |
116 | 118 | import static org.junit.jupiter.api.Assertions.fail; |
@@ -1958,6 +1960,178 @@ public void testImportBytesWithId() |
1958 | 1960 | assertEquals(result.getUniqueId(), "4288048cf8f811e88b560a87157ac806"); |
1959 | 1961 | } |
1960 | 1962 |
|
| 1963 | + @Test |
| 1964 | + public void testGetFederatedQueryConfigsWhenEmpty() |
| 1965 | + throws Exception |
| 1966 | + { |
| 1967 | + client = mockClient(); |
| 1968 | + server.enqueue(new MockResponse().setBody("[]")); |
| 1969 | + |
| 1970 | + List<TDFederatedQueryConfig> result = client.getFederatedQueryConfigs(); |
| 1971 | + |
| 1972 | + assertTrue(result.isEmpty()); |
| 1973 | + } |
| 1974 | + |
| 1975 | + @Test |
| 1976 | + public void testGetFederatedQueryConfigsWhenOnlyOne() |
| 1977 | + throws Exception |
| 1978 | + { |
| 1979 | + client = mockClient(); |
| 1980 | + final String federatedQueryConfigs = "[\n" + |
| 1981 | + " {\n" + |
| 1982 | + " \"id\": 12345,\n" + |
| 1983 | + " \"type\": \"custom_type\",\n" + |
| 1984 | + " \"user_id\": 67890,\n" + |
| 1985 | + " \"account_id\": 54321,\n" + |
| 1986 | + " \"name\": \"test_name\",\n" + |
| 1987 | + " \"connection_id\": 112233,\n" + |
| 1988 | + " \"created_at\": \"2023-06-01T00:00:00Z\",\n" + |
| 1989 | + " \"updated_at\": \"2023-06-15T00:00:00Z\",\n" + |
| 1990 | + " \"settings\": {\n" + |
| 1991 | + " \"account_name\": \"snowflake_account\",\n" + |
| 1992 | + " \"auth_method\": \"password\",\n" + |
| 1993 | + " \"private_key\": \"encrypted_key\",\n" + |
| 1994 | + " \"passphrase\": \"secret_phrase\",\n" + |
| 1995 | + " \"options\": {\n" + |
| 1996 | + " \"key1\": \"val1\",\n" + |
| 1997 | + " \"key2\": \"val2\"\n" + |
| 1998 | + " },\n" + |
| 1999 | + " \"user\": \"snowflake_user\",\n" + |
| 2000 | + " \"password\": \"snowflake_password\",\n" + |
| 2001 | + " \"database\": \"sample_database\"\n" + |
| 2002 | + " }\n" + |
| 2003 | + " }\n" + |
| 2004 | + "]"; |
| 2005 | + server.enqueue(new MockResponse().setBody(federatedQueryConfigs)); |
| 2006 | + |
| 2007 | + List<TDFederatedQueryConfig> result = client.getFederatedQueryConfigs(); |
| 2008 | + |
| 2009 | + Map<String, Object> settings = new HashMap<>(); |
| 2010 | + settings.put("account_name", "snowflake_account"); |
| 2011 | + settings.put("auth_method", "password"); |
| 2012 | + settings.put("private_key", "encrypted_key"); |
| 2013 | + settings.put("passphrase", "secret_phrase"); |
| 2014 | + Map<String, Object> options = new HashMap<>(); |
| 2015 | + options.put("key1", "val1"); |
| 2016 | + options.put("key2", "val2"); |
| 2017 | + settings.put("options", options); |
| 2018 | + settings.put("user", "snowflake_user"); |
| 2019 | + settings.put("password", "snowflake_password"); |
| 2020 | + settings.put("database", "sample_database"); |
| 2021 | + |
| 2022 | + List<TDFederatedQueryConfig> expected = Arrays.asList( |
| 2023 | + new TDFederatedQueryConfig(12345, "custom_type", 67890, 54321, "test_name", 112233, "2023-06-01T00:00:00Z", "2023-06-15T00:00:00Z", settings) |
| 2024 | + ); |
| 2025 | + assertIterableEquals(result, expected); |
| 2026 | + } |
| 2027 | + |
| 2028 | + @Test |
| 2029 | + public void testGetFederatedQueryConfigsWhenMultiple() |
| 2030 | + throws Exception |
| 2031 | + { |
| 2032 | + client = mockClient(); |
| 2033 | + final String federatedQueryConfigs = "[\n" + |
| 2034 | + " {\n" + |
| 2035 | + " \"id\": 12345,\n" + |
| 2036 | + " \"type\": \"custom_type\",\n" + |
| 2037 | + " \"user_id\": 67890,\n" + |
| 2038 | + " \"account_id\": 54321,\n" + |
| 2039 | + " \"name\": \"test_name\",\n" + |
| 2040 | + " \"connection_id\": 112233,\n" + |
| 2041 | + " \"created_at\": \"2023-06-01T00:00:00Z\",\n" + |
| 2042 | + " \"updated_at\": \"2023-06-15T00:00:00Z\",\n" + |
| 2043 | + " \"settings\": {\n" + |
| 2044 | + " \"account_name\": \"snowflake_account\",\n" + |
| 2045 | + " \"auth_method\": \"password\",\n" + |
| 2046 | + " \"private_key\": \"encrypted_key\",\n" + |
| 2047 | + " \"passphrase\": \"secret_phrase\",\n" + |
| 2048 | + " \"options\": {\n" + |
| 2049 | + " \"key1\": \"val1\",\n" + |
| 2050 | + " \"key2\": \"val2\"\n" + |
| 2051 | + " },\n" + |
| 2052 | + " \"user\": \"snowflake_user\",\n" + |
| 2053 | + " \"password\": \"snowflake_password\",\n" + |
| 2054 | + " \"database\": \"sample_database\"\n" + |
| 2055 | + " }\n" + |
| 2056 | + " },\n" + |
| 2057 | + " {\n" + |
| 2058 | + " \"id\": 67890,\n" + |
| 2059 | + " \"type\": \"another_type\",\n" + |
| 2060 | + " \"user_id\": 12345,\n" + |
| 2061 | + " \"account_id\": 98765,\n" + |
| 2062 | + " \"name\": \"another_test_name\",\n" + |
| 2063 | + " \"connection_id\": 445566,\n" + |
| 2064 | + " \"created_at\": \"2023-07-01T00:00:00Z\",\n" + |
| 2065 | + " \"updated_at\": \"2023-07-15T00:00:00Z\",\n" + |
| 2066 | + " \"settings\": {\n" + |
| 2067 | + " \"account_name\": \"another_snowflake_account\",\n" + |
| 2068 | + " \"auth_method\": \"oauth\",\n" + |
| 2069 | + " \"private_key\": \"another_encrypted_key\",\n" + |
| 2070 | + " \"passphrase\": \"another_secret_phrase\",\n" + |
| 2071 | + " \"options\": {\n" + |
| 2072 | + " \"keyA\": \"valA\",\n" + |
| 2073 | + " \"keyB\": \"valB\"\n" + |
| 2074 | + " },\n" + |
| 2075 | + " \"user\": \"another_snowflake_user\",\n" + |
| 2076 | + " \"password\": \"another_snowflake_password\",\n" + |
| 2077 | + " \"database\": \"another_sample_database\"\n" + |
| 2078 | + " }\n" + |
| 2079 | + " }\n" + |
| 2080 | + "]"; |
| 2081 | + server.enqueue(new MockResponse().setBody(federatedQueryConfigs)); |
| 2082 | + |
| 2083 | + List<TDFederatedQueryConfig> result = client.getFederatedQueryConfigs(); |
| 2084 | + |
| 2085 | + Map<String, Object> settings1 = new HashMap<>(); |
| 2086 | + settings1.put("account_name", "snowflake_account"); |
| 2087 | + settings1.put("auth_method", "password"); |
| 2088 | + settings1.put("private_key", "encrypted_key"); |
| 2089 | + settings1.put("passphrase", "secret_phrase"); |
| 2090 | + Map<String, Object> options1 = new HashMap<>(); |
| 2091 | + options1.put("key1", "val1"); |
| 2092 | + options1.put("key2", "val2"); |
| 2093 | + settings1.put("options", options1); |
| 2094 | + settings1.put("user", "snowflake_user"); |
| 2095 | + settings1.put("password", "snowflake_password"); |
| 2096 | + settings1.put("database", "sample_database"); |
| 2097 | + |
| 2098 | + Map<String, Object> settings2 = new HashMap<>(); |
| 2099 | + settings2.put("account_name", "another_snowflake_account"); |
| 2100 | + settings2.put("auth_method", "oauth"); |
| 2101 | + settings2.put("private_key", "another_encrypted_key"); |
| 2102 | + settings2.put("passphrase", "another_secret_phrase"); |
| 2103 | + Map<String, Object> options2 = new HashMap<>(); |
| 2104 | + options2.put("keyA", "valA"); |
| 2105 | + options2.put("keyB", "valB"); |
| 2106 | + settings2.put("options", options2); |
| 2107 | + settings2.put("user", "another_snowflake_user"); |
| 2108 | + settings2.put("password", "another_snowflake_password"); |
| 2109 | + settings2.put("database", "another_sample_database"); |
| 2110 | + |
| 2111 | + List<TDFederatedQueryConfig> expected = Arrays.asList( |
| 2112 | + new TDFederatedQueryConfig(12345, "custom_type", 67890, 54321, "test_name", 112233, "2023-06-01T00:00:00Z", "2023-06-15T00:00:00Z", settings1), |
| 2113 | + new TDFederatedQueryConfig(67890, "another_type", 12345, 98765, "another_test_name", 445566, "2023-07-01T00:00:00Z", "2023-07-15T00:00:00Z", settings2) |
| 2114 | + ); |
| 2115 | + assertIterableEquals(result, expected); |
| 2116 | + } |
| 2117 | + |
| 2118 | + @Test |
| 2119 | + public void testGetFederatedQueryConfigsWhenAuthenticationFail() |
| 2120 | + throws Exception |
| 2121 | + { |
| 2122 | + TDClient client = TDClient.newBuilder().setApiKey("1/xxfasdfafd").build(); // Set a wrong API key |
| 2123 | + server.enqueue(new MockResponse().setBody("[]")); |
| 2124 | + |
| 2125 | + try { |
| 2126 | + List<TDFederatedQueryConfig> result = client.getFederatedQueryConfigs(); |
| 2127 | + fail("should not reach here"); |
| 2128 | + } |
| 2129 | + catch (TDClientHttpUnauthorizedException e) { |
| 2130 | + // OK |
| 2131 | + assertEquals(HttpStatus.UNAUTHORIZED_401, e.getStatusCode()); |
| 2132 | + } |
| 2133 | + } |
| 2134 | + |
1961 | 2135 | private File createTempMsgpackGz(String prefix, int numRows) |
1962 | 2136 | throws IOException |
1963 | 2137 | { |
|
0 commit comments