aboutsummaryrefslogtreecommitdiffstats
path: root/runtime/src/test
diff options
context:
space:
mode:
authorAjith Sreekumar <ajith.sreekumar@bell.ca>2021-11-26 10:05:30 +0000
committerGerrit Code Review <gerrit@onap.org>2021-11-26 10:05:30 +0000
commitb58782b20186fde86a104ea449b0d90e302e35a8 (patch)
treee3fc1a4903c4dc903dddc5f48538320bfe8c2a7f /runtime/src/test
parent6ca36231e041a72c3a5308e9c21068842ce7a8ed (diff)
parent447c4ce78c8408622186453118139a81e3519ba8 (diff)
Merge "Code Coverage clamp runtime"
Diffstat (limited to 'runtime/src/test')
-rw-r--r--runtime/src/test/java/org/onap/policy/clamp/authorization/AuthorizationTest.java64
-rw-r--r--runtime/src/test/java/org/onap/policy/clamp/configuration/ClampGsonDataFormatTest.java95
2 files changed, 159 insertions, 0 deletions
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 000000000..e14295de7
--- /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 000000000..38ff8f271
--- /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();
+ }
+
+}