@@ -945,6 +945,57 @@ public TableDataInsertAllRequest.Rows apply(RowToInsert rowToInsert) {
945945 assertEquals ("ErrorMessage" , response .getErrorsFor (0L ).get (0 ).getMessage ());
946946 }
947947
948+ @ Test
949+ public void testInsertAllWithProjectInTable () {
950+ Map <String , Object > row1 = ImmutableMap .<String , Object >of ("field" , "value1" );
951+ Map <String , Object > row2 = ImmutableMap .<String , Object >of ("field" , "value2" );
952+ List <RowToInsert > rows =
953+ ImmutableList .of (new RowToInsert ("row1" , row1 ), new RowToInsert ("row2" , row2 ));
954+ TableId tableId = TableId .of ("project-different-from-option" , DATASET , TABLE );
955+ InsertAllRequest request =
956+ InsertAllRequest .newBuilder (tableId )
957+ .setRows (rows )
958+ .setSkipInvalidRows (false )
959+ .setIgnoreUnknownValues (true )
960+ .setTemplateSuffix ("suffix" )
961+ .build ();
962+ TableDataInsertAllRequest requestPb =
963+ new TableDataInsertAllRequest ()
964+ .setRows (
965+ Lists .transform (
966+ rows ,
967+ new Function <RowToInsert , TableDataInsertAllRequest .Rows >() {
968+ @ Override
969+ public TableDataInsertAllRequest .Rows apply (RowToInsert rowToInsert ) {
970+ return new TableDataInsertAllRequest .Rows ()
971+ .setInsertId (rowToInsert .getId ())
972+ .setJson (rowToInsert .getContent ());
973+ }
974+ }))
975+ .setSkipInvalidRows (false )
976+ .setIgnoreUnknownValues (true )
977+ .setTemplateSuffix ("suffix" );
978+ TableDataInsertAllResponse responsePb =
979+ new TableDataInsertAllResponse ()
980+ .setInsertErrors (
981+ ImmutableList .of (
982+ new TableDataInsertAllResponse .InsertErrors ()
983+ .setIndex (0L )
984+ .setErrors (ImmutableList .of (new ErrorProto ().setMessage ("ErrorMessage" )))));
985+ EasyMock .expect (
986+ bigqueryRpcMock .insertAll ("project-different-from-option" , DATASET , TABLE , requestPb ))
987+ .andReturn (responsePb );
988+ EasyMock .replay (bigqueryRpcMock );
989+ BigQueryOptions bigQueryOptions =
990+ createBigQueryOptionsForProject (OTHER_PROJECT , rpcFactoryMock );
991+ bigquery = bigQueryOptions .getService ();
992+ InsertAllResponse response = bigquery .insertAll (request );
993+ assertNotNull (response .getErrorsFor (0L ));
994+ assertNull (response .getErrorsFor (1L ));
995+ assertEquals (1 , response .getErrorsFor (0L ).size ());
996+ assertEquals ("ErrorMessage" , response .getErrorsFor (0L ).get (0 ).getMessage ());
997+ }
998+
948999 @ Test
9491000 public void testListTableData () {
9501001 EasyMock .expect (bigqueryRpcMock .listTableData (PROJECT , DATASET , TABLE , EMPTY_RPC_OPTIONS ))
0 commit comments