@@ -812,6 +812,25 @@ public void testCreateTable() {
812
812
verify (bigqueryRpcMock ).create (tableInfo .toPb (), EMPTY_RPC_OPTIONS );
813
813
}
814
814
815
+ @ Test
816
+ public void tesCreateExternalTable () {
817
+ TableInfo createTableInfo =
818
+ TableInfo .of (TABLE_ID , ExternalTableDefinition .newBuilder ().setSchema (TABLE_SCHEMA ).build ())
819
+ .setProjectId (OTHER_PROJECT );
820
+
821
+ com .google .api .services .bigquery .model .Table expectedCreateInput =
822
+ createTableInfo .toPb ().setSchema (TABLE_SCHEMA .toPb ());
823
+ expectedCreateInput .getExternalDataConfiguration ().setSchema (null );
824
+ when (bigqueryRpcMock .create (expectedCreateInput , EMPTY_RPC_OPTIONS ))
825
+ .thenReturn (createTableInfo .toPb ());
826
+ BigQueryOptions bigQueryOptions =
827
+ createBigQueryOptionsForProject (OTHER_PROJECT , rpcFactoryMock );
828
+ bigquery = bigQueryOptions .getService ();
829
+ Table table = bigquery .create (createTableInfo );
830
+ assertEquals (new Table (bigquery , new TableInfo .BuilderImpl (createTableInfo )), table );
831
+ verify (bigqueryRpcMock ).create (expectedCreateInput , EMPTY_RPC_OPTIONS );
832
+ }
833
+
815
834
@ Test
816
835
public void testCreateTableWithoutProject () {
817
836
TableInfo tableInfo = TABLE_INFO .setProjectId (PROJECT );
@@ -1189,6 +1208,25 @@ public void testUpdateTable() {
1189
1208
verify (bigqueryRpcMock ).patch (updatedTableInfo .toPb (), EMPTY_RPC_OPTIONS );
1190
1209
}
1191
1210
1211
+ @ Test
1212
+ public void testUpdateExternalTableWithNewSchema () {
1213
+ TableInfo updatedTableInfo =
1214
+ TableInfo .of (TABLE_ID , ExternalTableDefinition .newBuilder ().setSchema (TABLE_SCHEMA ).build ())
1215
+ .setProjectId (OTHER_PROJECT );
1216
+
1217
+ com .google .api .services .bigquery .model .Table expectedPatchInput =
1218
+ updatedTableInfo .toPb ().setSchema (TABLE_SCHEMA .toPb ());
1219
+ expectedPatchInput .getExternalDataConfiguration ().setSchema (null );
1220
+ when (bigqueryRpcMock .patch (expectedPatchInput , EMPTY_RPC_OPTIONS ))
1221
+ .thenReturn (updatedTableInfo .toPb ());
1222
+ BigQueryOptions bigQueryOptions =
1223
+ createBigQueryOptionsForProject (OTHER_PROJECT , rpcFactoryMock );
1224
+ bigquery = bigQueryOptions .getService ();
1225
+ Table table = bigquery .update (updatedTableInfo );
1226
+ assertEquals (new Table (bigquery , new TableInfo .BuilderImpl (updatedTableInfo )), table );
1227
+ verify (bigqueryRpcMock ).patch (expectedPatchInput , EMPTY_RPC_OPTIONS );
1228
+ }
1229
+
1192
1230
@ Test
1193
1231
public void testUpdateTableWithoutProject () {
1194
1232
TableInfo tableInfo = TABLE_INFO .setProjectId (PROJECT );
0 commit comments