summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-impl/vfc
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-07 13:58:09 -0400
committerJim Hahn <jrh3@att.com>2020-04-07 17:15:07 -0400
commit9b3ff5f270572a6760ff07dda9577cdadb53b088 (patch)
treeeacd325199fbb72fddaba94a057178a19e9c3360 /models-interactions/model-impl/vfc
parent3000fdca611c32b7001c553621660b8ea0d2eb49 (diff)
Address sonar issues in models
Addressed the following sonar issues: - use RE2 instead of java.util Pattern for "+" and "*" - don't use deprecated methods - for Date(long), sonar appeared not to parse the argument's type correctly. Modified the code slightly to make sonar happy - duplicate blocks of code - either log or throw - missing assert in junit - for SDNR & VFC, eliminated threads, as they are unnecessary - duplicate code block in different branches - useless assignments - redeclaring abstract methods - cyclomatic complexity - used lombok in some cases (e.g., EqualsAndHashCode) - assert argument order - actually deleted ControlLoopTargetType, because it is not needed and sonar complains regardless of which order is used - add private constructor to utility classes - use StandardCharsets instead of literals Also: - added logback-test.xml to SO to eliminate the voluminous output from the junit test Issue-ID: POLICY-2305 Change-Id: I586c331781bedbd54a115a71847d04d293689445 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-impl/vfc')
-rw-r--r--models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java43
1 files changed, 17 insertions, 26 deletions
diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java
index 7874d2514..8db3438cc 100644
--- a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java
+++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* vfc
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.. All rights reserved.
* Modifications Copyright (C) 2018-2019 AT&T Corporation. All rights reserved.
* ================================================================================
@@ -23,12 +23,13 @@
package org.onap.policy.vfc;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.endsWith;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.startsWith;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
@@ -50,7 +51,6 @@ public class VfcManagerTest implements VfcCallback {
private RestManager mockedRestManager;
private Pair<Integer, String> httpResponsePutOk;
- private Pair<Integer, String> httpResponseGetOk;
private Pair<Integer, String> httpResponseBadResponse;
private Pair<Integer, String> httpResponseErr;
@@ -65,7 +65,6 @@ public class VfcManagerTest implements VfcCallback {
mockedRestManager = mock(RestManager.class);
httpResponsePutOk = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(response));
- httpResponseGetOk = mockedRestManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
httpResponseBadResponse = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(null));
httpResponseErr = mockedRestManager.new Pair<>(200, null);
}
@@ -131,9 +130,6 @@ public class VfcManagerTest implements VfcCallback {
VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Exception");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(
startsWith(SOME_URL),
eq(DOROTHY),
@@ -143,7 +139,9 @@ public class VfcManagerTest implements VfcCallback {
anyString()))
.thenThrow(new RuntimeException("OzException"));
- managerThread.join();
+ manager.run();
+
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Test
@@ -151,14 +149,13 @@ public class VfcManagerTest implements VfcCallback {
VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Null");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(startsWith(SOME_URL),
eq(DOROTHY), eq("Null"), anyMap(), anyString(), anyString()))
.thenReturn(null);
- managerThread.join();
+ manager.run();
+
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Test
@@ -166,14 +163,13 @@ public class VfcManagerTest implements VfcCallback {
VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Error0");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(startsWith(SOME_URL),
eq(DOROTHY), eq("Error0"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponseErr);
- managerThread.join();
+ manager.run();
+
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Test
@@ -181,14 +177,13 @@ public class VfcManagerTest implements VfcCallback {
VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "BadResponse");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(startsWith(SOME_URL),
eq(DOROTHY), eq("OK"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponseBadResponse);
- managerThread.join();
+ manager.run();
+
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Test
@@ -196,17 +191,13 @@ public class VfcManagerTest implements VfcCallback {
VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Ok");
manager.setRestManager(mockedRestManager);
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
when(mockedRestManager.post(startsWith(SOME_URL),
eq(DOROTHY), eq("OK"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponsePutOk);
- when(mockedRestManager.get(endsWith("1234"), eq(DOROTHY), eq("OK"), anyMap()))
- .thenReturn(httpResponseGetOk);
+ manager.run();
- managerThread.join();
+ verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
}
@Override