aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-controlloop/src/test/java/org
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2021-06-16 12:08:01 +0100
committerliamfallon <liam.fallon@est.tech>2021-06-17 15:51:34 +0100
commit2d186df9e3ed47599dbc86c2f435f7884535398c (patch)
treed77b85e48927ad072248e784c7b99b12205f4e0b /runtime-controlloop/src/test/java/org
parent17f5d3c97e47064407452122bc6cb801e43df5f9 (diff)
Clean up CLAMP Sonar and checkstyle issues
This commit cleans up sonar and checkstyle issues identified in the CLAMP repository. Issue-ID: POLICY-3206 Change-Id: I16b61bbe771cc17de15183a24b2a5e82a8d35872 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'runtime-controlloop/src/test/java/org')
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java6
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java55
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/rest/MonitoringQueryControllerTest.java1
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java5
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/rest/CommonRestController.java15
5 files changed, 37 insertions, 45 deletions
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java
index 4dbb3ea02..f7749e164 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java
@@ -127,7 +127,7 @@ public class CommissioningControllerTest extends CommonRestController {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "?name=noResultWithThisName");
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- List entityList = rawresp.readEntity(List.class);
+ List<?> entityList = rawresp.readEntity(List.class);
assertThat(entityList).isEmpty();
}
@@ -138,7 +138,7 @@ public class CommissioningControllerTest extends CommonRestController {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- List entityList = rawresp.readEntity(List.class);
+ List<?> entityList = rawresp.readEntity(List.class);
assertNotNull(entityList);
assertThat(entityList).hasSize(2);
}
@@ -161,7 +161,7 @@ public class CommissioningControllerTest extends CommonRestController {
+ "?name=org.onap.domain.pmsh.PMSHControlLoopDefinition");
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- List entityList = rawresp.readEntity(List.class);
+ List<?> entityList = rawresp.readEntity(List.class);
assertNotNull(entityList);
assertThat(entityList).hasSize(4);
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java
index 44096eecd..78f380405 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java
@@ -47,7 +47,6 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-
public class TestMonitoringProvider {
private static final String CL_PARTICIPANT_STATISTICS_JSON =
@@ -68,8 +67,6 @@ public class TestMonitoringProvider {
private static ClElementStatisticsList inputClElementStatistics;
private static ClElementStatisticsList invalidClElementInput;
-
-
@BeforeClass
public static void beforeSetupStatistics() throws CoderException {
// Reading input json for statistics data
@@ -81,7 +78,6 @@ public class TestMonitoringProvider {
invalidClElementInput = CODER.decode(new File(INVALID_CL_ELEMENT_JSON_INPUT), ClElementStatisticsList.class);
}
-
@Test
public void testCreateParticipantStatistics() throws Exception {
PolicyModelsProviderParameters parameters =
@@ -121,15 +117,14 @@ public class TestMonitoringProvider {
}).hasMessageMatching("name is marked .*null but is null");
// Fetch specific statistics record with name, version and record count
- getResponse = provider.fetchFilteredParticipantStatistics("name2", "1.001", 1,
- null, null);
+ getResponse = provider.fetchFilteredParticipantStatistics("name2", "1.001", 1, null, null);
assertThat(getResponse.getStatisticsList()).hasSize(1);
assertEquals(getResponse.getStatisticsList().get(0).toString().replaceAll("\\s+", ""),
inputParticipantStatistics.getStatisticsList().get(2).toString().replaceAll("\\s+", ""));
// Fetch statistics using timestamp
- getResponse = provider.fetchFilteredParticipantStatistics("name1", "1.001", 0,
- null, Instant.parse("2021-01-10T15:00:00.000Z"));
+ getResponse = provider.fetchFilteredParticipantStatistics("name1", "1.001", 0, null,
+ Instant.parse("2021-01-10T15:00:00.000Z"));
assertThat(getResponse.getStatisticsList()).hasSize(1);
getResponse = provider.fetchFilteredParticipantStatistics("name1", "1.001", 0,
@@ -171,15 +166,12 @@ public class TestMonitoringProvider {
ClElementStatisticsList getResponse;
assertThatThrownBy(() -> {
- provider.fetchFilteredClElementStatistics(null, null, null, null,
- null, 0);
+ provider.fetchFilteredClElementStatistics(null, null, null, null, null, 0);
}).hasMessageMatching("name is marked .*null but is null");
- ClElementStatisticsList lists = provider.createClElementStatistics(inputClElementStatistics
- .getClElementStatistics());
+ var lists = provider.createClElementStatistics(inputClElementStatistics.getClElementStatistics());
- getResponse = provider.fetchFilteredClElementStatistics("name1", null, null, null,
- null, 0);
+ getResponse = provider.fetchFilteredClElementStatistics("name1", null, null, null, null, 0);
assertThat(getResponse.getClElementStatistics()).hasSize(2);
assertEquals(getResponse.getClElementStatistics().get(0).toString().replaceAll("\\s+", ""),
@@ -204,18 +196,17 @@ public class TestMonitoringProvider {
try (MonitoringProvider provider = Mockito.spy(new MonitoringProvider(parameters))) {
provider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList());
- //Mock the response for fetching participant conceptIdentifiers per control loop
+ // Mock the response for fetching participant conceptIdentifiers per control loop
List<ToscaConceptIdentifier> conceptIdentifiers = new ArrayList<>();
conceptIdentifiers.add(new ToscaConceptIdentifier("name1", "1.001"));
- when(provider.getAllParticipantIdsPerControlLoop("testName", "1.001"))
- .thenReturn(conceptIdentifiers);
+ when(provider.getAllParticipantIdsPerControlLoop("testName", "1.001")).thenReturn(conceptIdentifiers);
ParticipantStatisticsList getResponse;
getResponse = provider.fetchParticipantStatsPerControlLoop("testName", "1.001");
assertThat(getResponse.getStatisticsList()).hasSize(2);
assertEquals(getResponse.getStatisticsList().get(0).toString().replaceAll("\\s+", ""),
inputParticipantStatistics.getStatisticsList().get(0).toString().replaceAll("\\s+", ""));
- assertThat(provider.fetchParticipantStatsPerControlLoop("invalidCLName", "1.002")
- .getStatisticsList()).isEmpty();
+ assertThat(provider.fetchParticipantStatsPerControlLoop("invalidCLName", "1.002").getStatisticsList())
+ .isEmpty();
}
}
@@ -224,20 +215,19 @@ public class TestMonitoringProvider {
public void testClElementStatsPerCL() throws Exception {
PolicyModelsProviderParameters parameters =
CommonTestData.geParameterGroup(0, "getelemstatPerCL").getDatabaseProviderParameters();
- //Setup a dummy Control loop data
+ // Setup a dummy Control loop data
ControlLoopElement mockClElement = new ControlLoopElement();
mockClElement.setId(inputClElementStatistics.getClElementStatistics().get(0).getId());
- mockClElement.setParticipantId(new ToscaConceptIdentifier(inputClElementStatistics.getClElementStatistics()
- .get(0).getParticipantId().getName(), inputClElementStatistics.getClElementStatistics().get(0)
- .getParticipantId().getVersion()));
+ mockClElement.setParticipantId(new ToscaConceptIdentifier(
+ inputClElementStatistics.getClElementStatistics().get(0).getParticipantId().getName(),
+ inputClElementStatistics.getClElementStatistics().get(0).getParticipantId().getVersion()));
ControlLoop mockCL = new ControlLoop();
mockCL.setElements(new LinkedHashMap<>());
mockCL.getElements().put(mockClElement.getId(), mockClElement);
- //Mock controlloop data to be returned for the given CL Id
+ // Mock controlloop data to be returned for the given CL Id
ControlLoopProvider mockClProvider = Mockito.mock(ControlLoopProvider.class);
- when(mockClProvider.getControlLoop(new ToscaConceptIdentifier("testCLName", "1.001")))
- .thenReturn(mockCL);
+ when(mockClProvider.getControlLoop(new ToscaConceptIdentifier("testCLName", "1.001"))).thenReturn(mockCL);
try (MonitoringProvider monitoringProvider = new MonitoringProvider(parameters)) {
monitoringProvider.createClElementStatistics(inputClElementStatistics.getClElementStatistics());
@@ -252,13 +242,14 @@ public class TestMonitoringProvider {
assertEquals(getResponse.getClElementStatistics().get(1).toString().replaceAll("\\s+", ""),
inputClElementStatistics.getClElementStatistics().get(1).toString().replaceAll("\\s+", ""));
- assertThat(monitoringProvider.fetchClElementStatsPerControlLoop("invalidCLName", "1.002")
- .getClElementStatistics()).isEmpty();
+ assertThat(
+ monitoringProvider.fetchClElementStatsPerControlLoop("invalidCLName", "1.002").getClElementStatistics())
+ .isEmpty();
- Map<String, ToscaConceptIdentifier> clElementIds = monitoringProvider
- .getAllClElementsIdPerControlLoop("testCLName", "1.001");
- assertThat(clElementIds).containsKey(inputClElementStatistics.getClElementStatistics().get(0).getId()
- .toString());
+ Map<String, ToscaConceptIdentifier> clElementIds =
+ monitoringProvider.getAllClElementsIdPerControlLoop("testCLName", "1.001");
+ assertThat(clElementIds)
+ .containsKey(inputClElementStatistics.getClElementStatistics().get(0).getId().toString());
}
}
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/rest/MonitoringQueryControllerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/rest/MonitoringQueryControllerTest.java
index 118199a2d..a846d9317 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/rest/MonitoringQueryControllerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/rest/MonitoringQueryControllerTest.java
@@ -30,7 +30,6 @@ import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatisticsList;
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java
index 77f802d61..aa17e9c4f 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java
@@ -20,6 +20,8 @@
package org.onap.policy.clamp.controlloop.runtime.util;
+import javax.ws.rs.core.Response.Status;
+import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
@@ -39,13 +41,14 @@ public class CommonTestData {
* @param port port to be inserted into the parameters
* @param dbName the database name
* @return the standard Control Loop parameters
+ * @throws ControlLoopRuntimeException on errors reading the control loop parameters
*/
public static ClRuntimeParameterGroup geParameterGroup(final int port, final String dbName) {
try {
return coder.decode(getParameterGroupAsString(port, dbName), ClRuntimeParameterGroup.class);
} catch (CoderException e) {
- throw new RuntimeException("cannot read Control Loop parameters", e);
+ throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE, "cannot read Control Loop parameters", e);
}
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/rest/CommonRestController.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/rest/CommonRestController.java
index 0d668f139..00b9c6715 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/rest/CommonRestController.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/rest/CommonRestController.java
@@ -128,9 +128,8 @@ public class CommonRestController {
/**
* Starts the "Main".
*
- * @throws InterruptedException
- *
- * @throws Exception if an error occurs
+ * @throws InterruptedException if the NetworkUtil method calls are interrupted
+ * @throws IllegalStateException if a controller cannot be started on the requested port
*/
protected static void startMain() throws InterruptedException {
Registry.newRegistry();
@@ -152,11 +151,11 @@ public class CommonRestController {
/**
* Stops the "Main".
*
- * @throws ControlLoopException
- *
- * @throws Exception if an error occurs
+ * @throws ControlLoopException if an error occurs shutting down the controller
+ * @throws InterruptedException if the NetworkUtil method calls are interrupted
+ * @throws IllegalStateException if a controller cannot be started on the requested port
*/
- private static void stopMain() throws Exception {
+ private static void stopMain() throws ControlLoopException, InterruptedException {
if (main != null) {
Main main2 = main;
main = null;
@@ -260,4 +259,4 @@ public class CommonRestController {
Response rawresp = sendNoAuthRequest(endPoint).delete();
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
}
-} \ No newline at end of file
+}