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.osconfig.v1; 18 19 import com.google.api.core.BetaApi; 20 import com.google.cloud.osconfig.v1.OsConfigServiceGrpc.OsConfigServiceImplBase; 21 import com.google.protobuf.AbstractMessage; 22 import com.google.protobuf.Empty; 23 import io.grpc.stub.StreamObserver; 24 import java.util.ArrayList; 25 import java.util.LinkedList; 26 import java.util.List; 27 import java.util.Queue; 28 import javax.annotation.Generated; 29 30 @BetaApi 31 @Generated("by gapic-generator-java") 32 public class MockOsConfigServiceImpl extends OsConfigServiceImplBase { 33 private List<AbstractMessage> requests; 34 private Queue<Object> responses; 35 MockOsConfigServiceImpl()36 public MockOsConfigServiceImpl() { 37 requests = new ArrayList<>(); 38 responses = new LinkedList<>(); 39 } 40 getRequests()41 public List<AbstractMessage> getRequests() { 42 return requests; 43 } 44 addResponse(AbstractMessage response)45 public void addResponse(AbstractMessage response) { 46 responses.add(response); 47 } 48 setResponses(List<AbstractMessage> responses)49 public void setResponses(List<AbstractMessage> responses) { 50 this.responses = new LinkedList<Object>(responses); 51 } 52 addException(Exception exception)53 public void addException(Exception exception) { 54 responses.add(exception); 55 } 56 reset()57 public void reset() { 58 requests = new ArrayList<>(); 59 responses = new LinkedList<>(); 60 } 61 62 @Override executePatchJob( PatchJobs.ExecutePatchJobRequest request, StreamObserver<PatchJobs.PatchJob> responseObserver)63 public void executePatchJob( 64 PatchJobs.ExecutePatchJobRequest request, 65 StreamObserver<PatchJobs.PatchJob> responseObserver) { 66 Object response = responses.poll(); 67 if (response instanceof PatchJobs.PatchJob) { 68 requests.add(request); 69 responseObserver.onNext(((PatchJobs.PatchJob) 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 ExecutePatchJob, expected %s or %s", 78 response == null ? "null" : response.getClass().getName(), 79 PatchJobs.PatchJob.class.getName(), 80 Exception.class.getName()))); 81 } 82 } 83 84 @Override getPatchJob( PatchJobs.GetPatchJobRequest request, StreamObserver<PatchJobs.PatchJob> responseObserver)85 public void getPatchJob( 86 PatchJobs.GetPatchJobRequest request, StreamObserver<PatchJobs.PatchJob> responseObserver) { 87 Object response = responses.poll(); 88 if (response instanceof PatchJobs.PatchJob) { 89 requests.add(request); 90 responseObserver.onNext(((PatchJobs.PatchJob) 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 GetPatchJob, expected %s or %s", 99 response == null ? "null" : response.getClass().getName(), 100 PatchJobs.PatchJob.class.getName(), 101 Exception.class.getName()))); 102 } 103 } 104 105 @Override cancelPatchJob( PatchJobs.CancelPatchJobRequest request, StreamObserver<PatchJobs.PatchJob> responseObserver)106 public void cancelPatchJob( 107 PatchJobs.CancelPatchJobRequest request, 108 StreamObserver<PatchJobs.PatchJob> responseObserver) { 109 Object response = responses.poll(); 110 if (response instanceof PatchJobs.PatchJob) { 111 requests.add(request); 112 responseObserver.onNext(((PatchJobs.PatchJob) 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 CancelPatchJob, expected %s or %s", 121 response == null ? "null" : response.getClass().getName(), 122 PatchJobs.PatchJob.class.getName(), 123 Exception.class.getName()))); 124 } 125 } 126 127 @Override listPatchJobs( PatchJobs.ListPatchJobsRequest request, StreamObserver<PatchJobs.ListPatchJobsResponse> responseObserver)128 public void listPatchJobs( 129 PatchJobs.ListPatchJobsRequest request, 130 StreamObserver<PatchJobs.ListPatchJobsResponse> responseObserver) { 131 Object response = responses.poll(); 132 if (response instanceof PatchJobs.ListPatchJobsResponse) { 133 requests.add(request); 134 responseObserver.onNext(((PatchJobs.ListPatchJobsResponse) response)); 135 responseObserver.onCompleted(); 136 } else if (response instanceof Exception) { 137 responseObserver.onError(((Exception) response)); 138 } else { 139 responseObserver.onError( 140 new IllegalArgumentException( 141 String.format( 142 "Unrecognized response type %s for method ListPatchJobs, expected %s or %s", 143 response == null ? "null" : response.getClass().getName(), 144 PatchJobs.ListPatchJobsResponse.class.getName(), 145 Exception.class.getName()))); 146 } 147 } 148 149 @Override listPatchJobInstanceDetails( PatchJobs.ListPatchJobInstanceDetailsRequest request, StreamObserver<PatchJobs.ListPatchJobInstanceDetailsResponse> responseObserver)150 public void listPatchJobInstanceDetails( 151 PatchJobs.ListPatchJobInstanceDetailsRequest request, 152 StreamObserver<PatchJobs.ListPatchJobInstanceDetailsResponse> responseObserver) { 153 Object response = responses.poll(); 154 if (response instanceof PatchJobs.ListPatchJobInstanceDetailsResponse) { 155 requests.add(request); 156 responseObserver.onNext(((PatchJobs.ListPatchJobInstanceDetailsResponse) response)); 157 responseObserver.onCompleted(); 158 } else if (response instanceof Exception) { 159 responseObserver.onError(((Exception) response)); 160 } else { 161 responseObserver.onError( 162 new IllegalArgumentException( 163 String.format( 164 "Unrecognized response type %s for method ListPatchJobInstanceDetails, expected %s or %s", 165 response == null ? "null" : response.getClass().getName(), 166 PatchJobs.ListPatchJobInstanceDetailsResponse.class.getName(), 167 Exception.class.getName()))); 168 } 169 } 170 171 @Override createPatchDeployment( PatchDeployments.CreatePatchDeploymentRequest request, StreamObserver<PatchDeployments.PatchDeployment> responseObserver)172 public void createPatchDeployment( 173 PatchDeployments.CreatePatchDeploymentRequest request, 174 StreamObserver<PatchDeployments.PatchDeployment> responseObserver) { 175 Object response = responses.poll(); 176 if (response instanceof PatchDeployments.PatchDeployment) { 177 requests.add(request); 178 responseObserver.onNext(((PatchDeployments.PatchDeployment) response)); 179 responseObserver.onCompleted(); 180 } else if (response instanceof Exception) { 181 responseObserver.onError(((Exception) response)); 182 } else { 183 responseObserver.onError( 184 new IllegalArgumentException( 185 String.format( 186 "Unrecognized response type %s for method CreatePatchDeployment, expected %s or %s", 187 response == null ? "null" : response.getClass().getName(), 188 PatchDeployments.PatchDeployment.class.getName(), 189 Exception.class.getName()))); 190 } 191 } 192 193 @Override getPatchDeployment( PatchDeployments.GetPatchDeploymentRequest request, StreamObserver<PatchDeployments.PatchDeployment> responseObserver)194 public void getPatchDeployment( 195 PatchDeployments.GetPatchDeploymentRequest request, 196 StreamObserver<PatchDeployments.PatchDeployment> responseObserver) { 197 Object response = responses.poll(); 198 if (response instanceof PatchDeployments.PatchDeployment) { 199 requests.add(request); 200 responseObserver.onNext(((PatchDeployments.PatchDeployment) response)); 201 responseObserver.onCompleted(); 202 } else if (response instanceof Exception) { 203 responseObserver.onError(((Exception) response)); 204 } else { 205 responseObserver.onError( 206 new IllegalArgumentException( 207 String.format( 208 "Unrecognized response type %s for method GetPatchDeployment, expected %s or %s", 209 response == null ? "null" : response.getClass().getName(), 210 PatchDeployments.PatchDeployment.class.getName(), 211 Exception.class.getName()))); 212 } 213 } 214 215 @Override listPatchDeployments( PatchDeployments.ListPatchDeploymentsRequest request, StreamObserver<PatchDeployments.ListPatchDeploymentsResponse> responseObserver)216 public void listPatchDeployments( 217 PatchDeployments.ListPatchDeploymentsRequest request, 218 StreamObserver<PatchDeployments.ListPatchDeploymentsResponse> responseObserver) { 219 Object response = responses.poll(); 220 if (response instanceof PatchDeployments.ListPatchDeploymentsResponse) { 221 requests.add(request); 222 responseObserver.onNext(((PatchDeployments.ListPatchDeploymentsResponse) response)); 223 responseObserver.onCompleted(); 224 } else if (response instanceof Exception) { 225 responseObserver.onError(((Exception) response)); 226 } else { 227 responseObserver.onError( 228 new IllegalArgumentException( 229 String.format( 230 "Unrecognized response type %s for method ListPatchDeployments, expected %s or %s", 231 response == null ? "null" : response.getClass().getName(), 232 PatchDeployments.ListPatchDeploymentsResponse.class.getName(), 233 Exception.class.getName()))); 234 } 235 } 236 237 @Override deletePatchDeployment( PatchDeployments.DeletePatchDeploymentRequest request, StreamObserver<Empty> responseObserver)238 public void deletePatchDeployment( 239 PatchDeployments.DeletePatchDeploymentRequest request, 240 StreamObserver<Empty> responseObserver) { 241 Object response = responses.poll(); 242 if (response instanceof Empty) { 243 requests.add(request); 244 responseObserver.onNext(((Empty) response)); 245 responseObserver.onCompleted(); 246 } else if (response instanceof Exception) { 247 responseObserver.onError(((Exception) response)); 248 } else { 249 responseObserver.onError( 250 new IllegalArgumentException( 251 String.format( 252 "Unrecognized response type %s for method DeletePatchDeployment, expected %s or %s", 253 response == null ? "null" : response.getClass().getName(), 254 Empty.class.getName(), 255 Exception.class.getName()))); 256 } 257 } 258 259 @Override updatePatchDeployment( PatchDeployments.UpdatePatchDeploymentRequest request, StreamObserver<PatchDeployments.PatchDeployment> responseObserver)260 public void updatePatchDeployment( 261 PatchDeployments.UpdatePatchDeploymentRequest request, 262 StreamObserver<PatchDeployments.PatchDeployment> responseObserver) { 263 Object response = responses.poll(); 264 if (response instanceof PatchDeployments.PatchDeployment) { 265 requests.add(request); 266 responseObserver.onNext(((PatchDeployments.PatchDeployment) response)); 267 responseObserver.onCompleted(); 268 } else if (response instanceof Exception) { 269 responseObserver.onError(((Exception) response)); 270 } else { 271 responseObserver.onError( 272 new IllegalArgumentException( 273 String.format( 274 "Unrecognized response type %s for method UpdatePatchDeployment, expected %s or %s", 275 response == null ? "null" : response.getClass().getName(), 276 PatchDeployments.PatchDeployment.class.getName(), 277 Exception.class.getName()))); 278 } 279 } 280 281 @Override pausePatchDeployment( PatchDeployments.PausePatchDeploymentRequest request, StreamObserver<PatchDeployments.PatchDeployment> responseObserver)282 public void pausePatchDeployment( 283 PatchDeployments.PausePatchDeploymentRequest request, 284 StreamObserver<PatchDeployments.PatchDeployment> responseObserver) { 285 Object response = responses.poll(); 286 if (response instanceof PatchDeployments.PatchDeployment) { 287 requests.add(request); 288 responseObserver.onNext(((PatchDeployments.PatchDeployment) response)); 289 responseObserver.onCompleted(); 290 } else if (response instanceof Exception) { 291 responseObserver.onError(((Exception) response)); 292 } else { 293 responseObserver.onError( 294 new IllegalArgumentException( 295 String.format( 296 "Unrecognized response type %s for method PausePatchDeployment, expected %s or %s", 297 response == null ? "null" : response.getClass().getName(), 298 PatchDeployments.PatchDeployment.class.getName(), 299 Exception.class.getName()))); 300 } 301 } 302 303 @Override resumePatchDeployment( PatchDeployments.ResumePatchDeploymentRequest request, StreamObserver<PatchDeployments.PatchDeployment> responseObserver)304 public void resumePatchDeployment( 305 PatchDeployments.ResumePatchDeploymentRequest request, 306 StreamObserver<PatchDeployments.PatchDeployment> responseObserver) { 307 Object response = responses.poll(); 308 if (response instanceof PatchDeployments.PatchDeployment) { 309 requests.add(request); 310 responseObserver.onNext(((PatchDeployments.PatchDeployment) response)); 311 responseObserver.onCompleted(); 312 } else if (response instanceof Exception) { 313 responseObserver.onError(((Exception) response)); 314 } else { 315 responseObserver.onError( 316 new IllegalArgumentException( 317 String.format( 318 "Unrecognized response type %s for method ResumePatchDeployment, expected %s or %s", 319 response == null ? "null" : response.getClass().getName(), 320 PatchDeployments.PatchDeployment.class.getName(), 321 Exception.class.getName()))); 322 } 323 } 324 } 325