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.asset.v1; 18 19 import com.google.api.core.BetaApi; 20 import com.google.cloud.asset.v1.AssetServiceGrpc.AssetServiceImplBase; 21 import com.google.longrunning.Operation; 22 import com.google.protobuf.AbstractMessage; 23 import com.google.protobuf.Empty; 24 import io.grpc.stub.StreamObserver; 25 import java.util.ArrayList; 26 import java.util.LinkedList; 27 import java.util.List; 28 import java.util.Queue; 29 import javax.annotation.Generated; 30 31 @BetaApi 32 @Generated("by gapic-generator-java") 33 public class MockAssetServiceImpl extends AssetServiceImplBase { 34 private List<AbstractMessage> requests; 35 private Queue<Object> responses; 36 MockAssetServiceImpl()37 public MockAssetServiceImpl() { 38 requests = new ArrayList<>(); 39 responses = new LinkedList<>(); 40 } 41 getRequests()42 public List<AbstractMessage> getRequests() { 43 return requests; 44 } 45 addResponse(AbstractMessage response)46 public void addResponse(AbstractMessage response) { 47 responses.add(response); 48 } 49 setResponses(List<AbstractMessage> responses)50 public void setResponses(List<AbstractMessage> responses) { 51 this.responses = new LinkedList<Object>(responses); 52 } 53 addException(Exception exception)54 public void addException(Exception exception) { 55 responses.add(exception); 56 } 57 reset()58 public void reset() { 59 requests = new ArrayList<>(); 60 responses = new LinkedList<>(); 61 } 62 63 @Override exportAssets( ExportAssetsRequest request, StreamObserver<Operation> responseObserver)64 public void exportAssets( 65 ExportAssetsRequest request, StreamObserver<Operation> responseObserver) { 66 Object response = responses.poll(); 67 if (response instanceof Operation) { 68 requests.add(request); 69 responseObserver.onNext(((Operation) response)); 70 responseObserver.onCompleted(); 71 } else if (response instanceof Exception) { 72 responseObserver.onError(((Exception) response)); 73 } else { 74 responseObserver.onError( 75 new IllegalArgumentException( 76 String.format( 77 "Unrecognized response type %s for method ExportAssets, expected %s or %s", 78 response == null ? "null" : response.getClass().getName(), 79 Operation.class.getName(), 80 Exception.class.getName()))); 81 } 82 } 83 84 @Override listAssets( ListAssetsRequest request, StreamObserver<ListAssetsResponse> responseObserver)85 public void listAssets( 86 ListAssetsRequest request, StreamObserver<ListAssetsResponse> responseObserver) { 87 Object response = responses.poll(); 88 if (response instanceof ListAssetsResponse) { 89 requests.add(request); 90 responseObserver.onNext(((ListAssetsResponse) response)); 91 responseObserver.onCompleted(); 92 } else if (response instanceof Exception) { 93 responseObserver.onError(((Exception) response)); 94 } else { 95 responseObserver.onError( 96 new IllegalArgumentException( 97 String.format( 98 "Unrecognized response type %s for method ListAssets, expected %s or %s", 99 response == null ? "null" : response.getClass().getName(), 100 ListAssetsResponse.class.getName(), 101 Exception.class.getName()))); 102 } 103 } 104 105 @Override batchGetAssetsHistory( BatchGetAssetsHistoryRequest request, StreamObserver<BatchGetAssetsHistoryResponse> responseObserver)106 public void batchGetAssetsHistory( 107 BatchGetAssetsHistoryRequest request, 108 StreamObserver<BatchGetAssetsHistoryResponse> responseObserver) { 109 Object response = responses.poll(); 110 if (response instanceof BatchGetAssetsHistoryResponse) { 111 requests.add(request); 112 responseObserver.onNext(((BatchGetAssetsHistoryResponse) response)); 113 responseObserver.onCompleted(); 114 } else if (response instanceof Exception) { 115 responseObserver.onError(((Exception) response)); 116 } else { 117 responseObserver.onError( 118 new IllegalArgumentException( 119 String.format( 120 "Unrecognized response type %s for method BatchGetAssetsHistory, expected %s or %s", 121 response == null ? "null" : response.getClass().getName(), 122 BatchGetAssetsHistoryResponse.class.getName(), 123 Exception.class.getName()))); 124 } 125 } 126 127 @Override createFeed(CreateFeedRequest request, StreamObserver<Feed> responseObserver)128 public void createFeed(CreateFeedRequest request, StreamObserver<Feed> responseObserver) { 129 Object response = responses.poll(); 130 if (response instanceof Feed) { 131 requests.add(request); 132 responseObserver.onNext(((Feed) response)); 133 responseObserver.onCompleted(); 134 } else if (response instanceof Exception) { 135 responseObserver.onError(((Exception) response)); 136 } else { 137 responseObserver.onError( 138 new IllegalArgumentException( 139 String.format( 140 "Unrecognized response type %s for method CreateFeed, expected %s or %s", 141 response == null ? "null" : response.getClass().getName(), 142 Feed.class.getName(), 143 Exception.class.getName()))); 144 } 145 } 146 147 @Override getFeed(GetFeedRequest request, StreamObserver<Feed> responseObserver)148 public void getFeed(GetFeedRequest request, StreamObserver<Feed> responseObserver) { 149 Object response = responses.poll(); 150 if (response instanceof Feed) { 151 requests.add(request); 152 responseObserver.onNext(((Feed) response)); 153 responseObserver.onCompleted(); 154 } else if (response instanceof Exception) { 155 responseObserver.onError(((Exception) response)); 156 } else { 157 responseObserver.onError( 158 new IllegalArgumentException( 159 String.format( 160 "Unrecognized response type %s for method GetFeed, expected %s or %s", 161 response == null ? "null" : response.getClass().getName(), 162 Feed.class.getName(), 163 Exception.class.getName()))); 164 } 165 } 166 167 @Override listFeeds( ListFeedsRequest request, StreamObserver<ListFeedsResponse> responseObserver)168 public void listFeeds( 169 ListFeedsRequest request, StreamObserver<ListFeedsResponse> responseObserver) { 170 Object response = responses.poll(); 171 if (response instanceof ListFeedsResponse) { 172 requests.add(request); 173 responseObserver.onNext(((ListFeedsResponse) response)); 174 responseObserver.onCompleted(); 175 } else if (response instanceof Exception) { 176 responseObserver.onError(((Exception) response)); 177 } else { 178 responseObserver.onError( 179 new IllegalArgumentException( 180 String.format( 181 "Unrecognized response type %s for method ListFeeds, expected %s or %s", 182 response == null ? "null" : response.getClass().getName(), 183 ListFeedsResponse.class.getName(), 184 Exception.class.getName()))); 185 } 186 } 187 188 @Override updateFeed(UpdateFeedRequest request, StreamObserver<Feed> responseObserver)189 public void updateFeed(UpdateFeedRequest request, StreamObserver<Feed> responseObserver) { 190 Object response = responses.poll(); 191 if (response instanceof Feed) { 192 requests.add(request); 193 responseObserver.onNext(((Feed) response)); 194 responseObserver.onCompleted(); 195 } else if (response instanceof Exception) { 196 responseObserver.onError(((Exception) response)); 197 } else { 198 responseObserver.onError( 199 new IllegalArgumentException( 200 String.format( 201 "Unrecognized response type %s for method UpdateFeed, expected %s or %s", 202 response == null ? "null" : response.getClass().getName(), 203 Feed.class.getName(), 204 Exception.class.getName()))); 205 } 206 } 207 208 @Override deleteFeed(DeleteFeedRequest request, StreamObserver<Empty> responseObserver)209 public void deleteFeed(DeleteFeedRequest request, StreamObserver<Empty> responseObserver) { 210 Object response = responses.poll(); 211 if (response instanceof Empty) { 212 requests.add(request); 213 responseObserver.onNext(((Empty) response)); 214 responseObserver.onCompleted(); 215 } else if (response instanceof Exception) { 216 responseObserver.onError(((Exception) response)); 217 } else { 218 responseObserver.onError( 219 new IllegalArgumentException( 220 String.format( 221 "Unrecognized response type %s for method DeleteFeed, expected %s or %s", 222 response == null ? "null" : response.getClass().getName(), 223 Empty.class.getName(), 224 Exception.class.getName()))); 225 } 226 } 227 228 @Override searchAllResources( SearchAllResourcesRequest request, StreamObserver<SearchAllResourcesResponse> responseObserver)229 public void searchAllResources( 230 SearchAllResourcesRequest request, 231 StreamObserver<SearchAllResourcesResponse> responseObserver) { 232 Object response = responses.poll(); 233 if (response instanceof SearchAllResourcesResponse) { 234 requests.add(request); 235 responseObserver.onNext(((SearchAllResourcesResponse) response)); 236 responseObserver.onCompleted(); 237 } else if (response instanceof Exception) { 238 responseObserver.onError(((Exception) response)); 239 } else { 240 responseObserver.onError( 241 new IllegalArgumentException( 242 String.format( 243 "Unrecognized response type %s for method SearchAllResources, expected %s or %s", 244 response == null ? "null" : response.getClass().getName(), 245 SearchAllResourcesResponse.class.getName(), 246 Exception.class.getName()))); 247 } 248 } 249 250 @Override searchAllIamPolicies( SearchAllIamPoliciesRequest request, StreamObserver<SearchAllIamPoliciesResponse> responseObserver)251 public void searchAllIamPolicies( 252 SearchAllIamPoliciesRequest request, 253 StreamObserver<SearchAllIamPoliciesResponse> responseObserver) { 254 Object response = responses.poll(); 255 if (response instanceof SearchAllIamPoliciesResponse) { 256 requests.add(request); 257 responseObserver.onNext(((SearchAllIamPoliciesResponse) response)); 258 responseObserver.onCompleted(); 259 } else if (response instanceof Exception) { 260 responseObserver.onError(((Exception) response)); 261 } else { 262 responseObserver.onError( 263 new IllegalArgumentException( 264 String.format( 265 "Unrecognized response type %s for method SearchAllIamPolicies, expected %s or %s", 266 response == null ? "null" : response.getClass().getName(), 267 SearchAllIamPoliciesResponse.class.getName(), 268 Exception.class.getName()))); 269 } 270 } 271 272 @Override analyzeIamPolicy( AnalyzeIamPolicyRequest request, StreamObserver<AnalyzeIamPolicyResponse> responseObserver)273 public void analyzeIamPolicy( 274 AnalyzeIamPolicyRequest request, StreamObserver<AnalyzeIamPolicyResponse> responseObserver) { 275 Object response = responses.poll(); 276 if (response instanceof AnalyzeIamPolicyResponse) { 277 requests.add(request); 278 responseObserver.onNext(((AnalyzeIamPolicyResponse) response)); 279 responseObserver.onCompleted(); 280 } else if (response instanceof Exception) { 281 responseObserver.onError(((Exception) response)); 282 } else { 283 responseObserver.onError( 284 new IllegalArgumentException( 285 String.format( 286 "Unrecognized response type %s for method AnalyzeIamPolicy, expected %s or %s", 287 response == null ? "null" : response.getClass().getName(), 288 AnalyzeIamPolicyResponse.class.getName(), 289 Exception.class.getName()))); 290 } 291 } 292 293 @Override analyzeIamPolicyLongrunning( AnalyzeIamPolicyLongrunningRequest request, StreamObserver<Operation> responseObserver)294 public void analyzeIamPolicyLongrunning( 295 AnalyzeIamPolicyLongrunningRequest request, StreamObserver<Operation> responseObserver) { 296 Object response = responses.poll(); 297 if (response instanceof Operation) { 298 requests.add(request); 299 responseObserver.onNext(((Operation) response)); 300 responseObserver.onCompleted(); 301 } else if (response instanceof Exception) { 302 responseObserver.onError(((Exception) response)); 303 } else { 304 responseObserver.onError( 305 new IllegalArgumentException( 306 String.format( 307 "Unrecognized response type %s for method AnalyzeIamPolicyLongrunning, expected %s or %s", 308 response == null ? "null" : response.getClass().getName(), 309 Operation.class.getName(), 310 Exception.class.getName()))); 311 } 312 } 313 314 @Override analyzeMove( AnalyzeMoveRequest request, StreamObserver<AnalyzeMoveResponse> responseObserver)315 public void analyzeMove( 316 AnalyzeMoveRequest request, StreamObserver<AnalyzeMoveResponse> responseObserver) { 317 Object response = responses.poll(); 318 if (response instanceof AnalyzeMoveResponse) { 319 requests.add(request); 320 responseObserver.onNext(((AnalyzeMoveResponse) response)); 321 responseObserver.onCompleted(); 322 } else if (response instanceof Exception) { 323 responseObserver.onError(((Exception) response)); 324 } else { 325 responseObserver.onError( 326 new IllegalArgumentException( 327 String.format( 328 "Unrecognized response type %s for method AnalyzeMove, expected %s or %s", 329 response == null ? "null" : response.getClass().getName(), 330 AnalyzeMoveResponse.class.getName(), 331 Exception.class.getName()))); 332 } 333 } 334 335 @Override queryAssets( QueryAssetsRequest request, StreamObserver<QueryAssetsResponse> responseObserver)336 public void queryAssets( 337 QueryAssetsRequest request, StreamObserver<QueryAssetsResponse> responseObserver) { 338 Object response = responses.poll(); 339 if (response instanceof QueryAssetsResponse) { 340 requests.add(request); 341 responseObserver.onNext(((QueryAssetsResponse) response)); 342 responseObserver.onCompleted(); 343 } else if (response instanceof Exception) { 344 responseObserver.onError(((Exception) response)); 345 } else { 346 responseObserver.onError( 347 new IllegalArgumentException( 348 String.format( 349 "Unrecognized response type %s for method QueryAssets, expected %s or %s", 350 response == null ? "null" : response.getClass().getName(), 351 QueryAssetsResponse.class.getName(), 352 Exception.class.getName()))); 353 } 354 } 355 356 @Override createSavedQuery( CreateSavedQueryRequest request, StreamObserver<SavedQuery> responseObserver)357 public void createSavedQuery( 358 CreateSavedQueryRequest request, StreamObserver<SavedQuery> responseObserver) { 359 Object response = responses.poll(); 360 if (response instanceof SavedQuery) { 361 requests.add(request); 362 responseObserver.onNext(((SavedQuery) response)); 363 responseObserver.onCompleted(); 364 } else if (response instanceof Exception) { 365 responseObserver.onError(((Exception) response)); 366 } else { 367 responseObserver.onError( 368 new IllegalArgumentException( 369 String.format( 370 "Unrecognized response type %s for method CreateSavedQuery, expected %s or %s", 371 response == null ? "null" : response.getClass().getName(), 372 SavedQuery.class.getName(), 373 Exception.class.getName()))); 374 } 375 } 376 377 @Override getSavedQuery( GetSavedQueryRequest request, StreamObserver<SavedQuery> responseObserver)378 public void getSavedQuery( 379 GetSavedQueryRequest request, StreamObserver<SavedQuery> responseObserver) { 380 Object response = responses.poll(); 381 if (response instanceof SavedQuery) { 382 requests.add(request); 383 responseObserver.onNext(((SavedQuery) response)); 384 responseObserver.onCompleted(); 385 } else if (response instanceof Exception) { 386 responseObserver.onError(((Exception) response)); 387 } else { 388 responseObserver.onError( 389 new IllegalArgumentException( 390 String.format( 391 "Unrecognized response type %s for method GetSavedQuery, expected %s or %s", 392 response == null ? "null" : response.getClass().getName(), 393 SavedQuery.class.getName(), 394 Exception.class.getName()))); 395 } 396 } 397 398 @Override listSavedQueries( ListSavedQueriesRequest request, StreamObserver<ListSavedQueriesResponse> responseObserver)399 public void listSavedQueries( 400 ListSavedQueriesRequest request, StreamObserver<ListSavedQueriesResponse> responseObserver) { 401 Object response = responses.poll(); 402 if (response instanceof ListSavedQueriesResponse) { 403 requests.add(request); 404 responseObserver.onNext(((ListSavedQueriesResponse) response)); 405 responseObserver.onCompleted(); 406 } else if (response instanceof Exception) { 407 responseObserver.onError(((Exception) response)); 408 } else { 409 responseObserver.onError( 410 new IllegalArgumentException( 411 String.format( 412 "Unrecognized response type %s for method ListSavedQueries, expected %s or %s", 413 response == null ? "null" : response.getClass().getName(), 414 ListSavedQueriesResponse.class.getName(), 415 Exception.class.getName()))); 416 } 417 } 418 419 @Override updateSavedQuery( UpdateSavedQueryRequest request, StreamObserver<SavedQuery> responseObserver)420 public void updateSavedQuery( 421 UpdateSavedQueryRequest request, StreamObserver<SavedQuery> responseObserver) { 422 Object response = responses.poll(); 423 if (response instanceof SavedQuery) { 424 requests.add(request); 425 responseObserver.onNext(((SavedQuery) response)); 426 responseObserver.onCompleted(); 427 } else if (response instanceof Exception) { 428 responseObserver.onError(((Exception) response)); 429 } else { 430 responseObserver.onError( 431 new IllegalArgumentException( 432 String.format( 433 "Unrecognized response type %s for method UpdateSavedQuery, expected %s or %s", 434 response == null ? "null" : response.getClass().getName(), 435 SavedQuery.class.getName(), 436 Exception.class.getName()))); 437 } 438 } 439 440 @Override deleteSavedQuery( DeleteSavedQueryRequest request, StreamObserver<Empty> responseObserver)441 public void deleteSavedQuery( 442 DeleteSavedQueryRequest request, StreamObserver<Empty> responseObserver) { 443 Object response = responses.poll(); 444 if (response instanceof Empty) { 445 requests.add(request); 446 responseObserver.onNext(((Empty) response)); 447 responseObserver.onCompleted(); 448 } else if (response instanceof Exception) { 449 responseObserver.onError(((Exception) response)); 450 } else { 451 responseObserver.onError( 452 new IllegalArgumentException( 453 String.format( 454 "Unrecognized response type %s for method DeleteSavedQuery, expected %s or %s", 455 response == null ? "null" : response.getClass().getName(), 456 Empty.class.getName(), 457 Exception.class.getName()))); 458 } 459 } 460 461 @Override batchGetEffectiveIamPolicies( BatchGetEffectiveIamPoliciesRequest request, StreamObserver<BatchGetEffectiveIamPoliciesResponse> responseObserver)462 public void batchGetEffectiveIamPolicies( 463 BatchGetEffectiveIamPoliciesRequest request, 464 StreamObserver<BatchGetEffectiveIamPoliciesResponse> responseObserver) { 465 Object response = responses.poll(); 466 if (response instanceof BatchGetEffectiveIamPoliciesResponse) { 467 requests.add(request); 468 responseObserver.onNext(((BatchGetEffectiveIamPoliciesResponse) response)); 469 responseObserver.onCompleted(); 470 } else if (response instanceof Exception) { 471 responseObserver.onError(((Exception) response)); 472 } else { 473 responseObserver.onError( 474 new IllegalArgumentException( 475 String.format( 476 "Unrecognized response type %s for method BatchGetEffectiveIamPolicies, expected %s or %s", 477 response == null ? "null" : response.getClass().getName(), 478 BatchGetEffectiveIamPoliciesResponse.class.getName(), 479 Exception.class.getName()))); 480 } 481 } 482 483 @Override analyzeOrgPolicies( AnalyzeOrgPoliciesRequest request, StreamObserver<AnalyzeOrgPoliciesResponse> responseObserver)484 public void analyzeOrgPolicies( 485 AnalyzeOrgPoliciesRequest request, 486 StreamObserver<AnalyzeOrgPoliciesResponse> responseObserver) { 487 Object response = responses.poll(); 488 if (response instanceof AnalyzeOrgPoliciesResponse) { 489 requests.add(request); 490 responseObserver.onNext(((AnalyzeOrgPoliciesResponse) response)); 491 responseObserver.onCompleted(); 492 } else if (response instanceof Exception) { 493 responseObserver.onError(((Exception) response)); 494 } else { 495 responseObserver.onError( 496 new IllegalArgumentException( 497 String.format( 498 "Unrecognized response type %s for method AnalyzeOrgPolicies, expected %s or %s", 499 response == null ? "null" : response.getClass().getName(), 500 AnalyzeOrgPoliciesResponse.class.getName(), 501 Exception.class.getName()))); 502 } 503 } 504 505 @Override analyzeOrgPolicyGovernedContainers( AnalyzeOrgPolicyGovernedContainersRequest request, StreamObserver<AnalyzeOrgPolicyGovernedContainersResponse> responseObserver)506 public void analyzeOrgPolicyGovernedContainers( 507 AnalyzeOrgPolicyGovernedContainersRequest request, 508 StreamObserver<AnalyzeOrgPolicyGovernedContainersResponse> responseObserver) { 509 Object response = responses.poll(); 510 if (response instanceof AnalyzeOrgPolicyGovernedContainersResponse) { 511 requests.add(request); 512 responseObserver.onNext(((AnalyzeOrgPolicyGovernedContainersResponse) response)); 513 responseObserver.onCompleted(); 514 } else if (response instanceof Exception) { 515 responseObserver.onError(((Exception) response)); 516 } else { 517 responseObserver.onError( 518 new IllegalArgumentException( 519 String.format( 520 "Unrecognized response type %s for method AnalyzeOrgPolicyGovernedContainers, expected %s or %s", 521 response == null ? "null" : response.getClass().getName(), 522 AnalyzeOrgPolicyGovernedContainersResponse.class.getName(), 523 Exception.class.getName()))); 524 } 525 } 526 527 @Override analyzeOrgPolicyGovernedAssets( AnalyzeOrgPolicyGovernedAssetsRequest request, StreamObserver<AnalyzeOrgPolicyGovernedAssetsResponse> responseObserver)528 public void analyzeOrgPolicyGovernedAssets( 529 AnalyzeOrgPolicyGovernedAssetsRequest request, 530 StreamObserver<AnalyzeOrgPolicyGovernedAssetsResponse> responseObserver) { 531 Object response = responses.poll(); 532 if (response instanceof AnalyzeOrgPolicyGovernedAssetsResponse) { 533 requests.add(request); 534 responseObserver.onNext(((AnalyzeOrgPolicyGovernedAssetsResponse) response)); 535 responseObserver.onCompleted(); 536 } else if (response instanceof Exception) { 537 responseObserver.onError(((Exception) response)); 538 } else { 539 responseObserver.onError( 540 new IllegalArgumentException( 541 String.format( 542 "Unrecognized response type %s for method AnalyzeOrgPolicyGovernedAssets, expected %s or %s", 543 response == null ? "null" : response.getClass().getName(), 544 AnalyzeOrgPolicyGovernedAssetsResponse.class.getName(), 545 Exception.class.getName()))); 546 } 547 } 548 } 549