@@ -36,14 +36,14 @@ public class GrantViewAccessIT {
36
36
37
37
private final Logger log = Logger .getLogger (this .getClass ().getName ());
38
38
private String datasetName ;
39
+ private String viewDatasetName ;
39
40
private String tableName ;
40
41
private String viewName ;
41
42
private ByteArrayOutputStream bout ;
42
43
private PrintStream out ;
43
44
private PrintStream originalPrintStream ;
44
45
45
46
private static final String PROJECT_ID = requireEnvVar ("GOOGLE_CLOUD_PROJECT" );
46
- private static final String BIGQUERY_DATASET_NAME = requireEnvVar ("BIGQUERY_DATASET_NAME" );
47
47
48
48
private static String requireEnvVar (String varName ) {
49
49
String value = System .getenv (varName );
@@ -56,7 +56,6 @@ private static String requireEnvVar(String varName) {
56
56
@ BeforeClass
57
57
public static void checkRequirements () {
58
58
requireEnvVar ("GOOGLE_CLOUD_PROJECT" );
59
- requireEnvVar ("BIGQUERY_DATASET_NAME" );
60
59
}
61
60
62
61
@ Before
@@ -68,30 +67,32 @@ public void setUp() {
68
67
69
68
// create a temporary dataset, table and view to be deleted.
70
69
datasetName = "MY_DATASET_NAME_TEST_" + UUID .randomUUID ().toString ().substring (0 , 8 );
70
+ viewDatasetName = "MY_VIEW_DATASET_NAME_TEST_" + UUID .randomUUID ().toString ().substring (0 , 8 );
71
71
tableName = "MY_TABLE_NAME_TEST_" + UUID .randomUUID ().toString ().substring (0 , 8 );
72
72
viewName = "MY_VIEW_NAME_TEST_" + UUID .randomUUID ().toString ().substring (0 , 8 );
73
73
74
74
CreateDataset .createDataset (datasetName );
75
+ CreateDataset .createDataset (viewDatasetName );
75
76
76
77
Schema schema =
77
78
Schema .of (
78
79
Field .of ("timestampField" , StandardSQLTypeName .TIMESTAMP ),
79
80
Field .of ("stringField" , StandardSQLTypeName .STRING ),
80
81
Field .of ("booleanField" , StandardSQLTypeName .BOOL ));
81
- CreateTable .createTable (BIGQUERY_DATASET_NAME , tableName , schema );
82
+ CreateTable .createTable (viewDatasetName , tableName , schema );
82
83
83
84
String query =
84
85
String .format (
85
86
"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 );
88
89
}
89
90
90
91
@ After
91
92
public void tearDown () {
92
93
// 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 );
95
96
DeleteDataset .deleteDataset (PROJECT_ID , datasetName );
96
97
// restores print statements in the original method
97
98
System .out .flush ();
@@ -101,7 +102,7 @@ public void tearDown() {
101
102
102
103
@ Test
103
104
public void testGrantViewAccess () {
104
- GrantViewAccess .grantViewAccess (datasetName , BIGQUERY_DATASET_NAME , viewName );
105
+ GrantViewAccess .grantViewAccess (datasetName , viewDatasetName , viewName );
105
106
assertThat (bout .toString ()).contains ("Grant view access successfully" );
106
107
}
107
108
}
0 commit comments