1616
1717package com .google .cloud .bigquery ;
1818
19+ import static com .google .common .truth .Truth .assertThat ;
1920import static org .easymock .EasyMock .capture ;
2021import static org .easymock .EasyMock .eq ;
2122import static org .junit .Assert .assertArrayEquals ;
@@ -90,21 +91,16 @@ public class BigQueryImplTest {
9091 private static final TableId OTHER_TABLE_ID = TableId .of (PROJECT , DATASET , OTHER_TABLE );
9192 private static final TableId TABLE_ID_WITH_PROJECT = TableId .of (PROJECT , DATASET , TABLE );
9293 private static final Field FIELD_SCHEMA1 =
93- Field .newBuilder ("StringField " , LegacySQLTypeName .STRING )
94+ Field .newBuilder ("BooleanField " , LegacySQLTypeName .BOOLEAN )
9495 .setMode (Field .Mode .NULLABLE )
9596 .setDescription ("FieldDescription1" )
9697 .build ();
9798 private static final Field FIELD_SCHEMA2 =
9899 Field .newBuilder ("IntegerField" , LegacySQLTypeName .INTEGER )
99- .setMode (Field .Mode .REPEATED )
100+ .setMode (Field .Mode .NULLABLE )
100101 .setDescription ("FieldDescription2" )
101102 .build ();
102- private static final Field FIELD_SCHEMA3 =
103- Field .newBuilder ("RecordField" , LegacySQLTypeName .RECORD , FIELD_SCHEMA1 , FIELD_SCHEMA2 )
104- .setMode (Field .Mode .REQUIRED )
105- .setDescription ("FieldDescription3" )
106- .build ();
107- private static final Schema TABLE_SCHEMA = Schema .of (FIELD_SCHEMA1 , FIELD_SCHEMA2 , FIELD_SCHEMA3 );
103+ private static final Schema TABLE_SCHEMA = Schema .of (FIELD_SCHEMA1 , FIELD_SCHEMA2 );
108104 private static final StandardTableDefinition TABLE_DEFINITION =
109105 StandardTableDefinition .of (TABLE_SCHEMA );
110106 private static final TableInfo TABLE_INFO = TableInfo .of (TABLE_ID , TABLE_DEFINITION );
@@ -1125,7 +1121,8 @@ public void testQueryRequestCompleted() throws InterruptedException {
11251121 .setCacheHit (false )
11261122 .setPageToken (CURSOR )
11271123 .setTotalBytesProcessed (42L )
1128- .setTotalRows (BigInteger .valueOf (1L ));
1124+ .setTotalRows (BigInteger .valueOf (1L ))
1125+ .setSchema (TABLE_SCHEMA .toPb ());
11291126
11301127 EasyMock .expect (
11311128 bigqueryRpcMock .create (JOB_INFO .toPb (), Collections .<BigQueryRpc .Option , Object >emptyMap ()))
@@ -1143,25 +1140,27 @@ public void testQueryRequestCompleted() throws InterruptedException {
11431140 bigqueryRpcMock .getJob (
11441141 PROJECT , JOB , Collections .<BigQueryRpc .Option , Object >emptyMap ()))
11451142 .andReturn (jobResponsePb );
1143+ EasyMock .expect (
1144+ bigqueryRpcMock .getQueryResults (
1145+ PROJECT , JOB , BigQueryImpl .optionMap (Job .DEFAULT_QUERY_WAIT_OPTIONS )))
1146+ .andReturn (responsePb );
11461147 EasyMock .expect (
11471148 bigqueryRpcMock .listTableData (
11481149 PROJECT , DATASET , TABLE , Collections .<BigQueryRpc .Option , Object >emptyMap ()))
11491150 .andReturn (Tuple .<String , Iterable <TableRow >>of ("" , ImmutableList .of (TABLE_ROW )));
11501151
11511152 EasyMock .replay (bigqueryRpcMock );
11521153 bigquery = options .getService ();
1153- // TODO(pongad) revert back to QueryResult
1154- Page <FieldValueList > result =
1154+ QueryResult result =
11551155 bigquery
11561156 .query (QUERY_JOB_CONFIGURATION_FOR_QUERY , queryJob )
11571157 .getQueryResults (QueryResultsOption .pageSize (42L ));
1158- // assertEquals(null, result.getSchema());
1159- // assertEquals(1L, result.getTotalRows());
1158+ assertThat ( result .getSchema ()). isEqualTo ( TABLE_SCHEMA );
1159+ assertThat ( result .getTotalRows ()). isEqualTo ( 1 );
11601160 for (FieldValueList row : result .getValues ()) {
1161- assertEquals ( false , row .get (0 ).getBooleanValue ());
1162- assertEquals ( 1L , row .get (1 ).getLongValue ());
1161+ assertThat ( row .get (0 ).getBooleanValue ()). isFalse ( );
1162+ assertThat ( row .get (1 ).getLongValue ()). isEqualTo ( 1 );
11631163 }
1164- // assertEquals(CURSOR, result.getNextPageToken());
11651164 }
11661165
11671166 @ Test
@@ -1192,7 +1191,8 @@ public void testQueryRequestCompletedOnSecondAttempt() throws InterruptedExcepti
11921191 .setCacheHit (false )
11931192 .setPageToken (CURSOR )
11941193 .setTotalBytesProcessed (42L )
1195- .setTotalRows (BigInteger .valueOf (1L ));
1194+ .setTotalRows (BigInteger .valueOf (1L ))
1195+ .setSchema (TABLE_SCHEMA .toPb ());
11961196
11971197 EasyMock .expect (
11981198 bigqueryRpcMock .create (
@@ -1215,25 +1215,27 @@ public void testQueryRequestCompletedOnSecondAttempt() throws InterruptedExcepti
12151215 bigqueryRpcMock .getJob (
12161216 PROJECT , JOB , Collections .<BigQueryRpc .Option , Object >emptyMap ()))
12171217 .andReturn (jobResponsePb2 );
1218+ EasyMock .expect (
1219+ bigqueryRpcMock .getQueryResults (
1220+ PROJECT , JOB , BigQueryImpl .optionMap (Job .DEFAULT_QUERY_WAIT_OPTIONS )))
1221+ .andReturn (responsePb2 );
12181222 EasyMock .expect (
12191223 bigqueryRpcMock .listTableData (
12201224 PROJECT , DATASET , TABLE , Collections .<BigQueryRpc .Option , Object >emptyMap ()))
12211225 .andReturn (Tuple .<String , Iterable <TableRow >>of ("" , ImmutableList .of (TABLE_ROW )));
12221226
12231227 EasyMock .replay (bigqueryRpcMock );
12241228 bigquery = options .getService ();
1225- // TODO(pongad) revert back to QueryResult
1226- Page <FieldValueList > result =
1229+ QueryResult result =
12271230 bigquery
12281231 .query (QUERY_JOB_CONFIGURATION_FOR_QUERY , queryJob )
12291232 .getQueryResults (QueryResultsOption .pageSize (42L ));
1230- // assertEquals(null, result.getSchema());
1231- // assertEquals(1L, result.getTotalRows());
1233+ assertThat ( result .getSchema ()). isEqualTo ( TABLE_SCHEMA );
1234+ assertThat ( result .getTotalRows ()). isEqualTo ( 1 );
12321235 for (FieldValueList row : result .getValues ()) {
1233- assertEquals ( false , row .get (0 ).getBooleanValue ());
1234- assertEquals ( 1L , row .get (1 ).getLongValue ());
1236+ assertThat ( row .get (0 ).getBooleanValue ()). isFalse ( );
1237+ assertThat ( row .get (1 ).getLongValue ()). isEqualTo ( 1 );
12351238 }
1236- // assertEquals(CURSOR, result.getNextPageToken());
12371239 }
12381240
12391241 @ Test
0 commit comments