summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/controlloop/participant/http/handler/ClElementHandlerTest.java29
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandlerTest.java19
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/helm/HelmClientTest.java23
3 files changed, 71 insertions, 0 deletions
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;
@@ -64,6 +69,30 @@ class ClElementHandlerTest {
}
@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());
ControlLoopElement element = commonTestData.getControlLoopElement();
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;
@@ -106,6 +107,10 @@ class ControlLoopElementHandlerTest {
.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<HelmClient> 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