Search in sources :

Example 1 with ApiPolicyMatcher

use of com.google.cloud.storage.testing.ApiPolicyMatcher in project google-cloud-java by GoogleCloudPlatform.

the class PolicyHelperTest method testEquivalence.

@Test
public void testEquivalence() {
    Policy libPolicy = Policy.newBuilder().addIdentity(StorageRoles.objectViewer(), Identity.allUsers()).addIdentity(StorageRoles.objectAdmin(), Identity.user("test1@gmail.com"), Identity.user("test2@gmail.com")).setEtag(ETAG).build();
    com.google.api.services.storage.model.Policy apiPolicy = new com.google.api.services.storage.model.Policy().setBindings(ImmutableList.of(new Bindings().setMembers(ImmutableList.of("allUsers")).setRole("roles/storage.objectViewer"), new Bindings().setMembers(ImmutableList.of("user:test1@gmail.com", "user:test2@gmail.com")).setRole("roles/storage.objectAdmin"))).setEtag(ETAG);
    Policy actualLibPolicy = PolicyHelper.convertFromApiPolicy(apiPolicy);
    com.google.api.services.storage.model.Policy actualApiPolicy = PolicyHelper.convertToApiPolicy(libPolicy);
    assertEquals(libPolicy, actualLibPolicy);
    assertTrue(new ApiPolicyMatcher(apiPolicy).matches(actualApiPolicy));
}
Also used : Policy(com.google.cloud.Policy) ApiPolicyMatcher(com.google.cloud.storage.testing.ApiPolicyMatcher) Bindings(com.google.api.services.storage.model.Policy.Bindings) Test(org.junit.Test)

Aggregations

Bindings (com.google.api.services.storage.model.Policy.Bindings)1 Policy (com.google.cloud.Policy)1 ApiPolicyMatcher (com.google.cloud.storage.testing.ApiPolicyMatcher)1 Test (org.junit.Test)1