-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathBigQueryOptionsTest.java
More file actions
102 lines (85 loc) · 3.51 KB
/
Copy pathBigQueryOptionsTest.java
File metadata and controls
102 lines (85 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.bigquery;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.cloud.TransportOptions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
public class BigQueryOptionsTest {
@Test
void testInvalidTransport() {
IllegalArgumentException expected =
assertThrows(
IllegalArgumentException.class,
() ->
BigQueryOptions.newBuilder()
.setTransportOptions(Mockito.mock(TransportOptions.class)));
assertNotNull(expected.getMessage());
}
@Test
void dataFormatOptions_createdByDefault() {
BigQueryOptions options = BigQueryOptions.newBuilder().setProjectId("project-id").build();
assertNotNull(options.getDataFormatOptions());
assertFalse(options.getDataFormatOptions().useInt64Timestamp());
assertEquals(
DataFormatOptions.TimestampFormatOptions.TIMESTAMP_OUTPUT_FORMAT_UNSPECIFIED,
options.getDataFormatOptions().timestampFormatOptions());
}
@Test
void nonBuilderSetUseInt64Timestamp_capturedInDataFormatOptions() {
BigQueryOptions options =
BigQueryOptions.newBuilder()
.setDataFormatOptions(DataFormatOptions.newBuilder().useInt64Timestamp(false).build())
.setProjectId("project-id")
.build();
options.setUseInt64Timestamps(true);
assertTrue(options.getDataFormatOptions().useInt64Timestamp());
}
@Test
void nonBuilderSetUseInt64Timestamp_overridesEverything() {
BigQueryOptions options = BigQueryOptions.newBuilder().setProjectId("project-id").build();
options.setUseInt64Timestamps(true);
assertTrue(options.getDataFormatOptions().useInt64Timestamp());
}
@Test
void noDataFormatOptions_capturesUseInt64TimestampSetInBuilder() {
BigQueryOptions options =
BigQueryOptions.newBuilder().setUseInt64Timestamps(true).setProjectId("project-id").build();
assertTrue(options.getDataFormatOptions().useInt64Timestamp());
}
@Test
void dataFormatOptionsSetterHasPrecedence() {
BigQueryOptions options =
BigQueryOptions.newBuilder()
.setProjectId("project-id")
.setDataFormatOptions(DataFormatOptions.newBuilder().useInt64Timestamp(true).build())
.setUseInt64Timestamps(false)
.build();
assertTrue(options.getDataFormatOptions().useInt64Timestamp());
}
@Test
void testUseJwtAccessWithScope_defaultsToFalse() {
BigQueryOptions options = BigQueryOptions.newBuilder().setProjectId("project-id").build();
assertFalse(options.getUseJwtAccessWithScope());
}
}