|
| 1 | +/* |
| 2 | + * Copyright 2022 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.cloud.aiplatform.v1beta1; |
| 18 | + |
| 19 | +import com.google.api.core.BetaApi; |
| 20 | +import com.google.iam.v1.GetIamPolicyRequest; |
| 21 | +import com.google.iam.v1.IAMPolicyGrpc.IAMPolicyImplBase; |
| 22 | +import com.google.iam.v1.Policy; |
| 23 | +import com.google.iam.v1.SetIamPolicyRequest; |
| 24 | +import com.google.iam.v1.TestIamPermissionsRequest; |
| 25 | +import com.google.iam.v1.TestIamPermissionsResponse; |
| 26 | +import com.google.protobuf.AbstractMessage; |
| 27 | +import io.grpc.stub.StreamObserver; |
| 28 | +import java.util.ArrayList; |
| 29 | +import java.util.LinkedList; |
| 30 | +import java.util.List; |
| 31 | +import java.util.Queue; |
| 32 | +import javax.annotation.Generated; |
| 33 | + |
| 34 | +@BetaApi |
| 35 | +@Generated("by gapic-generator-java") |
| 36 | +public class MockIAMPolicyImpl extends IAMPolicyImplBase { |
| 37 | + private List<AbstractMessage> requests; |
| 38 | + private Queue<Object> responses; |
| 39 | + |
| 40 | + public MockIAMPolicyImpl() { |
| 41 | + requests = new ArrayList<>(); |
| 42 | + responses = new LinkedList<>(); |
| 43 | + } |
| 44 | + |
| 45 | + public List<AbstractMessage> getRequests() { |
| 46 | + return requests; |
| 47 | + } |
| 48 | + |
| 49 | + public void addResponse(AbstractMessage response) { |
| 50 | + responses.add(response); |
| 51 | + } |
| 52 | + |
| 53 | + public void setResponses(List<AbstractMessage> responses) { |
| 54 | + this.responses = new LinkedList<Object>(responses); |
| 55 | + } |
| 56 | + |
| 57 | + public void addException(Exception exception) { |
| 58 | + responses.add(exception); |
| 59 | + } |
| 60 | + |
| 61 | + public void reset() { |
| 62 | + requests = new ArrayList<>(); |
| 63 | + responses = new LinkedList<>(); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public void testIamPermissions( |
| 68 | + TestIamPermissionsRequest request, |
| 69 | + StreamObserver<TestIamPermissionsResponse> responseObserver) { |
| 70 | + Object response = responses.poll(); |
| 71 | + if (response instanceof TestIamPermissionsResponse) { |
| 72 | + requests.add(request); |
| 73 | + responseObserver.onNext(((TestIamPermissionsResponse) response)); |
| 74 | + responseObserver.onCompleted(); |
| 75 | + } else if (response instanceof Exception) { |
| 76 | + responseObserver.onError(((Exception) response)); |
| 77 | + } else { |
| 78 | + responseObserver.onError( |
| 79 | + new IllegalArgumentException( |
| 80 | + String.format( |
| 81 | + "Unrecognized response type %s for method TestIamPermissions, expected %s or %s", |
| 82 | + response == null ? "null" : response.getClass().getName(), |
| 83 | + TestIamPermissionsResponse.class.getName(), |
| 84 | + Exception.class.getName()))); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public void setIamPolicy(SetIamPolicyRequest request, StreamObserver<Policy> responseObserver) { |
| 90 | + Object response = responses.poll(); |
| 91 | + if (response instanceof Policy) { |
| 92 | + requests.add(request); |
| 93 | + responseObserver.onNext(((Policy) response)); |
| 94 | + responseObserver.onCompleted(); |
| 95 | + } else if (response instanceof Exception) { |
| 96 | + responseObserver.onError(((Exception) response)); |
| 97 | + } else { |
| 98 | + responseObserver.onError( |
| 99 | + new IllegalArgumentException( |
| 100 | + String.format( |
| 101 | + "Unrecognized response type %s for method SetIamPolicy, expected %s or %s", |
| 102 | + response == null ? "null" : response.getClass().getName(), |
| 103 | + Policy.class.getName(), |
| 104 | + Exception.class.getName()))); |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + @Override |
| 109 | + public void getIamPolicy(GetIamPolicyRequest request, StreamObserver<Policy> responseObserver) { |
| 110 | + Object response = responses.poll(); |
| 111 | + if (response instanceof Policy) { |
| 112 | + requests.add(request); |
| 113 | + responseObserver.onNext(((Policy) response)); |
| 114 | + responseObserver.onCompleted(); |
| 115 | + } else if (response instanceof Exception) { |
| 116 | + responseObserver.onError(((Exception) response)); |
| 117 | + } else { |
| 118 | + responseObserver.onError( |
| 119 | + new IllegalArgumentException( |
| 120 | + String.format( |
| 121 | + "Unrecognized response type %s for method GetIamPolicy, expected %s or %s", |
| 122 | + response == null ? "null" : response.getClass().getName(), |
| 123 | + Policy.class.getName(), |
| 124 | + Exception.class.getName()))); |
| 125 | + } |
| 126 | + } |
| 127 | +} |
0 commit comments