diff options
author | 2020-03-12 15:16:44 -0400 | |
---|---|---|
committer | 2020-03-13 09:27:55 -0400 | |
commit | 7f6929e5ea6da4015090b3adac73b35f9b3afb18 (patch) | |
tree | e1321bf17bfc7cd6f2231088b8a1d8b3d7b790e3 /controlloop/common/eventmanager/src/test/java | |
parent | aa8225b5211485b3c1150c21e51fd3e93b7f31d3 (diff) |
Fix sonar issues in drools-applications
Fixed various sonar issues, including moving some
code to policy-common.
Fixed some eclipse warnings, including deprecated junit APIs.
Issue-ID: POLICY-2426
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: I10b40c1e5af62308f2e4c315e4d399aafff2998f
Diffstat (limited to 'controlloop/common/eventmanager/src/test/java')
3 files changed, 12 insertions, 215 deletions
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java index 266ad1ac9..db16c4528 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java @@ -27,7 +27,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -50,9 +50,7 @@ import org.jetbrains.annotations.NotNull; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -85,10 +83,6 @@ public class ControlLoopEventManagerTest { private static final String TWO_ONSET_TEST = "TwoOnsetTest"; private static final String VNF_UUID = "83f674e8-7555-44d7-9a39-bdc3770b0491"; - - @Rule - public ExpectedException thrown = ExpectedException.none(); - private VirtualControlLoopEvent onset; private LockCallback callback; @@ -405,7 +399,7 @@ public class ControlLoopEventManagerTest { VirtualControlLoopNotification notification = manager.activate(yamlString, event); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); - + event.getAai().put(VSERVER_NAME, "testVserverName"); // serialize and de-serialize manager @@ -452,7 +446,7 @@ public class ControlLoopEventManagerTest { .hasMessage("Do not have a current operation."); assertNull(manager.unlockCurrentOperation()); - + event.getAai().put(VSERVER_NAME, "testVserverName"); ControlLoopOperationManager clom = manager.processControlLoop(); diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java index ae6af6c07..47e7d5344 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java @@ -159,29 +159,15 @@ public class ControlLoopProcessorTest { InputStream is = new FileInputStream(new File("src/test/resources/test.yaml")); String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8); - ControlLoopProcessor clProcessor = new ControlLoopProcessor(yamlString); - clProcessor.getCurrentPolicy(); - clProcessor.nextPolicyForResult(PolicyResult.SUCCESS); - - clProcessor = new ControlLoopProcessor(yamlString); - clProcessor.getCurrentPolicy(); - clProcessor.nextPolicyForResult(PolicyResult.FAILURE); - - clProcessor = new ControlLoopProcessor(yamlString); - clProcessor.getCurrentPolicy(); - clProcessor.nextPolicyForResult(PolicyResult.FAILURE_EXCEPTION); - - clProcessor = new ControlLoopProcessor(yamlString); - clProcessor.getCurrentPolicy(); - clProcessor.nextPolicyForResult(PolicyResult.FAILURE_GUARD); - - clProcessor = new ControlLoopProcessor(yamlString); - clProcessor.getCurrentPolicy(); - clProcessor.nextPolicyForResult(PolicyResult.FAILURE_RETRIES); + for (PolicyResult result : PolicyResult.values()) { + checkResult(yamlString, result); + } + } - clProcessor = new ControlLoopProcessor(yamlString); + private void checkResult(String yamlString, PolicyResult result) throws ControlLoopException { + ControlLoopProcessor clProcessor = new ControlLoopProcessor(yamlString); clProcessor.getCurrentPolicy(); - clProcessor.nextPolicyForResult(PolicyResult.FAILURE_TIMEOUT); + clProcessor.nextPolicyForResult(result); } /** diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java index 2f14954ca..7238ba05b 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java @@ -1,5 +1,7 @@ /*- * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,19 +24,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; -import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.AbstractSet; -import java.util.Arrays; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; import org.junit.Test; -import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.controlloop.drl.legacy.ControlLoopParams; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; @@ -55,179 +47,4 @@ public class ControlLoopUtilsTest { assertNull(ControlLoopUtils.toControlLoopParams(null)); } - - @Test - public void testToObject() { - Map<String, String> map = Map.of("abc", "def", "ghi", "jkl"); - Properties props = new Properties(); - props.putAll(map); - - // with empty prefix - Map<String, Object> result = ControlLoopUtils.toObject(props, ""); - assertEquals(map, result); - - // with dotted prefix - other items skipped - map = Map.of("pfx.abc", "def", "ghi", "jkl", "pfx.mno", "pqr", "differentpfx.stu", "vwx"); - props.clear(); - props.putAll(Map.of("pfx.abc", "def", "ghi", "jkl", "pfx.mno", "pqr", "differentpfx.stu", "vwx")); - result = ControlLoopUtils.toObject(props, "pfx."); - map = Map.of("abc", "def", "mno", "pqr"); - assertEquals(map, result); - - // undotted prefix - still skips other items - result = ControlLoopUtils.toObject(props, "pfx"); - assertEquals(map, result); - } - - @Test - public void testSetProperty() { - // one, two, and three components in the name, the last two with subscripts - Map<String, Object> map = Map.of("one", "one.abc", "two.def", "two.ghi", "three.jkl.mno[0]", "three.pqr", - "three.jkl.mno[1]", "three.stu"); - Properties props = new Properties(); - props.putAll(map); - - Map<String, Object> result = ControlLoopUtils.toObject(props, ""); - // @formatter:off - map = Map.of( - "one", "one.abc", - "two", Map.of("def", "two.ghi"), - "three", Map.of("jkl", - Map.of("mno", - List.of("three.pqr", "three.stu")))); - // @formatter:on - assertEquals(map, result); - } - - @Test - public void testGetNode() { - Map<String, Object> map = Map.of("abc[0].def", "node.ghi", "abc[0].jkl", "node.mno", "abc[1].def", "node.pqr"); - Properties props = new Properties(); - props.putAll(map); - - Map<String, Object> result = ControlLoopUtils.toObject(props, ""); - // @formatter:off - map = Map.of( - "abc", - List.of( - Map.of("def", "node.ghi", "jkl", "node.mno"), - Map.of("def", "node.pqr") - )); - // @formatter:on - assertEquals(map, result); - - } - - @Test - public void testExpand() { - // add subscripts out of order - Properties props = makeProperties("abc[2]", "expand.def", "abc[1]", "expand.ghi"); - - Map<String, Object> result = ControlLoopUtils.toObject(props, ""); - // @formatter:off - Map<String,Object> map = - Map.of("abc", - Arrays.asList(null, "expand.ghi", "expand.def")); - // @formatter:on - assertEquals(map, result); - - } - - @Test - public void testGetObject() { - // first value is primitive, while second is a map - Properties props = makeProperties("object.abc", "object.def", "object.abc.ghi", "object.jkl"); - - Map<String, Object> result = ControlLoopUtils.toObject(props, ""); - // @formatter:off - Map<String,Object> map = - Map.of("object", - Map.of("abc", - Map.of("ghi", "object.jkl"))); - // @formatter:on - assertEquals(map, result); - } - - @Test - public void testGetArray() { - // first value is primitive, while second is an array - Properties props = makeProperties("array.abc", "array.def", "array.abc[0].ghi", "array.jkl"); - - Map<String, Object> result = ControlLoopUtils.toObject(props, ""); - // @formatter:off - Map<String,Object> map = - Map.of("array", - Map.of("abc", - List.of( - Map.of("ghi", "array.jkl")))); - // @formatter:on - assertEquals(map, result); - } - - @Test - @SuppressWarnings("unchecked") - public void testCompressLists() throws IOException, CoderException { - assertEquals("plain-string", ControlLoopUtils.compressLists("plain-string").toString()); - - // @formatter:off - Map<String, Object> map = - Map.of( - "cmp.abc", "cmp.def", - "cmp.ghi", - Arrays.asList(null, "cmp.list1", null, "cmp.list2", - Map.of("cmp.map", Arrays.asList("cmp.map.list1", "cmp.map1.list2", null)))); - // @formatter:on - - // the data structure needs to be modifiable, so we'll encode/decode it - StandardCoder coder = new StandardCoder(); - map = coder.decode(coder.encode(map), LinkedHashMap.class); - - ControlLoopUtils.compressLists(map); - - // @formatter:off - Map<String, Object> expected = - Map.of( - "cmp.abc", "cmp.def", - "cmp.ghi", - Arrays.asList("cmp.list1", "cmp.list2", - Map.of("cmp.map", Arrays.asList("cmp.map.list1", "cmp.map1.list2")))); - // @formatter:on - assertEquals(expected, map); - } - - /** - * Makes properties containing the specified key/value pairs. The property set returns - * names in the order listed. - * - * @return a new properties containing the specified key/value pairs - */ - private Properties makeProperties(String key1, String value1, String key2, String value2) { - // control the order in which the names are returned - List<String> keyList = List.of(key1, key2); - - Set<String> keySet = new AbstractSet<>() { - @Override - public Iterator<String> iterator() { - return keyList.iterator(); - } - - @Override - public int size() { - return 2; - } - }; - - Properties props = new Properties() { - private static final long serialVersionUID = 1L; - - @Override - public Set<String> stringPropertyNames() { - return keySet; - } - }; - - props.putAll(Map.of(key1, value1, key2, value2)); - - return props; - } } |