* Root logger
*/
public static final String ROOT_LOGGER = "ROOT";
+
+ private LoggerUtil() {
+ // Empty constructor
+ }
/**
* set the log level of a logger
*/
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.
* of services (features) discovered via 'ServiceLoader'. See
* 'OrderedServiceImpl' for more details.
*/
+@FunctionalInterface
public interface OrderedService
{
/**
* @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");
* @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;
}
--- /dev/null
+/*-
+ * ============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"));
+ }
+
+}
--- /dev/null
+/*-
+ * ============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));
+ }
+
+}
package org.onap.policy.drools.utils;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import org.junit.Test;
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());
}
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());
}
}
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;
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"));
+ }
}