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=========================================================
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;
28 import io.kubernetes.client.openapi.ApiException;
29 import java.io.IOException;
30 import org.junit.jupiter.api.Test;
31 import org.junit.jupiter.api.extension.ExtendWith;
32 import org.onap.policy.clamp.acm.participant.kserve.exception.KserveException;
33 import org.springframework.boot.test.mock.mockito.MockBean;
34 import org.springframework.test.context.junit.jupiter.SpringExtension;
37 @ExtendWith(SpringExtension.class)
38 class InferenceServiceValidatorTest {
40 private static int TIMEOUT = 2;
41 private static int STATUS_CHECK_INTERVAL = 1;
44 private KserveClient kserveClient;
46 String inferenceSvcName = "inference-test";
47 String namespace = "test";
50 void test_runningPodState() throws IOException, ApiException {
51 doReturn("True").when(kserveClient).getInferenceServiceStatus(any(), any());
52 var inferenceServiceValidator =
53 new InferenceServiceValidator(inferenceSvcName, namespace, TIMEOUT, STATUS_CHECK_INTERVAL,
55 assertDoesNotThrow(inferenceServiceValidator::run);
59 void test_EmptyPodState() throws IOException, ApiException {
60 doReturn("").when(kserveClient).getInferenceServiceStatus(any(), any());
61 var inferenceServiceValidator =
62 new InferenceServiceValidator("", namespace, TIMEOUT, STATUS_CHECK_INTERVAL,
64 assertThatThrownBy(inferenceServiceValidator::run).isInstanceOf(KserveException.class)
65 .cause().hasMessage("Kserve setup is unavailable for inference service to be deployed");
69 void test_PodFailureState() throws IOException, ApiException {
70 doReturn("False").when(kserveClient).getInferenceServiceStatus(any(), any());
71 var inferenceServiceValidator =
72 new InferenceServiceValidator(inferenceSvcName, namespace, TIMEOUT, STATUS_CHECK_INTERVAL,
74 assertThatThrownBy(inferenceServiceValidator::run).isInstanceOf(KserveException.class)
75 .hasMessage("Error verifying the status of the inference service. Exiting");