2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023-2024 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=========================================================
21 package org.onap.policy.clamp.acm.participant.kserve.k8s;
23 import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
24 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.mock;
29 import io.kubernetes.client.openapi.ApiException;
30 import java.io.IOException;
31 import org.junit.jupiter.api.Test;
32 import org.onap.policy.clamp.acm.participant.kserve.exception.KserveException;
34 class InferenceServiceValidatorTest {
36 private static final int TIMEOUT = 2;
37 private static final int STATUS_CHECK_INTERVAL = 1;
39 private static final String inferenceSvcName = "inference-test";
40 private static final String namespace = "test";
43 void test_runningPodState() throws IOException, ApiException {
44 var kserveClient = mock(KserveClient.class);
45 doReturn("True").when(kserveClient).getInferenceServiceStatus(any(), any());
46 var inferenceServiceValidator =
47 new InferenceServiceValidator(inferenceSvcName, namespace, TIMEOUT, STATUS_CHECK_INTERVAL,
49 assertDoesNotThrow(inferenceServiceValidator::run);
53 void test_EmptyPodState() throws IOException, ApiException {
54 var kserveClient = mock(KserveClient.class);
55 doReturn("").when(kserveClient).getInferenceServiceStatus(any(), any());
56 var inferenceServiceValidator =
57 new InferenceServiceValidator("", namespace, TIMEOUT, STATUS_CHECK_INTERVAL,
59 assertThatThrownBy(inferenceServiceValidator::run).isInstanceOf(KserveException.class)
60 .cause().hasMessage("Kserve setup is unavailable for inference service to be deployed");
64 void test_PodFailureState() throws IOException, ApiException {
65 var kserveClient = mock(KserveClient.class);
66 doReturn("False").when(kserveClient).getInferenceServiceStatus(any(), any());
67 var inferenceServiceValidator =
68 new InferenceServiceValidator(inferenceSvcName, namespace, TIMEOUT, STATUS_CHECK_INTERVAL,
70 assertThatThrownBy(inferenceServiceValidator::run).isInstanceOf(KserveException.class)
71 .hasMessage("Error verifying the status of the inference service. Exiting");