|
| 1 | +/* |
| 2 | + * Copyright 2026 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.cloud.bigquery.jdbc; |
| 18 | + |
| 19 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 20 | +import static org.mockito.ArgumentMatchers.any; |
| 21 | +import static org.mockito.Mockito.mock; |
| 22 | +import static org.mockito.Mockito.verify; |
| 23 | +import static org.mockito.Mockito.when; |
| 24 | + |
| 25 | +import com.google.api.gax.core.NoCredentialsProvider; |
| 26 | +import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient; |
| 27 | +import com.google.cloud.bigquery.storage.v1.BigQueryWriteSettings; |
| 28 | +import com.google.cloud.bigquery.storage.v1.CreateWriteStreamRequest; |
| 29 | +import com.google.cloud.bigquery.storage.v1.TableName; |
| 30 | +import com.google.cloud.bigquery.storage.v1.TableSchema; |
| 31 | +import com.google.cloud.bigquery.storage.v1.WriteStream; |
| 32 | +import org.junit.jupiter.api.Test; |
| 33 | + |
| 34 | +public class BigQueryJdbcBulkInsertWriterTest { |
| 35 | + |
| 36 | + @Test |
| 37 | + public void testInitializePassesClientToJsonStreamWriter() throws Exception { |
| 38 | + BigQueryWriteClient mockClient = mock(BigQueryWriteClient.class); |
| 39 | + BigQueryWriteSettings mockSettings = |
| 40 | + BigQueryWriteSettings.newBuilder() |
| 41 | + .setCredentialsProvider(NoCredentialsProvider.create()) |
| 42 | + .build(); |
| 43 | + when(mockClient.getSettings()).thenReturn(mockSettings); |
| 44 | + |
| 45 | + WriteStream stream = |
| 46 | + WriteStream.newBuilder() |
| 47 | + .setName( |
| 48 | + "projects/test-project/datasets/test_dataset/tables/test_table/streams/_default") |
| 49 | + .setTableSchema(TableSchema.newBuilder().build()) |
| 50 | + .build(); |
| 51 | + when(mockClient.createWriteStream(any(CreateWriteStreamRequest.class))).thenReturn(stream); |
| 52 | + |
| 53 | + TableName tableName = TableName.of("test-project", "test_dataset", "test_table"); |
| 54 | + BigQueryJdbcBulkInsertWriter writer = new BigQueryJdbcBulkInsertWriter(); |
| 55 | + writer.initialize(tableName, mockClient, null); |
| 56 | + |
| 57 | + assertNotNull(writer.getStreamName()); |
| 58 | + verify(mockClient).getSettings(); |
| 59 | + } |
| 60 | +} |
0 commit comments