summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorRossC <ross.carter@est.tech>2020-05-07 13:25:34 +0100
committerRossC <ross.carter@est.tech>2020-05-08 14:57:56 +0100
commitea317372413753320db681efb9a1e469c3776f42 (patch)
tree33fd9dcc743783146057b2c4f45c051c140ce077 /core
parent5b0b7fac53c587307832119657a31b64926797a3 (diff)
Unit tests for various classes
Issue-ID: POLICY-1916 Change-Id: Ie7cafa16ce12ca542a4e76307caddb36b7753990 Signed-off-by: RossC <ross.carter@est.tech>
Diffstat (limited to 'core')
-rw-r--r--core/core-infrastructure/pom.xml5
-rw-r--r--core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtilsTest.java68
-rw-r--r--core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java67
3 files changed, 140 insertions, 0 deletions
diff --git a/core/core-infrastructure/pom.xml b/core/core-infrastructure/pom.xml
index fcae62e04..956d89400 100644
--- a/core/core-infrastructure/pom.xml
+++ b/core/core-infrastructure/pom.xml
@@ -42,6 +42,11 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtilsTest.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtilsTest.java
new file mode 100644
index 000000000..4e69f44ee
--- /dev/null
+++ b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtilsTest.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2020 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.apex.core.infrastructure.java.classes;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class ClassUtilsTest {
+
+ @Test
+ public void testGetClassNames() throws IOException {
+ InputStream input = null;
+ ClassUtils.getClassNames();
+ assertEquals(new TreeSet<>(), ClassUtils.processJar(input));
+ }
+
+ @Test
+ public void testProcessFileName() {
+ assertEquals("testing.txt",ClassUtils.processFileName("testing.txt"));
+ assertNull(ClassUtils.processFileName(null));
+ assertEquals("",ClassUtils.processFileName("/classes/"));
+ }
+
+ @Test
+ public void testProcessDir() throws Exception {
+ File mockFile = Mockito.mock(File.class);
+ File mockChildFile = Mockito.mock(File.class);
+ Mockito.when(mockFile.isDirectory()).thenReturn(false);
+ assertEquals(new TreeSet<>(),ClassUtils.processDir(mockFile, "Here"));
+ assertEquals(new TreeSet<>(),ClassUtils.processDir(null, "Test"));
+ Mockito.when(mockFile.isDirectory()).thenReturn(true);
+ File[] files = {mockChildFile};
+ Mockito.when(mockFile.listFiles()).thenReturn(files);
+ Mockito.when(mockChildFile.getName()).thenReturn("test.class");
+ Mockito.when(mockChildFile.getAbsolutePath()).thenReturn("/test/");
+ assertEquals(Set.of(".test."),ClassUtils.processDir(mockFile, "Here"));
+ Mockito.when(mockChildFile.getName()).thenReturn("test.class");
+ assertEquals(Set.of(".test."),ClassUtils.processDir(mockFile, "Here"));
+ Mockito.when(mockChildFile.getName()).thenReturn("$test.class");
+ assertEquals(new TreeSet<>(),ClassUtils.processDir(mockFile, "Here"));
+ }
+
+}
diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java
new file mode 100644
index 000000000..91b34e20c
--- /dev/null
+++ b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2020 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.apex.core.infrastructure.messaging;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.junit.Test;
+import org.onap.policy.apex.core.infrastructure.messaging.util.MessagingUtils;
+
+public class MessagingUtilsTest {
+
+ @Test
+ public void testCheckPort() throws UnknownHostException, IOException {
+ assertEquals(1,MessagingUtils.checkPort(1));
+ assertEquals(1,MessagingUtils.findPort(1));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testIllegalArgumentException() {
+ assertEquals(1,MessagingUtils.findPort(65536));
+ }
+
+ @Test
+ public void testGetHost() throws UnknownHostException {
+ InetAddress host = InetAddress.getLocalHost();
+ assertEquals(host,MessagingUtils.getHost());
+ }
+
+ @Test
+ public void testValidAllocateAddress() throws UnknownHostException {
+ assertNotNull(MessagingUtils.getLocalHostLanAddress());
+ assertEquals(3306,MessagingUtils.allocateAddress(3306));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidAllocateAddress() {
+ assertEquals(1,MessagingUtils.allocateAddress(1));
+ }
+
+ @Test
+ public void testSerializeObject() {
+ String testString = "Test";
+ MessagingUtils.serializeObject(new Object());
+ assertNotNull(MessagingUtils.serializeObject(testString));
+ }
+}