• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.dialogflow.cx.v3;
18 
19 import com.google.api.core.BetaApi;
20 import com.google.cloud.dialogflow.cx.v3.TestCasesGrpc.TestCasesImplBase;
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 MockTestCasesImpl extends TestCasesImplBase {
34   private List<AbstractMessage> requests;
35   private Queue<Object> responses;
36 
MockTestCasesImpl()37   public MockTestCasesImpl() {
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
listTestCases( ListTestCasesRequest request, StreamObserver<ListTestCasesResponse> responseObserver)64   public void listTestCases(
65       ListTestCasesRequest request, StreamObserver<ListTestCasesResponse> responseObserver) {
66     Object response = responses.poll();
67     if (response instanceof ListTestCasesResponse) {
68       requests.add(request);
69       responseObserver.onNext(((ListTestCasesResponse) 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 ListTestCases, expected %s or %s",
78                   response == null ? "null" : response.getClass().getName(),
79                   ListTestCasesResponse.class.getName(),
80                   Exception.class.getName())));
81     }
82   }
83 
84   @Override
batchDeleteTestCases( BatchDeleteTestCasesRequest request, StreamObserver<Empty> responseObserver)85   public void batchDeleteTestCases(
86       BatchDeleteTestCasesRequest request, StreamObserver<Empty> responseObserver) {
87     Object response = responses.poll();
88     if (response instanceof Empty) {
89       requests.add(request);
90       responseObserver.onNext(((Empty) 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 BatchDeleteTestCases, expected %s or %s",
99                   response == null ? "null" : response.getClass().getName(),
100                   Empty.class.getName(),
101                   Exception.class.getName())));
102     }
103   }
104 
105   @Override
getTestCase(GetTestCaseRequest request, StreamObserver<TestCase> responseObserver)106   public void getTestCase(GetTestCaseRequest request, StreamObserver<TestCase> responseObserver) {
107     Object response = responses.poll();
108     if (response instanceof TestCase) {
109       requests.add(request);
110       responseObserver.onNext(((TestCase) response));
111       responseObserver.onCompleted();
112     } else if (response instanceof Exception) {
113       responseObserver.onError(((Exception) response));
114     } else {
115       responseObserver.onError(
116           new IllegalArgumentException(
117               String.format(
118                   "Unrecognized response type %s for method GetTestCase, expected %s or %s",
119                   response == null ? "null" : response.getClass().getName(),
120                   TestCase.class.getName(),
121                   Exception.class.getName())));
122     }
123   }
124 
125   @Override
createTestCase( CreateTestCaseRequest request, StreamObserver<TestCase> responseObserver)126   public void createTestCase(
127       CreateTestCaseRequest request, StreamObserver<TestCase> responseObserver) {
128     Object response = responses.poll();
129     if (response instanceof TestCase) {
130       requests.add(request);
131       responseObserver.onNext(((TestCase) response));
132       responseObserver.onCompleted();
133     } else if (response instanceof Exception) {
134       responseObserver.onError(((Exception) response));
135     } else {
136       responseObserver.onError(
137           new IllegalArgumentException(
138               String.format(
139                   "Unrecognized response type %s for method CreateTestCase, expected %s or %s",
140                   response == null ? "null" : response.getClass().getName(),
141                   TestCase.class.getName(),
142                   Exception.class.getName())));
143     }
144   }
145 
146   @Override
updateTestCase( UpdateTestCaseRequest request, StreamObserver<TestCase> responseObserver)147   public void updateTestCase(
148       UpdateTestCaseRequest request, StreamObserver<TestCase> responseObserver) {
149     Object response = responses.poll();
150     if (response instanceof TestCase) {
151       requests.add(request);
152       responseObserver.onNext(((TestCase) 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 UpdateTestCase, expected %s or %s",
161                   response == null ? "null" : response.getClass().getName(),
162                   TestCase.class.getName(),
163                   Exception.class.getName())));
164     }
165   }
166 
167   @Override
runTestCase(RunTestCaseRequest request, StreamObserver<Operation> responseObserver)168   public void runTestCase(RunTestCaseRequest request, StreamObserver<Operation> responseObserver) {
169     Object response = responses.poll();
170     if (response instanceof Operation) {
171       requests.add(request);
172       responseObserver.onNext(((Operation) response));
173       responseObserver.onCompleted();
174     } else if (response instanceof Exception) {
175       responseObserver.onError(((Exception) response));
176     } else {
177       responseObserver.onError(
178           new IllegalArgumentException(
179               String.format(
180                   "Unrecognized response type %s for method RunTestCase, expected %s or %s",
181                   response == null ? "null" : response.getClass().getName(),
182                   Operation.class.getName(),
183                   Exception.class.getName())));
184     }
185   }
186 
187   @Override
batchRunTestCases( BatchRunTestCasesRequest request, StreamObserver<Operation> responseObserver)188   public void batchRunTestCases(
189       BatchRunTestCasesRequest request, StreamObserver<Operation> responseObserver) {
190     Object response = responses.poll();
191     if (response instanceof Operation) {
192       requests.add(request);
193       responseObserver.onNext(((Operation) 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 BatchRunTestCases, expected %s or %s",
202                   response == null ? "null" : response.getClass().getName(),
203                   Operation.class.getName(),
204                   Exception.class.getName())));
205     }
206   }
207 
208   @Override
calculateCoverage( CalculateCoverageRequest request, StreamObserver<CalculateCoverageResponse> responseObserver)209   public void calculateCoverage(
210       CalculateCoverageRequest request,
211       StreamObserver<CalculateCoverageResponse> responseObserver) {
212     Object response = responses.poll();
213     if (response instanceof CalculateCoverageResponse) {
214       requests.add(request);
215       responseObserver.onNext(((CalculateCoverageResponse) response));
216       responseObserver.onCompleted();
217     } else if (response instanceof Exception) {
218       responseObserver.onError(((Exception) response));
219     } else {
220       responseObserver.onError(
221           new IllegalArgumentException(
222               String.format(
223                   "Unrecognized response type %s for method CalculateCoverage, expected %s or %s",
224                   response == null ? "null" : response.getClass().getName(),
225                   CalculateCoverageResponse.class.getName(),
226                   Exception.class.getName())));
227     }
228   }
229 
230   @Override
importTestCases( ImportTestCasesRequest request, StreamObserver<Operation> responseObserver)231   public void importTestCases(
232       ImportTestCasesRequest request, StreamObserver<Operation> responseObserver) {
233     Object response = responses.poll();
234     if (response instanceof Operation) {
235       requests.add(request);
236       responseObserver.onNext(((Operation) response));
237       responseObserver.onCompleted();
238     } else if (response instanceof Exception) {
239       responseObserver.onError(((Exception) response));
240     } else {
241       responseObserver.onError(
242           new IllegalArgumentException(
243               String.format(
244                   "Unrecognized response type %s for method ImportTestCases, expected %s or %s",
245                   response == null ? "null" : response.getClass().getName(),
246                   Operation.class.getName(),
247                   Exception.class.getName())));
248     }
249   }
250 
251   @Override
exportTestCases( ExportTestCasesRequest request, StreamObserver<Operation> responseObserver)252   public void exportTestCases(
253       ExportTestCasesRequest request, StreamObserver<Operation> responseObserver) {
254     Object response = responses.poll();
255     if (response instanceof Operation) {
256       requests.add(request);
257       responseObserver.onNext(((Operation) 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 ExportTestCases, expected %s or %s",
266                   response == null ? "null" : response.getClass().getName(),
267                   Operation.class.getName(),
268                   Exception.class.getName())));
269     }
270   }
271 
272   @Override
listTestCaseResults( ListTestCaseResultsRequest request, StreamObserver<ListTestCaseResultsResponse> responseObserver)273   public void listTestCaseResults(
274       ListTestCaseResultsRequest request,
275       StreamObserver<ListTestCaseResultsResponse> responseObserver) {
276     Object response = responses.poll();
277     if (response instanceof ListTestCaseResultsResponse) {
278       requests.add(request);
279       responseObserver.onNext(((ListTestCaseResultsResponse) response));
280       responseObserver.onCompleted();
281     } else if (response instanceof Exception) {
282       responseObserver.onError(((Exception) response));
283     } else {
284       responseObserver.onError(
285           new IllegalArgumentException(
286               String.format(
287                   "Unrecognized response type %s for method ListTestCaseResults, expected %s or %s",
288                   response == null ? "null" : response.getClass().getName(),
289                   ListTestCaseResultsResponse.class.getName(),
290                   Exception.class.getName())));
291     }
292   }
293 
294   @Override
getTestCaseResult( GetTestCaseResultRequest request, StreamObserver<TestCaseResult> responseObserver)295   public void getTestCaseResult(
296       GetTestCaseResultRequest request, StreamObserver<TestCaseResult> responseObserver) {
297     Object response = responses.poll();
298     if (response instanceof TestCaseResult) {
299       requests.add(request);
300       responseObserver.onNext(((TestCaseResult) response));
301       responseObserver.onCompleted();
302     } else if (response instanceof Exception) {
303       responseObserver.onError(((Exception) response));
304     } else {
305       responseObserver.onError(
306           new IllegalArgumentException(
307               String.format(
308                   "Unrecognized response type %s for method GetTestCaseResult, expected %s or %s",
309                   response == null ? "null" : response.getClass().getName(),
310                   TestCaseResult.class.getName(),
311                   Exception.class.getName())));
312     }
313   }
314 }
315