• 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.v2beta1;
18 
19 import com.google.api.core.BetaApi;
20 import com.google.cloud.dialogflow.v2beta1.ParticipantsGrpc.ParticipantsImplBase;
21 import com.google.protobuf.AbstractMessage;
22 import io.grpc.stub.StreamObserver;
23 import java.util.ArrayList;
24 import java.util.LinkedList;
25 import java.util.List;
26 import java.util.Queue;
27 import javax.annotation.Generated;
28 
29 @BetaApi
30 @Generated("by gapic-generator-java")
31 public class MockParticipantsImpl extends ParticipantsImplBase {
32   private List<AbstractMessage> requests;
33   private Queue<Object> responses;
34 
MockParticipantsImpl()35   public MockParticipantsImpl() {
36     requests = new ArrayList<>();
37     responses = new LinkedList<>();
38   }
39 
getRequests()40   public List<AbstractMessage> getRequests() {
41     return requests;
42   }
43 
addResponse(AbstractMessage response)44   public void addResponse(AbstractMessage response) {
45     responses.add(response);
46   }
47 
setResponses(List<AbstractMessage> responses)48   public void setResponses(List<AbstractMessage> responses) {
49     this.responses = new LinkedList<Object>(responses);
50   }
51 
addException(Exception exception)52   public void addException(Exception exception) {
53     responses.add(exception);
54   }
55 
reset()56   public void reset() {
57     requests = new ArrayList<>();
58     responses = new LinkedList<>();
59   }
60 
61   @Override
createParticipant( CreateParticipantRequest request, StreamObserver<Participant> responseObserver)62   public void createParticipant(
63       CreateParticipantRequest request, StreamObserver<Participant> responseObserver) {
64     Object response = responses.poll();
65     if (response instanceof Participant) {
66       requests.add(request);
67       responseObserver.onNext(((Participant) response));
68       responseObserver.onCompleted();
69     } else if (response instanceof Exception) {
70       responseObserver.onError(((Exception) response));
71     } else {
72       responseObserver.onError(
73           new IllegalArgumentException(
74               String.format(
75                   "Unrecognized response type %s for method CreateParticipant, expected %s or %s",
76                   response == null ? "null" : response.getClass().getName(),
77                   Participant.class.getName(),
78                   Exception.class.getName())));
79     }
80   }
81 
82   @Override
getParticipant( GetParticipantRequest request, StreamObserver<Participant> responseObserver)83   public void getParticipant(
84       GetParticipantRequest request, StreamObserver<Participant> responseObserver) {
85     Object response = responses.poll();
86     if (response instanceof Participant) {
87       requests.add(request);
88       responseObserver.onNext(((Participant) response));
89       responseObserver.onCompleted();
90     } else if (response instanceof Exception) {
91       responseObserver.onError(((Exception) response));
92     } else {
93       responseObserver.onError(
94           new IllegalArgumentException(
95               String.format(
96                   "Unrecognized response type %s for method GetParticipant, expected %s or %s",
97                   response == null ? "null" : response.getClass().getName(),
98                   Participant.class.getName(),
99                   Exception.class.getName())));
100     }
101   }
102 
103   @Override
listParticipants( ListParticipantsRequest request, StreamObserver<ListParticipantsResponse> responseObserver)104   public void listParticipants(
105       ListParticipantsRequest request, StreamObserver<ListParticipantsResponse> responseObserver) {
106     Object response = responses.poll();
107     if (response instanceof ListParticipantsResponse) {
108       requests.add(request);
109       responseObserver.onNext(((ListParticipantsResponse) response));
110       responseObserver.onCompleted();
111     } else if (response instanceof Exception) {
112       responseObserver.onError(((Exception) response));
113     } else {
114       responseObserver.onError(
115           new IllegalArgumentException(
116               String.format(
117                   "Unrecognized response type %s for method ListParticipants, expected %s or %s",
118                   response == null ? "null" : response.getClass().getName(),
119                   ListParticipantsResponse.class.getName(),
120                   Exception.class.getName())));
121     }
122   }
123 
124   @Override
updateParticipant( UpdateParticipantRequest request, StreamObserver<Participant> responseObserver)125   public void updateParticipant(
126       UpdateParticipantRequest request, StreamObserver<Participant> responseObserver) {
127     Object response = responses.poll();
128     if (response instanceof Participant) {
129       requests.add(request);
130       responseObserver.onNext(((Participant) response));
131       responseObserver.onCompleted();
132     } else if (response instanceof Exception) {
133       responseObserver.onError(((Exception) response));
134     } else {
135       responseObserver.onError(
136           new IllegalArgumentException(
137               String.format(
138                   "Unrecognized response type %s for method UpdateParticipant, expected %s or %s",
139                   response == null ? "null" : response.getClass().getName(),
140                   Participant.class.getName(),
141                   Exception.class.getName())));
142     }
143   }
144 
145   @Override
analyzeContent( AnalyzeContentRequest request, StreamObserver<AnalyzeContentResponse> responseObserver)146   public void analyzeContent(
147       AnalyzeContentRequest request, StreamObserver<AnalyzeContentResponse> responseObserver) {
148     Object response = responses.poll();
149     if (response instanceof AnalyzeContentResponse) {
150       requests.add(request);
151       responseObserver.onNext(((AnalyzeContentResponse) response));
152       responseObserver.onCompleted();
153     } else if (response instanceof Exception) {
154       responseObserver.onError(((Exception) response));
155     } else {
156       responseObserver.onError(
157           new IllegalArgumentException(
158               String.format(
159                   "Unrecognized response type %s for method AnalyzeContent, expected %s or %s",
160                   response == null ? "null" : response.getClass().getName(),
161                   AnalyzeContentResponse.class.getName(),
162                   Exception.class.getName())));
163     }
164   }
165 
166   @Override
streamingAnalyzeContent( final StreamObserver<StreamingAnalyzeContentResponse> responseObserver)167   public StreamObserver<StreamingAnalyzeContentRequest> streamingAnalyzeContent(
168       final StreamObserver<StreamingAnalyzeContentResponse> responseObserver) {
169     StreamObserver<StreamingAnalyzeContentRequest> requestObserver =
170         new StreamObserver<StreamingAnalyzeContentRequest>() {
171           @Override
172           public void onNext(StreamingAnalyzeContentRequest value) {
173             requests.add(value);
174             final Object response = responses.remove();
175             if (response instanceof StreamingAnalyzeContentResponse) {
176               responseObserver.onNext(((StreamingAnalyzeContentResponse) response));
177             } else if (response instanceof Exception) {
178               responseObserver.onError(((Exception) response));
179             } else {
180               responseObserver.onError(
181                   new IllegalArgumentException(
182                       String.format(
183                           "Unrecognized response type %s for method StreamingAnalyzeContent, expected %s or %s",
184                           response == null ? "null" : response.getClass().getName(),
185                           StreamingAnalyzeContentResponse.class.getName(),
186                           Exception.class.getName())));
187             }
188           }
189 
190           @Override
191           public void onError(Throwable t) {
192             responseObserver.onError(t);
193           }
194 
195           @Override
196           public void onCompleted() {
197             responseObserver.onCompleted();
198           }
199         };
200     return requestObserver;
201   }
202 
203   @Override
suggestArticles( SuggestArticlesRequest request, StreamObserver<SuggestArticlesResponse> responseObserver)204   public void suggestArticles(
205       SuggestArticlesRequest request, StreamObserver<SuggestArticlesResponse> responseObserver) {
206     Object response = responses.poll();
207     if (response instanceof SuggestArticlesResponse) {
208       requests.add(request);
209       responseObserver.onNext(((SuggestArticlesResponse) response));
210       responseObserver.onCompleted();
211     } else if (response instanceof Exception) {
212       responseObserver.onError(((Exception) response));
213     } else {
214       responseObserver.onError(
215           new IllegalArgumentException(
216               String.format(
217                   "Unrecognized response type %s for method SuggestArticles, expected %s or %s",
218                   response == null ? "null" : response.getClass().getName(),
219                   SuggestArticlesResponse.class.getName(),
220                   Exception.class.getName())));
221     }
222   }
223 
224   @Override
suggestFaqAnswers( SuggestFaqAnswersRequest request, StreamObserver<SuggestFaqAnswersResponse> responseObserver)225   public void suggestFaqAnswers(
226       SuggestFaqAnswersRequest request,
227       StreamObserver<SuggestFaqAnswersResponse> responseObserver) {
228     Object response = responses.poll();
229     if (response instanceof SuggestFaqAnswersResponse) {
230       requests.add(request);
231       responseObserver.onNext(((SuggestFaqAnswersResponse) response));
232       responseObserver.onCompleted();
233     } else if (response instanceof Exception) {
234       responseObserver.onError(((Exception) response));
235     } else {
236       responseObserver.onError(
237           new IllegalArgumentException(
238               String.format(
239                   "Unrecognized response type %s for method SuggestFaqAnswers, expected %s or %s",
240                   response == null ? "null" : response.getClass().getName(),
241                   SuggestFaqAnswersResponse.class.getName(),
242                   Exception.class.getName())));
243     }
244   }
245 
246   @Override
suggestSmartReplies( SuggestSmartRepliesRequest request, StreamObserver<SuggestSmartRepliesResponse> responseObserver)247   public void suggestSmartReplies(
248       SuggestSmartRepliesRequest request,
249       StreamObserver<SuggestSmartRepliesResponse> responseObserver) {
250     Object response = responses.poll();
251     if (response instanceof SuggestSmartRepliesResponse) {
252       requests.add(request);
253       responseObserver.onNext(((SuggestSmartRepliesResponse) response));
254       responseObserver.onCompleted();
255     } else if (response instanceof Exception) {
256       responseObserver.onError(((Exception) response));
257     } else {
258       responseObserver.onError(
259           new IllegalArgumentException(
260               String.format(
261                   "Unrecognized response type %s for method SuggestSmartReplies, expected %s or %s",
262                   response == null ? "null" : response.getClass().getName(),
263                   SuggestSmartRepliesResponse.class.getName(),
264                   Exception.class.getName())));
265     }
266   }
267 
268   @Override
listSuggestions( ListSuggestionsRequest request, StreamObserver<ListSuggestionsResponse> responseObserver)269   public void listSuggestions(
270       ListSuggestionsRequest request, StreamObserver<ListSuggestionsResponse> responseObserver) {
271     Object response = responses.poll();
272     if (response instanceof ListSuggestionsResponse) {
273       requests.add(request);
274       responseObserver.onNext(((ListSuggestionsResponse) response));
275       responseObserver.onCompleted();
276     } else if (response instanceof Exception) {
277       responseObserver.onError(((Exception) response));
278     } else {
279       responseObserver.onError(
280           new IllegalArgumentException(
281               String.format(
282                   "Unrecognized response type %s for method ListSuggestions, expected %s or %s",
283                   response == null ? "null" : response.getClass().getName(),
284                   ListSuggestionsResponse.class.getName(),
285                   Exception.class.getName())));
286     }
287   }
288 
289   @Override
compileSuggestion( CompileSuggestionRequest request, StreamObserver<CompileSuggestionResponse> responseObserver)290   public void compileSuggestion(
291       CompileSuggestionRequest request,
292       StreamObserver<CompileSuggestionResponse> responseObserver) {
293     Object response = responses.poll();
294     if (response instanceof CompileSuggestionResponse) {
295       requests.add(request);
296       responseObserver.onNext(((CompileSuggestionResponse) response));
297       responseObserver.onCompleted();
298     } else if (response instanceof Exception) {
299       responseObserver.onError(((Exception) response));
300     } else {
301       responseObserver.onError(
302           new IllegalArgumentException(
303               String.format(
304                   "Unrecognized response type %s for method CompileSuggestion, expected %s or %s",
305                   response == null ? "null" : response.getClass().getName(),
306                   CompileSuggestionResponse.class.getName(),
307                   Exception.class.getName())));
308     }
309   }
310 }
311