aboutsummaryrefslogtreecommitdiffstats
path: root/utils-test/src/test/java/org/onap
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-02-13 16:16:45 -0500
committerJim Hahn <jrh3@att.com>2019-02-14 22:05:57 +0000
commitf10d38d4af0178d008c69ada7cd1a6abc6ec075a (patch)
treebc3923330a2dc4f9281157412038a09b5b68caba /utils-test/src/test/java/org/onap
parente4db2076fa2c7ce1763bfb0d70bd360bf57f6c99 (diff)
Sonar fixes
Added test for Serializer to increase junit coverage. Added tests for TestTimeMulti to increase junit coverage. Sonar fixes for PropertyConfiguration: - use equalsIgnoreCase - use the exception Updated license dates. Some fixes for LoggerFactoryWrapper to address sonar issue - utility classes should typically have a private constructor. Change-Id: I8957e9673fe8371ecca7abbb7ece87b0d6f46c1a Issue-ID: POLICY-1519 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'utils-test/src/test/java/org/onap')
-rw-r--r--utils-test/src/test/java/org/onap/policy/common/utils/io/SerializerTest.java28
-rw-r--r--utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeMultiTest.java17
2 files changed, 40 insertions, 5 deletions
diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/io/SerializerTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/io/SerializerTest.java
index 36812b3b..ee66195c 100644
--- a/utils-test/src/test/java/org/onap/policy/common/utils/io/SerializerTest.java
+++ b/utils-test/src/test/java/org/onap/policy/common/utils/io/SerializerTest.java
@@ -33,6 +33,8 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.junit.AfterClass;
import org.junit.Before;
@@ -195,7 +197,7 @@ public class SerializerTest {
public ByteArrayOutputStream makeByteArrayOutputStream() {
return out;
}
-
+
@Override
public ObjectOutputStream makeObjectOutputStream(ByteArrayOutputStream out) throws IOException {
return oos;
@@ -208,7 +210,7 @@ public class SerializerTest {
});
assertThatThrownBy(() -> Serializer.serialize(new MyObject(130))).isEqualTo(ex2);
-
+
}
@Test
@@ -269,6 +271,28 @@ public class SerializerTest {
}
@Test
+ public void testDeserialize_ObjectRead_ClassEx() throws Exception {
+ MyObject obj1 = new MyObject(200);
+
+ // must use binary character set
+ Charset binary = StandardCharsets.ISO_8859_1;
+
+ // serialize the object
+ String text = new String(Serializer.serialize(obj1), binary);
+
+ /*
+ * Replace the class name with a bogus class name, which should cause
+ * ClassNotFoundException when we attempt to deserialize it.
+ */
+ text = text.replace("MyObject", "AnObject");
+
+ byte[] data = text.getBytes(binary);
+
+ assertThatThrownBy(() -> Serializer.deserialize(MyObject.class, data)).isInstanceOf(IOException.class)
+ .hasCauseInstanceOf(ClassNotFoundException.class);
+ }
+
+ @Test
public void testDeserialize_ObjectCloseEx() throws Exception {
IOException ex = new IOException("testDeserialize_ObjectCloseEx");
diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeMultiTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeMultiTest.java
index 311e276d..f17235a2 100644
--- a/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeMultiTest.java
+++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeMultiTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* Common Utils-Test
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
@@ -20,6 +20,7 @@
package org.onap.policy.common.utils.time;
+import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -72,6 +73,9 @@ public class TestTimeMultiTest {
}
assertTrue(ttm.getMillis() >= tbeg + NTIMES * MIN_SLEEP_MS);
+
+ // something in the queue, but no threads remain -> exception
+ assertThatIllegalStateException().isThrownBy(() -> ttm.threadCompleted());
}
private class MyThread extends Thread {
@@ -95,6 +99,13 @@ public class TestTimeMultiTest {
public void run() {
try {
for (int x = 0; x < NTIMES; ++x) {
+ // negative sleep should have no effect
+ texpected = ttm.getMillis();
+ ttm.sleep(-1);
+ if ((tactual = ttm.getMillis()) != texpected) {
+ break;
+ }
+
texpected = ttm.getMillis() + sleepMs;
ttm.sleep(sleepMs);