2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.cnfm.lcm.bpmn.flows.extclients.kubernetes;
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertTrue;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.doNothing;
26 import static org.mockito.Mockito.doThrow;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.when;
29 import java.io.IOException;
31 import java.util.UUID;
32 import org.junit.Test;
33 import org.onap.so.cnfm.lcm.bpmn.flows.GsonProvider;
34 import org.onap.so.cnfm.lcm.bpmn.flows.exceptions.KubernetesRequestProcessingException;
35 import com.google.gson.Gson;
36 import io.kubernetes.client.custom.IntOrString;
37 import io.kubernetes.client.openapi.ApiClient;
38 import io.kubernetes.client.openapi.ApiException;
39 import io.kubernetes.client.openapi.JSON;
40 import io.kubernetes.client.openapi.models.V1DaemonSet;
41 import io.kubernetes.client.openapi.models.V1DaemonSetSpec;
42 import io.kubernetes.client.openapi.models.V1DaemonSetStatus;
43 import io.kubernetes.client.openapi.models.V1DaemonSetUpdateStrategy;
44 import io.kubernetes.client.openapi.models.V1Deployment;
45 import io.kubernetes.client.openapi.models.V1DeploymentSpec;
46 import io.kubernetes.client.openapi.models.V1DeploymentStatus;
47 import io.kubernetes.client.openapi.models.V1Job;
48 import io.kubernetes.client.openapi.models.V1JobCondition;
49 import io.kubernetes.client.openapi.models.V1JobStatus;
50 import io.kubernetes.client.openapi.models.V1ObjectMeta;
51 import io.kubernetes.client.openapi.models.V1Pod;
52 import io.kubernetes.client.openapi.models.V1PodCondition;
53 import io.kubernetes.client.openapi.models.V1PodStatus;
54 import io.kubernetes.client.openapi.models.V1ReplicaSet;
55 import io.kubernetes.client.openapi.models.V1ReplicaSetSpec;
56 import io.kubernetes.client.openapi.models.V1ReplicaSetStatus;
57 import io.kubernetes.client.openapi.models.V1RollingUpdateDaemonSet;
58 import io.kubernetes.client.openapi.models.V1RollingUpdateStatefulSetStrategy;
59 import io.kubernetes.client.openapi.models.V1Service;
60 import io.kubernetes.client.openapi.models.V1StatefulSet;
61 import io.kubernetes.client.openapi.models.V1StatefulSetSpec;
62 import io.kubernetes.client.openapi.models.V1StatefulSetStatus;
63 import io.kubernetes.client.openapi.models.V1StatefulSetUpdateStrategy;
64 import io.kubernetes.client.util.Watch;
66 import okhttp3.Response;
67 import okhttp3.ResponseBody;
68 import okio.BufferedSource;
72 * @author Waqas Ikram (waqas.ikram@est.tech)
75 public class KubernetesClientTest {
77 private static final String DUMMY_LABEL_SELECTOR = "app.kubernetes.io/instance=test";
78 private static final String BATCH_V1 = "batch/v1";
79 private static final String V1 = "v1";
80 private static final String APPS_V1 = "apps/v1";
81 private static final String RESPONSE_TYPE_ADDED = "ADDED";
82 private static final String RANDOM_UUID = UUID.randomUUID().toString();
83 private final GsonProvider gsonProvider = new GsonProvider();
84 private final Gson gson = gsonProvider.getGson();
85 private final JSON json = new JSON();
87 private final KubernetesClient objUnderTest = new KubernetesClientImpl();
90 public void testIsJobReady_jobStatusComplete_true() throws ApiException, IOException {
92 final ApiClient mockedApiClient = mockApiClientResponse(getJobResponse("Complete", "Running"));
93 assertTrue(objUnderTest.isJobReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
97 @Test(expected = KubernetesRequestProcessingException.class)
98 public void testIsJobReady_jobStatusFailed_throwException() throws ApiException, IOException {
100 final ApiClient mockedApiClient = mockApiClientResponse(getJobResponse("Failed", "Not Running"));
101 objUnderTest.isJobReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
105 @Test(expected = KubernetesRequestProcessingException.class)
106 public void testIsJobReady_apiExceptionThrown_throwsException() throws ApiException, IOException {
108 final ApiClient mockedApiClient = mockApiClientResponse(ApiException.class);
109 objUnderTest.isJobReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
113 @Test(expected = KubernetesRequestProcessingException.class)
114 public void testIsJobReady_RuntimeExceptionThrown_throwsException() throws ApiException, IOException {
116 final ApiClient mockedApiClient = mockApiClientResponse(RuntimeException.class);
117 objUnderTest.isJobReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
122 public void testIsJobReady_jobStatusPending_false() throws ApiException, IOException {
124 final ApiClient mockedApiClient = mockApiClientResponse(getJobResponse("pending", "pending"));
125 assertFalse(objUnderTest.isJobReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
130 public void testIsPodReady_statusTrue_true() throws ApiException, IOException {
132 final V1PodCondition condition = new V1PodCondition().type("Ready").status(Boolean.TRUE.toString());
133 final ApiClient mockedApiClient = mockApiClientResponse(getPodResponse(condition));
134 assertTrue(objUnderTest.isPodReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
139 public void testIsPodReady_statusFalse_false() throws ApiException, IOException {
141 final V1PodCondition condition = new V1PodCondition().type("Ready").status(Boolean.FALSE.toString());
142 final ApiClient mockedApiClient = mockApiClientResponse(getPodResponse(condition));
143 assertFalse(objUnderTest.isPodReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
148 public void testIsPodReady_missingCondition_false() throws ApiException, IOException {
150 final ApiClient mockedApiClient = mockApiClientResponse(getPodResponse(null));
151 assertFalse(objUnderTest.isPodReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
155 @Test(expected = KubernetesRequestProcessingException.class)
156 public void testIsPodReady_apiExceptionThrown_throwsException() throws ApiException, IOException {
158 final ApiClient mockedApiClient = mockApiClientResponse(ApiException.class);
159 objUnderTest.isPodReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
163 @Test(expected = KubernetesRequestProcessingException.class)
164 public void testIsPodReady_RuntimeExceptionThrown_throwsException() throws ApiException, IOException {
166 final ApiClient mockedApiClient = mockApiClientResponse(RuntimeException.class);
167 objUnderTest.isPodReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
172 public void testIsServiceReady_exists_true() throws ApiException, IOException {
173 final ApiClient mockedApiClient = mockApiClientResponse(getServiceResponse());
174 assertTrue(objUnderTest.isServiceReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
178 @Test(expected = KubernetesRequestProcessingException.class)
179 public void testIsServiceReady_apiExceptionThrown_throwsException() throws ApiException, IOException {
181 final ApiClient mockedApiClient = mockApiClientResponse(ApiException.class);
182 objUnderTest.isServiceReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
186 @Test(expected = KubernetesRequestProcessingException.class)
187 public void testIsServiceReady_RuntimeExceptionThrown_throwsException() throws ApiException, IOException {
189 final ApiClient mockedApiClient = mockApiClientResponse(RuntimeException.class);
190 objUnderTest.isServiceReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
195 public void testIsDeploymentReady_statusAvailable_true() throws ApiException, IOException {
197 final V1DeploymentStatus status =
198 new V1DeploymentStatus().replicas(Integer.valueOf(2)).availableReplicas(Integer.valueOf(2));
199 final V1DeploymentSpec spec = new V1DeploymentSpec().replicas(Integer.valueOf(2));
201 final ApiClient mockedApiClient = mockApiClientResponse(getDeploymentResponse(status, spec));
202 assertTrue(objUnderTest.isDeploymentReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
207 public void testIsDeploymentReady_statusNotAvailable_false() throws ApiException, IOException {
209 final V1DeploymentStatus status =
210 new V1DeploymentStatus().replicas(Integer.valueOf(2)).availableReplicas(Integer.valueOf(3));
211 final V1DeploymentSpec spec = new V1DeploymentSpec().replicas(Integer.valueOf(2));
213 final ApiClient mockedApiClient = mockApiClientResponse(getDeploymentResponse(status, spec));
214 assertFalse(objUnderTest.isDeploymentReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
219 public void testIsDeploymentReady_statusIsNull_false() throws ApiException, IOException {
221 final V1DeploymentSpec spec = new V1DeploymentSpec().replicas(Integer.valueOf(2));
223 final ApiClient mockedApiClient = mockApiClientResponse(getDeploymentResponse(null, spec));
224 assertFalse(objUnderTest.isDeploymentReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
228 @Test(expected = KubernetesRequestProcessingException.class)
229 public void testIsDeploymentReady_apiExceptionThrown_throwsException() throws ApiException, IOException {
231 final ApiClient mockedApiClient = mockApiClientResponse(ApiException.class);
232 objUnderTest.isDeploymentReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
236 @Test(expected = KubernetesRequestProcessingException.class)
237 public void testIsDeploymentReady_RuntimeExceptionThrown_throwsException() throws ApiException, IOException {
239 final ApiClient mockedApiClient = mockApiClientResponse(RuntimeException.class);
240 objUnderTest.isDeploymentReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
246 public void testIsReplicaSetReady_statusReady_true() throws ApiException, IOException {
248 final V1ReplicaSetStatus status = new V1ReplicaSetStatus().readyReplicas(Integer.valueOf(1));
249 final V1ReplicaSetSpec spec = new V1ReplicaSetSpec().replicas(Integer.valueOf(1));
251 final ApiClient mockedApiClient = mockApiClientResponse(getReplicaSetResponse(status, spec));
252 assertTrue(objUnderTest.isReplicaSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
257 public void testIsReplicaSetReady_statusNotReady_false() throws ApiException, IOException {
259 final V1ReplicaSetStatus status = new V1ReplicaSetStatus().readyReplicas(Integer.valueOf(1));
260 final V1ReplicaSetSpec spec = new V1ReplicaSetSpec().replicas(Integer.valueOf(2));
262 final ApiClient mockedApiClient = mockApiClientResponse(getReplicaSetResponse(status, spec));
263 assertFalse(objUnderTest.isReplicaSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
268 public void testIsReplicaSetReady_specIsNull_false() throws ApiException, IOException {
270 final V1ReplicaSetStatus status = new V1ReplicaSetStatus().readyReplicas(Integer.valueOf(1));
272 final ApiClient mockedApiClient = mockApiClientResponse(getReplicaSetResponse(status, null));
273 assertFalse(objUnderTest.isReplicaSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
277 @Test(expected = KubernetesRequestProcessingException.class)
278 public void testIsReplicaSetReady_apiExceptionThrown_throwsException() throws ApiException, IOException {
280 final ApiClient mockedApiClient = mockApiClientResponse(ApiException.class);
281 objUnderTest.isReplicaSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
285 @Test(expected = KubernetesRequestProcessingException.class)
286 public void testIsReplicaSetReady_RuntimeExceptionThrown_throwsException() throws ApiException, IOException {
288 final ApiClient mockedApiClient = mockApiClientResponse(RuntimeException.class);
289 objUnderTest.isReplicaSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
294 public void testIsDaemonSetReady_statusRollingUpdate_true() throws ApiException, IOException {
296 final V1RollingUpdateDaemonSet rollingUpdate =
297 new V1RollingUpdateDaemonSet().maxUnavailable(new IntOrString("50%"));
298 final V1DaemonSetSpec spec = new V1DaemonSetSpec()
299 .updateStrategy(new V1DaemonSetUpdateStrategy().type("RollingUpdate").rollingUpdate(rollingUpdate));
300 final V1DaemonSetStatus status = new V1DaemonSetStatus().desiredNumberScheduled(Integer.valueOf(2))
301 .numberReady(Integer.valueOf(2)).updatedNumberScheduled(Integer.valueOf(2));
303 final ApiClient mockedApiClient = mockApiClientResponse(getDaemonSetResponse(status, spec));
304 assertTrue(objUnderTest.isDaemonSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
310 public void testIsDaemonSetReady_statusRollingUpdateTypeRecreate_true() throws ApiException, IOException {
312 final V1DaemonSetSpec spec =
313 new V1DaemonSetSpec().updateStrategy(new V1DaemonSetUpdateStrategy().type("Recreate"));
314 final V1DaemonSetStatus status = new V1DaemonSetStatus();
316 final ApiClient mockedApiClient = mockApiClientResponse(getDaemonSetResponse(status, spec));
317 assertTrue(objUnderTest.isDaemonSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
322 public void testIsDaemonSetReady_updateAndDesiredScheduledNumberIsNotSame_true() throws ApiException, IOException {
324 final V1DaemonSetSpec spec =
325 new V1DaemonSetSpec().updateStrategy(new V1DaemonSetUpdateStrategy().type("RollingUpdate"));
326 final V1DaemonSetStatus status = new V1DaemonSetStatus().desiredNumberScheduled(Integer.valueOf(3))
327 .updatedNumberScheduled(Integer.valueOf(2));
330 final ApiClient mockedApiClient = mockApiClientResponse(getDaemonSetResponse(status, spec));
331 assertFalse(objUnderTest.isDaemonSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
336 public void testIsDaemonSetReady_rollingUpdateWithMaxUnavailableIntValAndDesiredNumberReady_true()
337 throws ApiException, IOException {
339 final V1RollingUpdateDaemonSet rollingUpdate =
340 new V1RollingUpdateDaemonSet().maxUnavailable(new IntOrString(4));
341 final V1DaemonSetSpec spec = new V1DaemonSetSpec()
342 .updateStrategy(new V1DaemonSetUpdateStrategy().type("RollingUpdate").rollingUpdate(rollingUpdate));
343 final V1DaemonSetStatus status = new V1DaemonSetStatus().desiredNumberScheduled(Integer.valueOf(6))
344 .numberReady(Integer.valueOf(2)).updatedNumberScheduled(Integer.valueOf(6));
346 final ApiClient mockedApiClient = mockApiClientResponse(getDaemonSetResponse(status, spec));
347 assertTrue(objUnderTest.isDaemonSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
353 public void testIsDaemonSetReady_rollingUpdateWithMaxUnavailableIntValAndDesiredNumberNotReady_false()
354 throws ApiException, IOException {
356 final V1RollingUpdateDaemonSet rollingUpdate =
357 new V1RollingUpdateDaemonSet().maxUnavailable(new IntOrString(4));
358 final V1DaemonSetSpec spec = new V1DaemonSetSpec()
359 .updateStrategy(new V1DaemonSetUpdateStrategy().type("RollingUpdate").rollingUpdate(rollingUpdate));
360 final V1DaemonSetStatus status = new V1DaemonSetStatus().desiredNumberScheduled(Integer.valueOf(6))
361 .numberReady(Integer.valueOf(1)).updatedNumberScheduled(Integer.valueOf(6));
363 final ApiClient mockedApiClient = mockApiClientResponse(getDaemonSetResponse(status, spec));
364 assertFalse(objUnderTest.isDaemonSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
368 @Test(expected = KubernetesRequestProcessingException.class)
369 public void testIsDaemonSetReady_apiExceptionThrown_throwsException() throws ApiException, IOException {
371 final ApiClient mockedApiClient = mockApiClientResponse(ApiException.class);
372 objUnderTest.isDaemonSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
376 @Test(expected = KubernetesRequestProcessingException.class)
377 public void testIsDaemonSetReady_RuntimeExceptionThrown_throwsException() throws ApiException, IOException {
379 final ApiClient mockedApiClient = mockApiClientResponse(RuntimeException.class);
380 objUnderTest.isDaemonSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
385 public void testIsStatefulSetReady_rollingUpdateAndReplicasSameAsReadyReplicas_true()
386 throws IOException, ApiException {
388 final V1StatefulSetUpdateStrategy updateStrategy = new V1StatefulSetUpdateStrategy().type("RollingUpdate")
389 .rollingUpdate(new V1RollingUpdateStatefulSetStrategy().partition(Integer.valueOf(0)));
390 final V1StatefulSetSpec spec =
391 new V1StatefulSetSpec().updateStrategy(updateStrategy).replicas(Integer.valueOf(2));
392 final V1StatefulSetStatus status =
393 new V1StatefulSetStatus().updatedReplicas(Integer.valueOf(2)).readyReplicas(Integer.valueOf(2));
395 final ApiClient mockedApiClient = mockApiClientResponse(getStatefulSetResponse(status, spec));
396 assertTrue(objUnderTest.isStatefulSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
402 public void testIsStatefulSetReady_updateStrategyRecreate_true() throws IOException, ApiException {
404 final V1StatefulSetUpdateStrategy updateStrategy = new V1StatefulSetUpdateStrategy().type("Recreate");
405 final V1StatefulSetSpec spec = new V1StatefulSetSpec().updateStrategy(updateStrategy);
406 final V1StatefulSetStatus status = new V1StatefulSetStatus();
408 final ApiClient mockedApiClient = mockApiClientResponse(getStatefulSetResponse(status, spec));
409 assertTrue(objUnderTest.isStatefulSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
414 public void testIsStatefulSetReady_rollingUpdateAndUnExpectedReplicas_false() throws IOException, ApiException {
416 final V1StatefulSetUpdateStrategy updateStrategy = new V1StatefulSetUpdateStrategy().type("RollingUpdate")
417 .rollingUpdate(new V1RollingUpdateStatefulSetStrategy().partition(Integer.valueOf(2)));
418 final V1StatefulSetSpec spec =
419 new V1StatefulSetSpec().updateStrategy(updateStrategy).replicas(Integer.valueOf(6));
420 final V1StatefulSetStatus status = new V1StatefulSetStatus().updatedReplicas(Integer.valueOf(2));
422 final ApiClient mockedApiClient = mockApiClientResponse(getStatefulSetResponse(status, spec));
423 assertFalse(objUnderTest.isStatefulSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR));
426 @Test(expected = KubernetesRequestProcessingException.class)
427 public void testIsStatefulSetReady_apiExceptionThrown_throwsException() throws ApiException, IOException {
429 final ApiClient mockedApiClient = mockApiClientResponse(ApiException.class);
430 objUnderTest.isStatefulSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
434 @Test(expected = KubernetesRequestProcessingException.class)
435 public void testIsStatefulSetReady_RuntimeExceptionThrown_throwsException() throws ApiException, IOException {
437 final ApiClient mockedApiClient = mockApiClientResponse(RuntimeException.class);
438 objUnderTest.isStatefulSetReady(mockedApiClient, DUMMY_LABEL_SELECTOR);
442 private String getStatefulSetResponse(final V1StatefulSetStatus status, final V1StatefulSetSpec spec) {
443 return gson.toJson(new Watch.Response<V1StatefulSet>(RESPONSE_TYPE_ADDED, getStatefulSet(status, spec)));
446 private V1StatefulSet getStatefulSet(final V1StatefulSetStatus status, final V1StatefulSetSpec spec) {
447 return new V1StatefulSet().apiVersion(APPS_V1).metadata(getV1ObjectMeta()).spec(spec).status(status);
450 private String getDaemonSetResponse(final V1DaemonSetStatus status, final V1DaemonSetSpec spec) {
451 return gson.toJson(new Watch.Response<V1DaemonSet>(RESPONSE_TYPE_ADDED, getDaemonSet(status, spec)));
454 private V1DaemonSet getDaemonSet(final V1DaemonSetStatus status, final V1DaemonSetSpec spec) {
455 return new V1DaemonSet().apiVersion(APPS_V1).metadata(getV1ObjectMeta()).spec(spec).status(status);
458 private String getReplicaSetResponse(final V1ReplicaSetStatus status, final V1ReplicaSetSpec spec) {
459 return gson.toJson(new Watch.Response<V1ReplicaSet>(RESPONSE_TYPE_ADDED, getReplicaSet(status, spec)));
462 private V1ReplicaSet getReplicaSet(final V1ReplicaSetStatus status, final V1ReplicaSetSpec spec) {
463 return new V1ReplicaSet().apiVersion(APPS_V1).metadata(getV1ObjectMeta()).status(status).spec(spec);
466 private String getDeploymentResponse(final V1DeploymentStatus status, final V1DeploymentSpec spec) {
467 return gson.toJson(new Watch.Response<V1Deployment>(RESPONSE_TYPE_ADDED, getDeployment(status, spec)));
470 private V1Deployment getDeployment(final V1DeploymentStatus status, final V1DeploymentSpec spec) {
471 return new V1Deployment().apiVersion(APPS_V1).metadata(getV1ObjectMeta()).status(status).spec(spec);
474 private String getServiceResponse() {
475 return gson.toJson(new Watch.Response<V1Service>(RESPONSE_TYPE_ADDED, getService()));
478 private V1Service getService() {
479 return new V1Service().apiVersion(V1).metadata(getV1ObjectMeta());
482 private String getPodResponse(final V1PodCondition condition) {
483 return gson.toJson(new Watch.Response<V1Pod>(RESPONSE_TYPE_ADDED, getPod(condition)));
486 private V1Pod getPod(final V1PodCondition condition) {
487 final V1Pod pod = new V1Pod().apiVersion(V1).metadata(getV1ObjectMeta());
488 if (condition != null) {
489 return pod.status(new V1PodStatus().addConditionsItem(condition));
494 private String getJobResponse(final String type, final String reason) {
495 return gson.toJson(new Watch.Response<V1Job>(RESPONSE_TYPE_ADDED, getJob(type, reason)));
498 private V1Job getJob(final String type, final String reason) {
499 return new V1Job().apiVersion(BATCH_V1).metadata(getV1ObjectMeta()).status(new V1JobStatus()
500 .addConditionsItem(new V1JobCondition().type(type).status(Boolean.TRUE.toString()).reason(reason)));
503 private V1ObjectMeta getV1ObjectMeta() {
504 return new V1ObjectMeta().name("job-name").namespace("job-namespace").uid(RANDOM_UUID)
505 .resourceVersion(RANDOM_UUID).labels(Map.of("label-key", "label-value"));
508 private ApiClient mockApiClientResponse(final String response) throws IOException, ApiException {
509 final ApiClient mockedApiClient = mock(ApiClient.class);
510 final Response mockedResponse = mock(Response.class);
511 final ResponseBody mockedResponseBody = mock(ResponseBody.class);
512 final BufferedSource mockedBufferedSource = mock(BufferedSource.class);
513 final Call mockedCall = mock(Call.class);
515 when(mockedApiClient.getJSON()).thenReturn(json);
516 doNothing().when(mockedResponse).close();
517 when(mockedResponse.body()).thenReturn(mockedResponseBody);
518 when(mockedBufferedSource.readUtf8Line()).thenReturn(response);
519 when(mockedBufferedSource.exhausted()).thenReturn(false).thenReturn(true);
520 when(mockedResponseBody.source()).thenReturn(mockedBufferedSource);
521 when(mockedResponse.isSuccessful()).thenReturn(true);
522 when(mockedCall.execute()).thenReturn(mockedResponse);
523 when(mockedApiClient.buildCall(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()))
524 .thenReturn(mockedCall);
526 return mockedApiClient;
529 private ApiClient mockApiClientResponse(Class<? extends Throwable> exception) throws ApiException {
530 final ApiClient mockedApiClient = mock(ApiClient.class);
531 doThrow(exception).when(mockedApiClient).buildCall(any(), any(), any(), any(), any(), any(), any(), any(),
533 return mockedApiClient;