summaryrefslogtreecommitdiffstats
path: root/policy-utils
diff options
context:
space:
mode:
Diffstat (limited to 'policy-utils')
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/LoggerUtil.java4
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java3
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedService.java1
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java6
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/utils/LoggerUtilTest.java33
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/utils/NetworkUtilTest.java37
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java31
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java22
8 files changed, 119 insertions, 18 deletions
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/LoggerUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/LoggerUtil.java
index 257d2dae..681a2b20 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/LoggerUtil.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/LoggerUtil.java
@@ -32,6 +32,10 @@ public class LoggerUtil {
* Root logger
*/
public static final String ROOT_LOGGER = "ROOT";
+
+ private LoggerUtil() {
+ // Empty constructor
+ }
/**
* set the log level of a logger
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java
index bd5b8aac..6734226d 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java
@@ -39,6 +39,9 @@ public class NetworkUtil {
*/
public static final String IPv4_WILDCARD_ADDRESS = "0.0.0.0";
+ private NetworkUtil() {
+ // Empty constructor
+ }
/**
* try to connect to $host:$port $retries times while we are getting connection failures.
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedService.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedService.java
index 75a3cd7d..7a6ca0a0 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedService.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedService.java
@@ -25,6 +25,7 @@ package org.onap.policy.drools.utils;
* of services (features) discovered via 'ServiceLoader'. See
* 'OrderedServiceImpl' for more details.
*/
+@FunctionalInterface
public interface OrderedService
{
/**
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java
index 50135e84..bf59ec96 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java
@@ -45,8 +45,7 @@ public class ReflectionUtil {
* @throws IllegalArgumentException if an invalid parameter has been passed in
*/
public static Class<?> fetchClass(ClassLoader classLoader,
- String className)
- throws IllegalArgumentException {
+ String className) {
if (classLoader == null)
throw new IllegalArgumentException("A class loader must be provided");
@@ -70,8 +69,7 @@ public class ReflectionUtil {
* @return true if exists
* @throws IllegalArgumentException if an invalid parameter has been passed in
*/
- public static boolean isClass(ClassLoader classLoader, String classname)
- throws IllegalArgumentException {
+ public static boolean isClass(ClassLoader classLoader, String classname) {
return fetchClass(classLoader, classname) != null;
}
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/LoggerUtilTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/LoggerUtilTest.java
new file mode 100644
index 00000000..d942a427
--- /dev/null
+++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/LoggerUtilTest.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-utils
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.drools.utils;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class LoggerUtilTest {
+
+ @Test
+ public void test() {
+ assertNotNull(LoggerUtil.setLevel("foo", "warn"));
+ }
+
+}
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/NetworkUtilTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/NetworkUtilTest.java
new file mode 100644
index 00000000..c8b7735b
--- /dev/null
+++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/NetworkUtilTest.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-utils
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.drools.utils;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class NetworkUtilTest {
+
+ @Test
+ public void test() throws InterruptedException, IOException {
+ assertNotNull(NetworkUtil.IPv4_WILDCARD_ADDRESS);
+ assertFalse(NetworkUtil.isTcpPortOpen("localhost", 8080, 1, 5));
+ }
+
+}
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java
index 1af831ad..5063447c 100644
--- a/policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java
+++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.drools.utils;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import org.junit.Test;
@@ -30,18 +31,20 @@ public class PairTripleTest {
public void pairTest() {
Pair<String, String> p = new Pair<String, String>("foo", "bar");
- assertEquals(p.first(),"foo");
- assertEquals(p.second(),"bar");
- assertEquals(p.getFirst(),"foo");
- assertEquals(p.getSecond(),"bar");
+ assertEquals("foo", p.first());
+ assertEquals("bar", p.second());
+ assertEquals("foo", p.getFirst());
+ assertEquals("bar", p.getSecond());
p.first("one");
p.second("two");
- assertEquals(p.first(),"one");
- assertEquals(p.second(),"two");
- assertEquals(p.getFirst(),"one");
- assertEquals(p.getSecond(),"two");
+ assertEquals("one", p.first());
+ assertEquals("two", p.second());
+ assertEquals("one", p.getFirst());
+ assertEquals("two", p.getSecond());
+
+ assertNotNull(p.toString());
}
@@ -49,17 +52,17 @@ public class PairTripleTest {
public void tripleTest() {
Triple<String, String, String> t = new Triple<String, String,String>("foo", "bar", "fiz");
- assertEquals(t.first(),"foo");
- assertEquals(t.second(),"bar");
- assertEquals(t.third(),"fiz");
+ assertEquals("foo", t.first());
+ assertEquals("bar", t.second());
+ assertEquals("fiz", t.third());
t.first("one");
t.second("two");
t.third("three");
- assertEquals(t.first(),"one");
- assertEquals(t.second(),"two");
- assertEquals(t.third(),"three");
+ assertEquals("one", t.first());
+ assertEquals("two", t.second());
+ assertEquals("three", t.third());
}
}
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java
index ab4bace5..0cb51060 100644
--- a/policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java
+++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java
@@ -21,6 +21,7 @@ package org.onap.policy.drools.utils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -58,5 +59,26 @@ public class ReflectionUtilTest {
fail();
}
}
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testException1() {
+ ReflectionUtil.fetchClass(null, "org.onap.policy.drools.utils.ReflectionUtil");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testException2() {
+ Class<?> class1;
+ try {
+ class1 = Class.forName("org.onap.policy.drools.utils.ReflectionUtil");
+ ClassLoader classLoader = class1.getClassLoader();
+ ReflectionUtil.fetchClass(classLoader, null);
+ } catch (ClassNotFoundException e) {
+ fail();
+ }
+ }
+ @Test
+ public void testException3() throws ClassNotFoundException {
+ assertNull(ReflectionUtil.fetchClass(ClassLoader.getSystemClassLoader(), "foo.bar"));
+ }
}