diff options
author | Jim Hahn <jrh3@att.com> | 2020-04-07 13:58:09 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-04-07 17:15:07 -0400 |
commit | 9b3ff5f270572a6760ff07dda9577cdadb53b088 (patch) | |
tree | eacd325199fbb72fddaba94a057178a19e9c3360 /models-interactions/model-impl/sdnc/src/test | |
parent | 3000fdca611c32b7001c553621660b8ea0d2eb49 (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/sdnc/src/test')
-rw-r--r-- | models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java | 5 | ||||
-rw-r--r-- | models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java | 46 |
2 files changed, 23 insertions, 28 deletions
diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java index 41f07c3c7..7b5ad46c5 100644 --- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Huawei. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2020 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. @@ -20,6 +20,8 @@ package org.onap.policy.sdnc; +import static org.junit.Assert.assertNotNull; + import org.junit.Test; import org.onap.policy.sdnc.util.Serialization; import org.slf4j.Logger; @@ -70,5 +72,6 @@ public class DemoTest { body = Serialization.gsonPretty.toJson(response); logger.info("{}", body); + assertNotNull(body); } } diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java index c069f1c3b..b962ce8c7 100644 --- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Huawei. All rights reserved. * ================================================================================ - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,12 +24,13 @@ package org.onap.policy.sdnc; 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.UUID; @@ -48,7 +49,6 @@ public class SdncManagerTest implements SdncCallback { private RestManager mockedRestManager; private Pair<Integer, String> httpResponsePutOk; - private Pair<Integer, String> httpResponseGetOk; private Pair<Integer, String> httpResponseBadResponse; private Pair<Integer, String> httpResponseErr; @@ -63,7 +63,6 @@ public class SdncManagerTest implements SdncCallback { 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); } @@ -120,14 +119,15 @@ public class SdncManagerTest implements SdncCallback { SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "Exception"); manager.setRestManager(mockedRestManager); - Thread managerThread = new Thread(manager); - managerThread.start(); - when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("Exception"), anyMap(), anyString(), anyString())).thenThrow(new RuntimeException("OzException")); + Thread managerThread = new Thread(manager); + managerThread.start(); + + managerThread.join(1000); - managerThread.join(100); + verify(mockedRestManager).post(any(), any(), any(), any(), any(), any()); } @Test @@ -135,13 +135,12 @@ public class SdncManagerTest implements SdncCallback { SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "Null"); manager.setRestManager(mockedRestManager); - Thread managerThread = new Thread(manager); - managerThread.start(); - when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("Null"), anyMap(), anyString(), anyString())).thenReturn(null); - managerThread.join(100); + manager.run(); + + verify(mockedRestManager).post(any(), any(), any(), any(), any(), any()); } @@ -150,13 +149,12 @@ public class SdncManagerTest implements SdncCallback { SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "Error0"); manager.setRestManager(mockedRestManager); - Thread managerThread = new Thread(manager); - managerThread.start(); - when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("Error0"), anyMap(), anyString(), anyString())).thenReturn(httpResponseErr); - managerThread.join(100); + manager.run(); + + verify(mockedRestManager).post(any(), any(), any(), any(), any(), any()); } @Test @@ -164,13 +162,12 @@ public class SdncManagerTest implements SdncCallback { SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "BadResponse"); manager.setRestManager(mockedRestManager); - Thread managerThread = new Thread(manager); - managerThread.start(); - when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("OK"), anyMap(), anyString(), anyString())).thenReturn(httpResponseBadResponse); - managerThread.join(100); + manager.run(); + + verify(mockedRestManager).post(any(), any(), any(), any(), any(), any()); } @Test @@ -178,17 +175,12 @@ public class SdncManagerTest implements SdncCallback { SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "OOK"); manager.setRestManager(mockedRestManager); - Thread managerThread = new Thread(manager); - managerThread.start(); - when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), 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(100); + verify(mockedRestManager).post(any(), any(), any(), any(), any(), any()); } @Override |