Code Coverage on clamp-participant-dcae 97/122597/2
authorlapentafd <francesco.lapenta@est.tech>
Fri, 9 Jul 2021 10:52:54 +0000 (11:52 +0100)
committerlapentafd <francesco.lapenta@est.tech>
Tue, 13 Jul 2021 14:53:14 +0000 (15:53 +0100)
Added assertions to existing tests

Issue-ID: POLICY-3452
Change-Id: I653b899f31595ef2bd1164e6caa6a736399c947a
Signed-off-by: lapentafd <francesco.lapenta@est.tech>
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClientTest.java
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java

index a96581e..3f5e425 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.policy.clamp.controlloop.participant.dcae.endtoend;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.mockserver.model.HttpRequest.request;
@@ -160,4 +161,16 @@ class PartecipantDcaeTest {
         assertEquals(participantHandler.getParticipantId(), participantControlLoopUpdateMsg.getParticipantId());
         assertEquals(1, participantHandler.getControlLoopHandler().getControlLoops().getControlLoopList().size());
     }
+
+    @Test
+    void testControlLoopUpdateListenerString() throws CoderException {
+        ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
+        participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+
+        assertThat(participantControlLoopUpdateMsg.toString()).contains("state=UNINITIALISED");
+        ParticipantControlLoopUpdate copyParticipantControlLoopUpdateMsg =
+                TestListenerUtils.createCopyControlLoopUpdateMsg(participantControlLoopUpdateMsg);
+        assertThat(copyParticipantControlLoopUpdateMsg.toString()).contains("state=UNINITIALISED");
+        assertNotEquals(participantControlLoopUpdateMsg, copyParticipantControlLoopUpdateMsg);
+    }
 }
index f730f36..f3aa176 100644 (file)
@@ -22,6 +22,7 @@ package org.onap.policy.clamp.controlloop.participant.dcae.httpclient;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.fail;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockserver.model.HttpRequest.request;
 import static org.mockserver.model.HttpResponse.response;
@@ -97,6 +98,17 @@ class ClampHttpClientTest {
         }
     }
 
+    @Test
+    void test_create() throws Exception {
+        try (ClampHttpClient client = new ClampHttpClient(parameters)) {
+
+            assertThat(client.create(LOOP, null)).isNull();
+
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+    }
+
     @Test
     void test_deploy() throws Exception {
         try (ClampHttpClient client = new ClampHttpClient(parameters)) {
@@ -128,4 +140,26 @@ class ClampHttpClientTest {
     void test_getStatusEmptyMap() {
         assertThat(ClampHttpClient.getStatusCode(new Loop())).isEqualTo(ClampHttpClient.STATUS_NOT_FOUND);
     }
+
+    @Test
+    void test_stop() throws Exception {
+        try (ClampHttpClient client = new ClampHttpClient(parameters)) {
+
+            assertFalse(client.stop(LOOP));
+
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+    }
+
+    @Test
+    void test_delete() throws Exception {
+        try (ClampHttpClient client = new ClampHttpClient(parameters)) {
+
+            assertFalse(client.delete(LOOP));
+
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+    }
 }
index ab181d4..40f2f5f 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.policy.clamp.controlloop.participant.dcae.main.handler;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
@@ -74,10 +75,13 @@ class ControlLoopElementHandlerTest {
         ParticipantIntermediaryApi intermediaryApi = mock(ParticipantIntermediaryApi.class);
         controlLoopElementHandler.setIntermediaryApi(intermediaryApi);
 
-        controlLoopElementHandler.controlLoopElementStateChange(UUID.randomUUID(), ControlLoopState.PASSIVE,
+        UUID controlLoopElementId = UUID.randomUUID();
+        controlLoopElementHandler.controlLoopElementStateChange(controlLoopElementId, ControlLoopState.PASSIVE,
                 ControlLoopOrderedState.UNINITIALISED);
 
         verify(clampClient).undeploy(eq(LOOP));
+        controlLoopElementHandler.handleStatistics(controlLoopElementId);
+        assertThat(intermediaryApi.getControlLoopElement(controlLoopElementId)).isNull();
     }
 
     @Test
index 0b2712b..4579b52 100644 (file)
@@ -182,6 +182,15 @@ public class TestListenerUtils {
         return clUpdateMsg;
     }
 
+    /**
+     * Method to create a deep copy of ControlLoopUpdateMsg.
+     *
+     * @return ParticipantControlLoopUpdate message
+     */
+    public static ParticipantControlLoopUpdate createCopyControlLoopUpdateMsg(ParticipantControlLoopUpdate cpy) {
+        return new ParticipantControlLoopUpdate(cpy);
+    }
+
     /**
      * Method to create ParticipantHealthCheck message.
      *