|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | +package com.cloud.kubernetes.version; |
| 18 | + |
| 19 | +import java.util.UUID; |
| 20 | + |
| 21 | +import org.apache.cloudstack.api.response.KubernetesSupportedVersionResponse; |
| 22 | +import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; |
| 23 | +import org.junit.Assert; |
| 24 | +import org.junit.Test; |
| 25 | +import org.junit.runner.RunWith; |
| 26 | +import org.mockito.InjectMocks; |
| 27 | +import org.mockito.Mock; |
| 28 | +import org.mockito.Mockito; |
| 29 | +import org.mockito.junit.MockitoJUnitRunner; |
| 30 | +import org.springframework.test.util.ReflectionTestUtils; |
| 31 | + |
| 32 | +import com.cloud.api.query.dao.TemplateJoinDao; |
| 33 | +import com.cloud.api.query.vo.TemplateJoinVO; |
| 34 | + |
| 35 | +@RunWith(MockitoJUnitRunner.class) |
| 36 | +public class KubernetesVersionManagerImplTest { |
| 37 | + |
| 38 | + @Mock |
| 39 | + TemplateJoinDao templateJoinDao; |
| 40 | + |
| 41 | + @InjectMocks |
| 42 | + KubernetesVersionManagerImpl kubernetesVersionManager = new KubernetesVersionManagerImpl(); |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testUpdateTemplateDetailsInKubernetesSupportedVersionResponseNullTemplate() { |
| 46 | + KubernetesSupportedVersion kubernetesSupportedVersion = Mockito.mock(KubernetesSupportedVersion.class); |
| 47 | + Mockito.when(kubernetesSupportedVersion.getIsoId()).thenReturn(1L); |
| 48 | + KubernetesSupportedVersionResponse response = new KubernetesSupportedVersionResponse(); |
| 49 | + kubernetesVersionManager.updateTemplateDetailsInKubernetesSupportedVersionResponse(kubernetesSupportedVersion, |
| 50 | + response); |
| 51 | + Assert.assertNull(ReflectionTestUtils.getField(response, "isoId")); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void testUpdateTemplateDetailsInKubernetesSupportedVersionResponseValidTemplate() { |
| 56 | + KubernetesSupportedVersion kubernetesSupportedVersion = Mockito.mock(KubernetesSupportedVersion.class); |
| 57 | + Mockito.when(kubernetesSupportedVersion.getIsoId()).thenReturn(1L); |
| 58 | + KubernetesSupportedVersionResponse response = new KubernetesSupportedVersionResponse(); |
| 59 | + TemplateJoinVO templateJoinVO = Mockito.mock(TemplateJoinVO.class); |
| 60 | + String uuid = UUID.randomUUID().toString(); |
| 61 | + Mockito.when(templateJoinVO.getUuid()).thenReturn(uuid); |
| 62 | + Mockito.when(templateJoinDao.findById(1L)).thenReturn(templateJoinVO); |
| 63 | + kubernetesVersionManager.updateTemplateDetailsInKubernetesSupportedVersionResponse(kubernetesSupportedVersion, |
| 64 | + response); |
| 65 | + Assert.assertEquals(uuid, ReflectionTestUtils.getField(response, "isoId")); |
| 66 | + Assert.assertNull(ReflectionTestUtils.getField(response, "isoState")); |
| 67 | + ObjectInDataStoreStateMachine.State state = ObjectInDataStoreStateMachine.State.Ready; |
| 68 | + Mockito.when(templateJoinVO.getState()).thenReturn(state); |
| 69 | + kubernetesVersionManager.updateTemplateDetailsInKubernetesSupportedVersionResponse(kubernetesSupportedVersion, |
| 70 | + response); |
| 71 | + Assert.assertEquals(state.toString(), ReflectionTestUtils.getField(response, "isoState")); |
| 72 | + } |
| 73 | +} |
0 commit comments