@@ -36,14 +36,14 @@ public class GrantViewAccessIT {
3636
3737 private final Logger log = Logger .getLogger (this .getClass ().getName ());
3838 private String datasetName ;
39+ private String viewDatasetName ;
3940 private String tableName ;
4041 private String viewName ;
4142 private ByteArrayOutputStream bout ;
4243 private PrintStream out ;
4344 private PrintStream originalPrintStream ;
4445
4546 private static final String PROJECT_ID = requireEnvVar ("GOOGLE_CLOUD_PROJECT" );
46- private static final String BIGQUERY_DATASET_NAME = requireEnvVar ("BIGQUERY_DATASET_NAME" );
4747
4848 private static String requireEnvVar (String varName ) {
4949 String value = System .getenv (varName );
@@ -56,7 +56,6 @@ private static String requireEnvVar(String varName) {
5656 @ BeforeClass
5757 public static void checkRequirements () {
5858 requireEnvVar ("GOOGLE_CLOUD_PROJECT" );
59- requireEnvVar ("BIGQUERY_DATASET_NAME" );
6059 }
6160
6261 @ Before
@@ -68,30 +67,32 @@ public void setUp() {
6867
6968 // create a temporary dataset, table and view to be deleted.
7069 datasetName = "MY_DATASET_NAME_TEST_" + UUID .randomUUID ().toString ().substring (0 , 8 );
70+ viewDatasetName = "MY_VIEW_DATASET_NAME_TEST_" + UUID .randomUUID ().toString ().substring (0 , 8 );
7171 tableName = "MY_TABLE_NAME_TEST_" + UUID .randomUUID ().toString ().substring (0 , 8 );
7272 viewName = "MY_VIEW_NAME_TEST_" + UUID .randomUUID ().toString ().substring (0 , 8 );
7373
7474 CreateDataset .createDataset (datasetName );
75+ CreateDataset .createDataset (viewDatasetName );
7576
7677 Schema schema =
7778 Schema .of (
7879 Field .of ("timestampField" , StandardSQLTypeName .TIMESTAMP ),
7980 Field .of ("stringField" , StandardSQLTypeName .STRING ),
8081 Field .of ("booleanField" , StandardSQLTypeName .BOOL ));
81- CreateTable .createTable (BIGQUERY_DATASET_NAME , tableName , schema );
82+ CreateTable .createTable (viewDatasetName , tableName , schema );
8283
8384 String query =
8485 String .format (
8586 "SELECT timestampField, stringField, booleanField FROM %s.%s" ,
86- BIGQUERY_DATASET_NAME , tableName );
87- CreateView .createView (BIGQUERY_DATASET_NAME , viewName , query );
87+ viewDatasetName , tableName );
88+ CreateView .createView (viewDatasetName , viewName , query );
8889 }
8990
9091 @ After
9192 public void tearDown () {
9293 // Clean up
93- DeleteTable .deleteTable (BIGQUERY_DATASET_NAME , viewName );
94- DeleteTable .deleteTable (BIGQUERY_DATASET_NAME , tableName );
94+ DeleteTable .deleteTable (viewDatasetName , viewName );
95+ DeleteTable .deleteTable (viewDatasetName , tableName );
9596 DeleteDataset .deleteDataset (PROJECT_ID , datasetName );
9697 // restores print statements in the original method
9798 System .out .flush ();
@@ -101,7 +102,7 @@ public void tearDown() {
101102
102103 @ Test
103104 public void testGrantViewAccess () {
104- GrantViewAccess .grantViewAccess (datasetName , BIGQUERY_DATASET_NAME , viewName );
105+ GrantViewAccess .grantViewAccess (datasetName , viewDatasetName , viewName );
105106 assertThat (bout .toString ()).contains ("Grant view access successfully" );
106107 }
107108}
0 commit comments