From bb4b558d8c253381b1ab04bd300f495dc10a1a7c Mon Sep 17 00:00:00 2001 From: lapentafd Date: Wed, 17 Nov 2021 16:51:16 +0000 Subject: Code coverage clamp participant Issue-ID: POLICY-3452 Change-Id: I5de10918f91ff2857cf81cc362c9cbecfcb01ec1 Signed-off-by: lapentafd --- .../http/handler/ClElementHandlerTest.java | 29 ++++++++++++++++++++++ .../handler/ControlLoopElementHandlerTest.java | 19 ++++++++++++++ .../kubernetes/helm/HelmClientTest.java | 23 +++++++++++++++++ 3 files changed, 71 insertions(+) (limited to 'participant') diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/controlloop/participant/http/handler/ClElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/controlloop/participant/http/handler/ClElementHandlerTest.java index d80436ef3..28b62c2c5 100644 --- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/controlloop/participant/http/handler/ClElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/controlloop/participant/http/handler/ClElementHandlerTest.java @@ -24,15 +24,20 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; +import java.io.IOException; import java.util.Map; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.Spy; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; import org.onap.policy.clamp.controlloop.participant.http.main.handler.ControlLoopElementHandler; +import org.onap.policy.clamp.controlloop.participant.http.main.models.ConfigRequest; import org.onap.policy.clamp.controlloop.participant.http.utils.CommonTestData; import org.onap.policy.clamp.controlloop.participant.http.utils.ToscaUtils; import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi; @@ -63,6 +68,30 @@ class ClElementHandlerTest { serviceTemplate = ToscaUtils.readControlLoopFromTosca(); } + @Test + void test_controlLoopElementeStateChange() throws IOException { + var controlLoopId = commonTestData.getControlLoopId(); + var element = commonTestData.getControlLoopElement(); + var controlLoopElementId = element.getId(); + + var config = Mockito.mock(ConfigRequest.class); + assertDoesNotThrow(() -> controlLoopElementHandler.invokeHttpClient(config)); + + assertDoesNotThrow(() -> controlLoopElementHandler + .controlLoopElementStateChange(controlLoopId, + controlLoopElementId, ControlLoopState.PASSIVE, ControlLoopOrderedState.PASSIVE)); + + assertDoesNotThrow(() -> controlLoopElementHandler + .controlLoopElementStateChange(controlLoopId, + controlLoopElementId, ControlLoopState.PASSIVE, ControlLoopOrderedState.UNINITIALISED)); + + assertDoesNotThrow(() -> controlLoopElementHandler + .controlLoopElementStateChange(controlLoopId, + controlLoopElementId, ControlLoopState.PASSIVE, ControlLoopOrderedState.RUNNING)); + + controlLoopElementHandler.close(); + } + @Test void test_ControlLoopElementUpdate() { doNothing().when(controlLoopElementHandler).invokeHttpClient(any()); diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandlerTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandlerTest.java index 1f8e76952..d7f09705b 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandlerTest.java @@ -27,6 +27,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.when; import java.io.File; import java.io.IOException; @@ -105,6 +106,10 @@ class ControlLoopElementHandlerTest { doThrow(new ServiceException("Error uninstalling the chart")).when(chartService) .uninstallChart(charts.get(0)); + assertDoesNotThrow(() -> controlLoopElementHandler + .controlLoopElementStateChange(commonTestData.getControlLoopId(), controlLoopElementId1, + ControlLoopState.PASSIVE, ControlLoopOrderedState.PASSIVE)); + assertDoesNotThrow(() -> controlLoopElementHandler .controlLoopElementStateChange(commonTestData.getControlLoopId(), controlLoopElementId1, ControlLoopState.PASSIVE, ControlLoopOrderedState.UNINITIALISED)); @@ -141,4 +146,18 @@ class ControlLoopElementHandlerTest { assertThat(controlLoopElementHandler.getChartMap().containsKey(elementId2)).isFalse(); } + + @Test + void test_handleStatistics() throws PfModelException { + UUID elementId1 = UUID.randomUUID(); + controlLoopElementHandler.getChartMap().put(elementId1, charts.get(0)); + when(participantIntermediaryApi.getControlLoopElement(elementId1)).thenReturn(new ControlLoopElement()); + assertDoesNotThrow(() -> controlLoopElementHandler.handleStatistics(elementId1)); + } + + @Test + void test_checkPodStatus() { + var chartInfo = charts.get(0); + assertDoesNotThrow(() -> controlLoopElementHandler.checkPodStatus(chartInfo, 1, 1)); + } } diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/helm/HelmClientTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/helm/HelmClientTest.java index 41b1fbeb5..335dbcb21 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/helm/HelmClientTest.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/helm/HelmClientTest.java @@ -29,6 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; import java.io.File; import java.io.IOException; @@ -46,6 +47,7 @@ import org.mockito.Spy; import org.onap.policy.clamp.controlloop.participant.kubernetes.exception.ServiceException; import org.onap.policy.clamp.controlloop.participant.kubernetes.models.ChartInfo; import org.onap.policy.clamp.controlloop.participant.kubernetes.models.ChartList; +import org.onap.policy.clamp.controlloop.participant.kubernetes.models.HelmRepository; import org.onap.policy.clamp.controlloop.participant.kubernetes.service.ChartStore; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; @@ -68,6 +70,9 @@ class HelmClientTest { @Mock ChartStore chartStore; + @Mock + HelmRepository repo; + private static MockedStatic mockedClient; @BeforeAll @@ -90,9 +95,27 @@ class HelmClientTest { doReturn(new File("/target/tmp/override.yaml")).when(chartStore) .getOverrideFile(any()); var chartinfo = charts.get(0); + assertDoesNotThrow(() -> helmClient.installChart(chartinfo)); chartinfo.setNamespace(""); assertDoesNotThrow(() -> helmClient.installChart(chartinfo)); + + mockedClient.when(() -> HelmClient.executeCommand(any())) + .thenReturn(new String()); + assertDoesNotThrow(() -> helmClient.installChart(chartinfo)); + + } + + @Test + void test_addRepository() throws IOException { + mockedClient.when(() -> HelmClient.executeCommand(any())) + .thenReturn(new String()); + when(repo.getRepoName()).thenReturn("RepoName"); + assertDoesNotThrow(() -> helmClient.addRepository(repo)); + + mockedClient.when(() -> HelmClient.executeCommand(any())) + .thenReturn("failed"); + assertDoesNotThrow(() -> helmClient.addRepository(repo)); } @Test -- cgit 1.2.3-korg