Clamp code coverage 20/125520/1
authorlapentafd <francesco.lapenta@est.tech>
Tue, 2 Nov 2021 09:10:54 +0000 (09:10 +0000)
committerlapentafd <francesco.lapenta@est.tech>
Tue, 2 Nov 2021 09:27:09 +0000 (09:27 +0000)
Issue-ID: POLICY-3452
Change-Id: I35c10562c5e11698491a5d93adcf417784395534
Signed-off-by: lapentafd <francesco.lapenta@est.tech>
participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/helm/HelmClientTest.java
participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/rest/ChartControllerTest.java
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java
runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java

index 79a37f8..41b1fbe 100644 (file)
@@ -89,7 +89,10 @@ class HelmClientTest {
             .thenReturn("success");
         doReturn(new File("/target/tmp/override.yaml")).when(chartStore)
             .getOverrideFile(any());
-        assertDoesNotThrow(() -> helmClient.installChart(charts.get(0)));
+        var chartinfo = charts.get(0);
+        assertDoesNotThrow(() -> helmClient.installChart(chartinfo));
+        chartinfo.setNamespace("");
+        assertDoesNotThrow(() -> helmClient.installChart(chartinfo));
     }
 
     @Test
index bbb57c3..2af2a01 100644 (file)
@@ -73,6 +73,7 @@ class ChartControllerTest {
     private static String UNINSTALL_CHART_URL = "/helm/uninstall/";
     private static String ONBOARD_CHART_URL = "/helm/onboard/chart";
     private static String DELETE_CHART_URL = "/helm/chart";
+    private static String CONFIGURE_REPO_URL = "/helm/repo";
 
     @Autowired
     private MockMvc mockMvc;
@@ -217,6 +218,23 @@ class ChartControllerTest {
 
     }
 
+    /**
+     * Test endpoint for configuring a helm repository.
+     * @throws Exception in case of error.
+     */
+    @Test
+    void testConfigureRepo() throws Exception {
+        RequestBuilder requestBuilder;
+
+        requestBuilder = MockMvcRequestBuilders.post(CONFIGURE_REPO_URL).accept(MediaType.APPLICATION_JSON_VALUE)
+            .content(getInstallationJson(charts.get(0).getChartId().getName(), charts.get(0).getChartId().getVersion()))
+            .contentType(MediaType.APPLICATION_JSON_VALUE);
+
+        mockMvc.perform(requestBuilder).andExpect(status().isCreated());
+
+    }
+
+
     private String getInstallationJson(String name, String version) {
         JSONObject jsonObj = new JSONObject();
         jsonObj.put("name", name);
index e77dd69..676747d 100644 (file)
@@ -132,11 +132,11 @@ class ControlLoopHandlerTest {
         stateChange.setTimestamp(Instant.ofEpochMilli(3000));
 
         var clh = setTestControlLoopHandler(id, uuid);
-        clh.handleControlLoopStateChange(stateChange);
+        clh.handleControlLoopStateChange(stateChange, List.of());
         var newid = new ToscaConceptIdentifier("id", "1.2.3");
         stateChange.setControlLoopId(newid);
         stateChange.setParticipantId(newid);
-        assertDoesNotThrow(() -> clh.handleControlLoopStateChange(stateChange));
+        assertDoesNotThrow(() -> clh.handleControlLoopStateChange(stateChange, List.of()));
 
         List<ControlLoopElementDefinition> clElementDefinitions = new ArrayList<>();
         var cld = new ControlLoopElementDefinition();
index d8892c8..ae1c598 100644 (file)
@@ -23,6 +23,9 @@ package org.onap.policy.clamp.controlloop.runtime.instantiation;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -34,6 +37,7 @@ import org.junit.jupiter.api.Test;
 import org.mockito.Mockito;
 import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
+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.models.controlloop.concepts.ControlLoops;
 import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ClElementStatisticsProvider;
@@ -63,7 +67,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
  *
  */
 class ControlLoopInstantiationProviderTest {
-
+    private static final String ID_NAME = "PMSH_Instance1";
+    private static final String ID_VERSION = "1.2.3";
     private static final String CL_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/controlloops/ControlLoops.json";
     private static final String CL_INSTANTIATION_UPDATE_JSON =
             "src/test/resources/rest/controlloops/ControlLoopsUpdate.json";
@@ -156,6 +161,24 @@ class ControlLoopInstantiationProviderTest {
         deleteEntryInDB(serviceTemplate.getName(), serviceTemplate.getVersion());
     }
 
+    @Test
+    void testIntanceResponses() throws PfModelException {
+        var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider,
+                supervisionHandler, participantProvider);
+        var instancePropertyList = instantiationProvider.createInstanceProperties(serviceTemplate);
+        assertNull(instancePropertyList.getErrorDetails());
+        var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+        assertEquals(id, instancePropertyList.getAffectedInstanceProperties().get(0));
+        var instanceOrderState = instantiationProvider.getInstantiationOrderState(ID_NAME, ID_VERSION);
+        assertEquals(ControlLoopOrderedState.UNINITIALISED, instanceOrderState.getOrderedState());
+        assertEquals(ID_NAME, instanceOrderState.getControlLoopIdentifierList().get(0).getName());
+
+        assertNotNull(clProvider.getControlLoop(id));
+        var instanceResponse = instantiationProvider.deleteInstanceProperties(ID_NAME, ID_VERSION);
+        assertEquals(ID_NAME, instanceResponse.getAffectedControlLoops().get(0).getName());
+        assertNull(clProvider.getControlLoop(id));
+    }
+
     @Test
     void testInstantiationCrud() throws Exception {
         participantProvider.createParticipants(CommonTestData.createParticipants());