Code Coverage clamp runtime

Issue-ID: POLICY-3452
Change-Id: I2ef9edd6bbbf5bdf12e9dccfde0d170d01191336
Signed-off-by: lapentafd <francesco.lapenta@est.tech>
diff --git a/runtime/src/test/java/org/onap/policy/clamp/authorization/AuthorizationTest.java b/runtime/src/test/java/org/onap/policy/clamp/authorization/AuthorizationTest.java
new file mode 100644
index 0000000..e14295d
--- /dev/null
+++ b/runtime/src/test/java/org/onap/policy/clamp/authorization/AuthorizationTest.java
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.authorization;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+class AuthorizationTest {
+
+    private static String USERNAME = "username";
+    private static String PASSWORD = "p4ssw0rd";
+
+    @Test
+    void cldsUserTest() {
+        var cldsUser = new CldsUser();
+        cldsUser.setUser(USERNAME);
+        cldsUser.setPassword(PASSWORD);
+        var permissions = new SecureServicePermission("type", "instance", "action");
+        SecureServicePermission[] p = {permissions};
+        cldsUser.setPermissions(p);
+
+        assertEquals(USERNAME, cldsUser.getUser());
+        assertEquals(PASSWORD, cldsUser.getPassword());
+        assertEquals("type|instance|action", cldsUser.getPermissionsString()[0]);
+    }
+
+    @Test
+    void secureServicePermission() {
+        var permission = new SecureServicePermission("*", "*", "*");
+        permission.setType("type");
+        permission.setInstance("instance");
+        permission.setAction("action");
+        assertEquals("type", permission.getType());
+        assertEquals("instance", permission.getInstance());
+        assertEquals("action", permission.getAction());
+    }
+
+    @Test
+    void authorizationControllertest() {
+        var auth = new AuthorizationController();
+        assertThat(auth.getClampInformation().getAllPermissions()).isEmpty();
+    }
+
+}
diff --git a/runtime/src/test/java/org/onap/policy/clamp/configuration/ClampGsonDataFormatTest.java b/runtime/src/test/java/org/onap/policy/clamp/configuration/ClampGsonDataFormatTest.java
new file mode 100644
index 0000000..38ff8f2
--- /dev/null
+++ b/runtime/src/test/java/org/onap/policy/clamp/configuration/ClampGsonDataFormatTest.java
@@ -0,0 +1,95 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.configuration;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.gson.Gson;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.policy.operational.OperationalPolicy;
+
+class ClampGsonDataFormatTest {
+
+    private static String FORMAT = "clamp-gson";
+    private static String PATH_JSON = "src/test/resources/tosca/service-details.json";
+
+
+    @Test
+    void testFormat() throws IOException {
+        var clampGsonDataFormat = new ClampGsonDataFormat();
+
+        assertEquals(FORMAT, clampGsonDataFormat.getDataFormatName());
+        assertTrue(clampGsonDataFormat.isContentTypeHeader());
+        assertNull(clampGsonDataFormat.getGson());
+
+        clampGsonDataFormat.close();
+    }
+
+    @Test
+    void testMarshal() throws IOException {
+        var clampGsonDataFormatFull = new ClampGsonDataFormat(new Gson(), OperationalPolicy.class);
+
+        var exchange = mock(Exchange.class);
+        when(exchange.hasOut()).thenReturn(true);
+        when(exchange.getOut()).thenReturn(mock(Message.class));
+        assertDoesNotThrow(() -> clampGsonDataFormatFull
+                .marshal(exchange, new OperationalPolicy(), mock(OutputStream.class)));
+
+        when(exchange.hasOut()).thenReturn(false);
+        when(exchange.getIn()).thenReturn(mock(Message.class));
+        assertDoesNotThrow(() -> clampGsonDataFormatFull
+                .marshal(exchange, new OperationalPolicy(), mock(OutputStream.class)));
+
+        clampGsonDataFormatFull.setContentTypeHeader(false);
+        assertDoesNotThrow(() -> clampGsonDataFormatFull
+                .marshal(exchange, new OperationalPolicy(), mock(OutputStream.class)));
+
+        clampGsonDataFormatFull.close();
+    }
+
+    @Test
+    void testUnmarshal() throws IOException {
+        var clampGsonDataFormatFull = new ClampGsonDataFormat(new Gson(), OperationalPolicy.class);
+
+        var exchange = mock(Exchange.class);
+        var jsonExample = new File(PATH_JSON);
+        var stubInputStream = new FileInputStream(jsonExample);
+        assertDoesNotThrow(() -> clampGsonDataFormatFull.unmarshal(exchange, stubInputStream));
+
+        clampGsonDataFormatFull.setUnmarshalType(String.class);
+        var stubInputStream2 = new FileInputStream(jsonExample);
+        assertDoesNotThrow(() -> clampGsonDataFormatFull.unmarshal(exchange, stubInputStream2));
+
+        clampGsonDataFormatFull.close();
+    }
+
+}