summaryrefslogtreecommitdiffstats
path: root/models-sim/policy-models-sim-pdp/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-14 15:02:00 -0400
committerJim Hahn <jrh3@att.com>2019-06-17 17:39:54 -0400
commit77df45928640808633af05908c680955848e4cd2 (patch)
tree799e3b9de30f65007c6965baf3e35200610e7de2 /models-sim/policy-models-sim-pdp/src/test
parent3deee00dcccb21efa194be439915ae06e878fd44 (diff)
Fix simple sonar issues in models: errors to sim-pdp
models-errors models-pdp models-provider models-sim-pdp Also had to work around this checkstyle issue: src/test/java/org/onap/policy/models/sim/pdp/comm/ TestPdpStateChangeListener.java:[77,32] (javadoc) JavadocMethod: Unable to get class information for @throws tag 'PdpSimulatorException'. The error appears to be bogus, as PdpSimulatorException is on the "throws" line thus indicating that the class IS accessible to the above java file. Change-Id: Iaca58457a32b00121000fc0bab12a8be4cb19bac Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-sim/policy-models-sim-pdp/src/test')
-rw-r--r--models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java26
-rw-r--r--models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java12
-rw-r--r--models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.java7
-rw-r--r--models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterHandler.java48
-rw-r--r--models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpStatusParameters.java5
5 files changed, 39 insertions, 59 deletions
diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java
index 8e3582e21..324edd7c5 100644
--- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java
+++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@@ -23,7 +24,6 @@ package org.onap.policy.models.sim.pdp.comm;
import static org.junit.Assert.assertEquals;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -33,7 +33,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -46,7 +45,6 @@ import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.sim.pdp.PdpSimulatorActivator;
import org.onap.policy.models.sim.pdp.PdpSimulatorCommandLineArguments;
import org.onap.policy.models.sim.pdp.PdpSimulatorConstants;
-import org.onap.policy.models.sim.pdp.exception.PdpSimulatorException;
import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterGroup;
import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterHandler;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -57,6 +55,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
public class TestPdpStateChangeListener {
+ private static final String PDP_SUBGROUP = "pdpSubgroup";
+ private static final String PDP_GROUP = "pdpGroup";
private PdpUpdateListener pdpUpdateMessageListener;
private PdpStateChangeListener pdpStateChangeListener;
private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
@@ -66,12 +66,10 @@ public class TestPdpStateChangeListener {
/**
* Method for setup before each test.
*
- * @throws PdpSimulatorException if some error occurs while starting up the pdp simulator
- * @throws FileNotFoundException if the file is missing
- * @throws IOException if IO exception occurs
+ * @throws Exception if an error occurs
*/
@Before
- public void setUp() throws PdpSimulatorException, FileNotFoundException, IOException {
+ public void setUp() throws Exception {
pdpUpdateMessageListener = new PdpUpdateListener();
pdpStateChangeListener = new PdpStateChangeListener();
Registry.newRegistry();
@@ -125,8 +123,8 @@ public class TestPdpStateChangeListener {
private PdpUpdate performPdpUpdate(final String instance) {
final PdpUpdate pdpUpdateMsg = new PdpUpdate();
pdpUpdateMsg.setDescription("dummy pdp status for test");
- pdpUpdateMsg.setPdpGroup("pdpGroup");
- pdpUpdateMsg.setPdpSubgroup("pdpSubgroup");
+ pdpUpdateMsg.setPdpGroup(PDP_GROUP);
+ pdpUpdateMsg.setPdpSubgroup(PDP_SUBGROUP);
pdpUpdateMsg.setName(instance);
final ToscaPolicy toscaPolicy = new ToscaPolicy();
toscaPolicy.setType("apexpolicytype");
@@ -142,7 +140,7 @@ public class TestPdpStateChangeListener {
propertiesMap.put("content", "");
}
toscaPolicy.setProperties(propertiesMap);
- final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
+ final List<ToscaPolicy> toscaPolicies = new ArrayList<>();
toscaPolicies.add(toscaPolicy);
pdpUpdateMsg.setPolicies(toscaPolicies);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
@@ -155,8 +153,8 @@ public class TestPdpStateChangeListener {
performPdpUpdate(pdpStatus.getName());
final PdpStateChange pdpStateChangeMsg = new PdpStateChange();
pdpStateChangeMsg.setState(PdpState.PASSIVE);
- pdpStateChangeMsg.setPdpGroup("pdpGroup");
- pdpStateChangeMsg.setPdpSubgroup("pdpSubgroup");
+ pdpStateChangeMsg.setPdpGroup(PDP_GROUP);
+ pdpStateChangeMsg.setPdpSubgroup(PDP_SUBGROUP);
pdpStateChangeMsg.setName(pdpStatus.getName());
pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg);
@@ -170,8 +168,8 @@ public class TestPdpStateChangeListener {
pdpStatus.setState(PdpState.ACTIVE);
final PdpStateChange pdpStateChangeMsg = new PdpStateChange();
pdpStateChangeMsg.setState(PdpState.ACTIVE);
- pdpStateChangeMsg.setPdpGroup("pdpGroup");
- pdpStateChangeMsg.setPdpSubgroup("pdpSubgroup");
+ pdpStateChangeMsg.setPdpGroup(PDP_GROUP);
+ pdpStateChangeMsg.setPdpSubgroup(PDP_SUBGROUP);
pdpStateChangeMsg.setName(pdpStatus.getName());
pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg);
diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java
index f3885f42d..e5eebf066 100644
--- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java
+++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@@ -23,7 +24,6 @@ package org.onap.policy.models.sim.pdp.comm;
import static org.junit.Assert.assertEquals;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -33,7 +33,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -44,7 +43,6 @@ import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.sim.pdp.PdpSimulatorActivator;
import org.onap.policy.models.sim.pdp.PdpSimulatorCommandLineArguments;
import org.onap.policy.models.sim.pdp.PdpSimulatorConstants;
-import org.onap.policy.models.sim.pdp.exception.PdpSimulatorException;
import org.onap.policy.models.sim.pdp.handler.PdpMessageHandler;
import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterGroup;
import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterHandler;
@@ -64,12 +62,10 @@ public class TestPdpUpdateListener {
/**
* Method for setup before each test.
*
- * @throws PdpSimulatorException if some error occurs while starting up the pdp simulator
- * @throws FileNotFoundException if the file is missing
- * @throws IOException if IO exception occurs
+ * @throws Exception if an error occurs
*/
@Before
- public void setUp() throws PdpSimulatorException, FileNotFoundException, IOException {
+ public void setUp() throws Exception {
Registry.newRegistry();
final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json",
"-p", "src/test/resources/topic.properties" };
@@ -136,7 +132,7 @@ public class TestPdpUpdateListener {
propertiesMap.put("content", "");
}
toscaPolicy.setProperties(propertiesMap);
- final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
+ final List<ToscaPolicy> toscaPolicies = new ArrayList<>();
toscaPolicies.add(toscaPolicy);
pdpUpdateMsg.setPolicies(toscaPolicies);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.java
index 4351645b8..e0da3d805 100644
--- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.java
+++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@@ -45,9 +46,9 @@ public class CommonTestData {
public static final String DESCRIPTION = "Pdp status for HealthCheck";
public static final String POLICY_NAME = "onap.controllloop.operational.apex.BBS";
public static final String POLICY_VERSION = "0.0.1";
- public static final List<ToscaPolicyTypeIdentifierParameters> SUPPORTED_POLICY_TYPES =
+ protected static final List<ToscaPolicyTypeIdentifierParameters> SUPPORTED_POLICY_TYPES =
Arrays.asList(getSupportedPolicyTypes(POLICY_NAME, POLICY_VERSION));
- private static final String REST_SERVER_PASSWORD = "zb!XztG34";
+ private static final String REST_SERVER_PASS = "zb!XztG34";
private static final String REST_SERVER_USER = "healthcheck";
private static final int REST_SERVER_PORT = 6969;
private static final String REST_SERVER_HOST = "0.0.0.0";
@@ -116,7 +117,7 @@ public class CommonTestData {
map.put("host", REST_SERVER_HOST);
map.put("port", REST_SERVER_PORT);
map.put("userName", REST_SERVER_USER);
- map.put("password", REST_SERVER_PASSWORD);
+ map.put("password", REST_SERVER_PASS);
}
return map;
diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterHandler.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterHandler.java
index e8e1f9036..337092f2f 100644
--- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterHandler.java
+++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterHandler.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@@ -20,6 +21,7 @@
package org.onap.policy.models.sim.pdp.parameters;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -61,12 +63,8 @@ public class TestPdpSimulatorParameterHandler {
final PdpSimulatorCommandLineArguments noArguments = new PdpSimulatorCommandLineArguments();
noArguments.parse(noArgumentString);
- try {
- new PdpSimulatorParameterHandler().getParameters(noArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("no parameters found"));
- }
+ assertThatThrownBy(() -> new PdpSimulatorParameterHandler().getParameters(noArguments))
+ .hasMessageContaining("no parameters found");
}
@Test
@@ -76,13 +74,9 @@ public class TestPdpSimulatorParameterHandler {
final PdpSimulatorCommandLineArguments invalidArguments = new PdpSimulatorCommandLineArguments();
invalidArguments.parse(invalidArgumentString);
- try {
- new PdpSimulatorParameterHandler().getParameters(invalidArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().startsWith("error reading parameters from"));
- assertTrue(e.getCause() instanceof CoderException);
- }
+ assertThatThrownBy(() -> new PdpSimulatorParameterHandler().getParameters(invalidArguments))
+ .hasMessageStartingWith("error reading parameters from")
+ .hasCauseInstanceOf(CoderException.class);
}
@Test
@@ -92,11 +86,8 @@ public class TestPdpSimulatorParameterHandler {
final PdpSimulatorCommandLineArguments noArguments = new PdpSimulatorCommandLineArguments();
noArguments.parse(noArgumentString);
- try {
- new PdpSimulatorParameterHandler().getParameters(noArguments);
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("is null"));
- }
+ assertThatThrownBy(() -> new PdpSimulatorParameterHandler().getParameters(noArguments))
+ .hasMessageContaining("is null");
}
@Test
@@ -113,19 +104,14 @@ public class TestPdpSimulatorParameterHandler {
@Test
public void testPdpSimulatorParameterGroup_InvalidName() throws PdpSimulatorException {
- final String[] pdpSimulatorConfigParameters = {"-c",
+ final String[] pdpSimulatorConfigParameters = {"-c",
"src/test/resources/PdpSimulatorConfigParameters_InvalidName.json"};
final PdpSimulatorCommandLineArguments arguments = new PdpSimulatorCommandLineArguments();
arguments.parse(pdpSimulatorConfigParameters);
- try {
- new PdpSimulatorParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains(
- "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string"));
- }
+ assertThatThrownBy(() -> new PdpSimulatorParameterHandler().getParameters(arguments)).hasMessageContaining(
+ "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string");
}
@Test
@@ -145,13 +131,11 @@ public class TestPdpSimulatorParameterHandler {
}
@Test
- public void testPdpSimulatorInvalidOption() throws PdpSimulatorException {
+ public void testPdpSimulatorInvalidOption() {
final String[] pdpSimulatorConfigParameters = { "-d" };
final PdpSimulatorCommandLineArguments arguments = new PdpSimulatorCommandLineArguments();
- try {
- arguments.parse(pdpSimulatorConfigParameters);
- } catch (final Exception exp) {
- assertTrue(exp.getMessage().startsWith("invalid command line arguments specified"));
- }
+
+ assertThatThrownBy(() -> arguments.parse(pdpSimulatorConfigParameters))
+ .hasMessageStartingWith("invalid command line arguments specified");
}
}
diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpStatusParameters.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpStatusParameters.java
index a48082901..49ec29bb7 100644
--- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpStatusParameters.java
+++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpStatusParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@@ -36,7 +37,7 @@ public class TestPdpStatusParameters {
private static CommonTestData testData = new CommonTestData();
@Test
- public void test() throws Exception {
+ public void test() {
final PdpStatusParameters pdpStatusParameters =
testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
final GroupValidationResult validationResult = pdpStatusParameters.validate();
@@ -48,7 +49,7 @@ public class TestPdpStatusParameters {
}
@Test
- public void testValidate() throws Exception {
+ public void testValidate() {
final PdpStatusParameters pdpStatusParameters =
testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
final GroupValidationResult result = pdpStatusParameters.validate();