|
22 | 22 |
|
23 | 23 | import com.google.cloud.bigquery.JobInfo.CreateDisposition; |
24 | 24 | import com.google.cloud.bigquery.JobInfo.WriteDisposition; |
| 25 | +import com.google.common.base.Function; |
25 | 26 | import com.google.common.collect.ImmutableList; |
| 27 | +import com.google.common.collect.Lists; |
26 | 28 | import java.util.List; |
27 | 29 | import org.junit.Test; |
28 | 30 |
|
29 | 31 | public class CopyJobConfigurationTest { |
30 | 32 |
|
| 33 | + private static final String TEST_PROJECT_ID = "test-project-id"; |
31 | 34 | private static final TableId SOURCE_TABLE = TableId.of("dataset", "sourceTable"); |
32 | 35 | private static final List<TableId> SOURCE_TABLES = |
33 | 36 | ImmutableList.of( |
@@ -115,10 +118,34 @@ public void testToPbAndFromPb() { |
115 | 118 |
|
116 | 119 | @Test |
117 | 120 | public void testSetProjectId() { |
118 | | - CopyJobConfiguration configuration = COPY_JOB_CONFIGURATION_MULTIPLE_TABLES.setProjectId("p"); |
119 | | - assertEquals("p", configuration.getDestinationTable().getProject()); |
| 121 | + CopyJobConfiguration configuration = |
| 122 | + COPY_JOB_CONFIGURATION_MULTIPLE_TABLES.setProjectId(TEST_PROJECT_ID); |
| 123 | + assertEquals(TEST_PROJECT_ID, configuration.getDestinationTable().getProject()); |
120 | 124 | for (TableId sourceTable : configuration.getSourceTables()) { |
121 | | - assertEquals("p", sourceTable.getProject()); |
| 125 | + assertEquals(TEST_PROJECT_ID, sourceTable.getProject()); |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + @Test |
| 130 | + public void testSetProjectIdDoNotOverride() { |
| 131 | + CopyJobConfiguration configuration = |
| 132 | + COPY_JOB_CONFIGURATION_MULTIPLE_TABLES |
| 133 | + .toBuilder() |
| 134 | + .setSourceTables( |
| 135 | + Lists.transform( |
| 136 | + SOURCE_TABLES, |
| 137 | + new Function<TableId, TableId>() { |
| 138 | + @Override |
| 139 | + public TableId apply(TableId tableId) { |
| 140 | + return tableId.setProjectId(TEST_PROJECT_ID); |
| 141 | + } |
| 142 | + })) |
| 143 | + .setDestinationTable(DESTINATION_TABLE.setProjectId(TEST_PROJECT_ID)) |
| 144 | + .build() |
| 145 | + .setProjectId("do-not-update"); |
| 146 | + assertEquals(TEST_PROJECT_ID, configuration.getDestinationTable().getProject()); |
| 147 | + for (TableId sourceTable : configuration.getSourceTables()) { |
| 148 | + assertEquals(TEST_PROJECT_ID, sourceTable.getProject()); |
122 | 149 | } |
123 | 150 | } |
124 | 151 |
|
|
0 commit comments