use of com.google.iam.v1.Policy in project openstack4j by ContainX.
the class KeystonePolicyServiceTest method policy_update_Test.
// ------------ Policy Tests ------------
// The following tests are to verify the update() method of the
// PolicyService using HTTP PATCH, which is not supported by betamax.
// Find more tests in KeystonePolicyServiceSpec in core-integration-test
// module.
public void policy_update_Test() throws Exception {
respondWith(JSON_POLICIES_GET_BYID);
Policy policy_setToUpdate = osv3().identity().policies().get(POLICY_ID);
respondWith(JSON_POLICIES_UPDATE);
Policy updatedPolicy = osv3().identity().policies().update(policy_setToUpdate.toBuilder().blob(POLICY_BLOB_UPDATE).build());
assertEquals(updatedPolicy.getId(), POLICY_ID);
assertEquals(updatedPolicy.getBlob(), POLICY_BLOB_UPDATE);
assertEquals(updatedPolicy.getProjectId(), POLICY_PROJECT_ID);
assertEquals(updatedPolicy.getUserId(), POLICY_USER_ID);
assertEquals(updatedPolicy.getType(), POLICY_TYPE);
}
use of com.google.iam.v1.Policy in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method setIamPolicyExceptionTest.
@Test
@SuppressWarnings("all")
public void setIamPolicyExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockIAMPolicy.addException(exception);
try {
String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
Policy policy = Policy.newBuilder().build();
client.setIamPolicy(formattedResource, policy);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.iam.v1.Policy in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method setIamPolicyTest.
@Test
@SuppressWarnings("all")
public void setIamPolicyTest() {
int version = 351608024;
ByteString etag = ByteString.copyFromUtf8("21");
Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build();
mockIAMPolicy.addResponse(expectedResponse);
String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
Policy policy = Policy.newBuilder().build();
Policy actualResponse = client.setIamPolicy(formattedResource, policy);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockIAMPolicy.getRequests();
Assert.assertEquals(1, actualRequests.size());
SetIamPolicyRequest actualRequest = (SetIamPolicyRequest) actualRequests.get(0);
Assert.assertEquals(formattedResource, actualRequest.getResource());
Assert.assertEquals(policy, actualRequest.getPolicy());
}
use of com.google.iam.v1.Policy in project google-cloud-java by GoogleCloudPlatform.
the class ITTopicAdminClientSnippets method replaceTopicPolicyAndTestPermissionsIsSuccessful.
@Test
public void replaceTopicPolicyAndTestPermissionsIsSuccessful() throws Exception {
String topicName = topics[0];
topicAdminClientSnippets.createTopic(topicName);
Policy policy = topicAdminClientSnippets.replaceTopicPolicy(topicName);
assertNotNull(policy.getBindingsCount());
assertTrue(policy.getBindings(0).getRole().equalsIgnoreCase(Role.viewer().toString()));
assertTrue(policy.getBindings(0).getMembers(0).equalsIgnoreCase(Identity.allAuthenticatedUsers().toString()));
TestIamPermissionsResponse response = topicAdminClientSnippets.testTopicPermissions(topicName);
assertTrue(response.getPermissionsList().contains("pubsub.topics.get"));
}
use of com.google.iam.v1.Policy in project google-cloud-java by GoogleCloudPlatform.
the class ITTopicAdminClientSnippets method topicPolicyIsCorrectlyRetrieved.
@Test
public void topicPolicyIsCorrectlyRetrieved() throws Exception {
String topicName = topics[0];
topicAdminClientSnippets.createTopic(topicName);
Policy policy = topicAdminClientSnippets.getTopicPolicy(topicName);
assertNotNull(policy);
}
Aggregations