aboutsummaryrefslogtreecommitdiffstats
path: root/core/core-infrastructure/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/core-infrastructure/src')
-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
2 files changed, 135 insertions, 0 deletions
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));
+ }
+}