/
AclTest.java
139 lines (126 loc) · 4.69 KB
/
AclTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Copyright 2015 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.bigquery;
import static org.junit.Assert.assertEquals;
import com.google.api.services.bigquery.model.Dataset;
import com.google.cloud.bigquery.Acl.DatasetAclEntity;
import com.google.cloud.bigquery.Acl.Domain;
import com.google.cloud.bigquery.Acl.Entity;
import com.google.cloud.bigquery.Acl.Entity.Type;
import com.google.cloud.bigquery.Acl.Group;
import com.google.cloud.bigquery.Acl.IamMember;
import com.google.cloud.bigquery.Acl.Role;
import com.google.cloud.bigquery.Acl.User;
import com.google.cloud.bigquery.Acl.View;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.junit.Test;
public class AclTest {
@Test
public void testDatasetEntity() {
DatasetId datasetId = DatasetId.of("dataset");
List<String> targetTypes = ImmutableList.of("VIEWS");
DatasetAclEntity entity = new DatasetAclEntity(datasetId, targetTypes);
assertEquals(datasetId, entity.getId());
assertEquals(targetTypes, entity.getTargetTypes());
Dataset.Access pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
}
@Test
public void testDomainEntity() {
Domain entity = new Domain("d1");
assertEquals("d1", entity.getDomain());
assertEquals(Type.DOMAIN, entity.getType());
Dataset.Access pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
}
@Test
public void testGroupEntity() {
Group entity = new Group("g1");
assertEquals("g1", entity.getIdentifier());
assertEquals(Type.GROUP, entity.getType());
Dataset.Access pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
}
@Test
public void testSpecialGroupEntity() {
Group entity = Group.ofAllAuthenticatedUsers();
assertEquals("allAuthenticatedUsers", entity.getIdentifier());
Dataset.Access pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
entity = Group.ofProjectWriters();
assertEquals("projectWriters", entity.getIdentifier());
pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
entity = Group.ofProjectReaders();
assertEquals("projectReaders", entity.getIdentifier());
pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
entity = Group.ofProjectOwners();
assertEquals("projectOwners", entity.getIdentifier());
pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
}
@Test
public void testUserEntity() {
User entity = new User("u1");
assertEquals("u1", entity.getEmail());
assertEquals(Type.USER, entity.getType());
Dataset.Access pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
}
@Test
public void testViewEntity() {
TableId viewId = TableId.of("project", "dataset", "view");
View entity = new View(viewId);
assertEquals(viewId, entity.getId());
assertEquals(Type.VIEW, entity.getType());
Dataset.Access pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
}
@Test
public void testRoutineEntity() {
RoutineId routineId = RoutineId.of("project", "dataset", "routine");
Acl.Routine entity = new Acl.Routine(routineId);
assertEquals(routineId, entity.getId());
assertEquals(Type.ROUTINE, entity.getType());
Dataset.Access pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
}
@Test
public void testIamMemberEntity() {
IamMember entity = new IamMember("member1");
assertEquals("member1", entity.getIamMember());
Dataset.Access pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
}
@Test
public void testOf() {
Acl acl = Acl.of(Group.ofAllAuthenticatedUsers(), Role.READER);
assertEquals(Group.ofAllAuthenticatedUsers(), acl.getEntity());
assertEquals(Role.READER, acl.getRole());
Dataset.Access pb = acl.toPb();
assertEquals(acl, Acl.fromPb(pb));
View view = new View(TableId.of("project", "dataset", "view"));
acl = Acl.of(view);
assertEquals(view, acl.getEntity());
assertEquals(null, acl.getRole());
Acl.Routine routine = new Acl.Routine(RoutineId.of("project", "dataset", "routine"));
acl = Acl.of(routine);
assertEquals(routine, acl.getEntity());
assertEquals(null, acl.getRole());
}
}