Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Handle null role in Acl.fromPb, add test
  • Loading branch information
mziccard committed Nov 27, 2015
commit 3f0d511746b9589de453dfce2a1171ff9ba301ad
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.gcloud.bigquery;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.services.bigquery.model.Dataset.Access;

import java.io.Serializable;
Expand Down Expand Up @@ -370,15 +372,15 @@ Access toPb() {
* Build an ACL for an {@code entity} and a {@code role}.
*/
public Acl(Entity entity, Role role) {
this.entity = entity;
this.entity = checkNotNull(entity);
this.role = role;
}

/**
* Build an ACL for a view entity.
*/
public Acl(View view) {
this.entity = view;
this.entity = checkNotNull(view);
this.role = null;
}

Expand Down Expand Up @@ -428,7 +430,7 @@ Access toPb() {
}

static Acl fromPb(Access access) {
Role role = Role.valueOf(access.getRole());
return new Acl(Entity.fromPb(access), role);
return new Acl(Entity.fromPb(access),
access.getRole() != null ? Role.valueOf(access.getRole()) : null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,9 @@ public void testAcl() {
assertEquals(Role.READER, acl.role());
Dataset.Access pb = acl.toPb();
assertEquals(acl, Acl.fromPb(pb));
View view = new View(TableId.of("project", "dataset", "view"));
acl = new Acl(view);
assertEquals(view, acl.entity());
assertEquals(null, acl.role());
}
}