summaryrefslogtreecommitdiffstats
path: root/models-sim
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-06-18 12:22:21 +0000
committerGerrit Code Review <gerrit@onap.org>2019-06-18 12:22:21 +0000
commit26e7f16c6e3f224d38e09441be30c1d4fa795c2a (patch)
treed784ca790e8865577d6e2b0b44ee869af4eab45e /models-sim
parent92bd3a4d89a3f7740094e0c5dac278722fc3f27c (diff)
parent77df45928640808633af05908c680955848e4cd2 (diff)
Merge "Fix simple sonar issues in models: errors to sim-pdp"
Diffstat (limited to 'models-sim')
-rw-r--r--models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.java20
-rw-r--r--models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.java7
-rw-r--r--models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java3
-rw-r--r--models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.java6
-rw-r--r--models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java15
-rw-r--r--models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.java11
-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
11 files changed, 64 insertions, 96 deletions
diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.java
index be396de05..502dec7b3 100644
--- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.java
+++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.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.
@@ -22,11 +23,9 @@ package org.onap.policy.models.sim.pdp;
import java.util.List;
import java.util.Properties;
-
+import java.util.Random;
import lombok.Getter;
import lombok.Setter;
-
-
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
@@ -57,6 +56,7 @@ public class PdpSimulatorActivator {
private List<TopicSink> topicSinks;// topics to which pdp sends pdp status
private List<TopicSource> topicSources; // topics to which pdp listens to for messages from pap.
private static final String[] MSG_TYPE_NAMES = { "messageName" };
+ private static final Random RANDOM = new Random();
/**
* Listens for messages on the topic, decodes them into a message, and then dispatches them.
@@ -85,9 +85,9 @@ public class PdpSimulatorActivator {
topicSinks = TopicEndpoint.manager.addTopicSinks(topicProperties);
topicSources = TopicEndpoint.manager.addTopicSources(topicProperties);
- final int random = (int) (Math.random() * 1000);
+ final int random = RANDOM.nextInt();
final String instanceId = "pdp_" + random;
- LOGGER.debug("PdpSimulatorActivator initializing with instance id:" + instanceId);
+ LOGGER.debug("PdpSimulatorActivator initializing with instance id: {}", instanceId);
try {
this.pdpSimulatorParameterGroup = pdpSimulatorParameterGroup;
this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES);
@@ -100,8 +100,8 @@ public class PdpSimulatorActivator {
// @formatter:off
this.manager = new ServiceManager()
.addAction("topics",
- () -> TopicEndpoint.manager.start(),
- () -> TopicEndpoint.manager.shutdown())
+ TopicEndpoint.manager::start,
+ TopicEndpoint.manager::shutdown)
.addAction("set alive",
() -> setAlive(true),
() -> setAlive(false))
@@ -117,7 +117,7 @@ public class PdpSimulatorActivator {
() -> Registry.register(PdpSimulatorConstants.REG_PDP_STATUS_PUBLISHER,
new PdpStatusPublisher(topicSinks,
pdpSimulatorParameterGroup.getPdpStatusParameters().getTimeIntervalMs())),
- () -> stopAndRemovePdpStatusPublisher())
+ this::stopAndRemovePdpStatusPublisher)
.addAction("Register pdp update listener",
() -> msgDispatcher.register(PdpMessageType.PDP_UPDATE.name(), pdpUpdateListener),
() -> msgDispatcher.unregister(PdpMessageType.PDP_UPDATE.name()))
@@ -125,8 +125,8 @@ public class PdpSimulatorActivator {
() -> msgDispatcher.register(PdpMessageType.PDP_STATE_CHANGE.name(), pdpStateChangeListener),
() -> msgDispatcher.unregister(PdpMessageType.PDP_STATE_CHANGE.name()))
.addAction("Message Dispatcher",
- () -> registerMsgDispatcher(),
- () -> unregisterMsgDispatcher());
+ this::registerMsgDispatcher,
+ this::unregisterMsgDispatcher);
// @formatter:on
}
diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.java
index f5892d5c8..78330135a 100644
--- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.java
+++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.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,8 +24,6 @@ package org.onap.policy.models.sim.pdp;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Properties;
-
-
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.sim.pdp.exception.PdpSimulatorException;
import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterGroup;
@@ -52,7 +51,9 @@ public class PdpSimulatorMain {
* @param args the command line arguments
*/
public PdpSimulatorMain(final String[] args) {
- LOGGER.info("In PdpSimulator with parameters ", Arrays.toString(args));
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("In PdpSimulator with parameters {}", Arrays.toString(args));
+ }
// Check the arguments
final PdpSimulatorCommandLineArguments arguments = new PdpSimulatorCommandLineArguments();
diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java
index d4296c6df..7b8f29c4b 100644
--- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java
+++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.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.
@@ -22,8 +23,6 @@ package org.onap.policy.models.sim.pdp.handler;
import java.util.ArrayList;
import java.util.List;
-
-
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
import org.onap.policy.models.pdp.concepts.PdpStatus;
diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.java
index ec1fa25a3..9df1aa103 100644
--- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.java
+++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.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.
@@ -21,7 +22,6 @@
package org.onap.policy.models.sim.pdp.handler;
import java.util.List;
-
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
@@ -31,8 +31,6 @@ import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.sim.pdp.PdpSimulatorConstants;
import org.onap.policy.models.sim.pdp.comm.PdpStatusPublisher;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* This class supports the handling of pdp state change messages.
@@ -41,8 +39,6 @@ import org.slf4j.LoggerFactory;
*/
public class PdpStateChangeMessageHandler {
- private static final Logger LOGGER = LoggerFactory.getLogger(PdpStateChangeMessageHandler.class);
-
/**
* Method which handles a pdp state change event from PAP.
*
diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java
index 94499f43d..4f33d079f 100644
--- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java
+++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.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.
@@ -21,8 +22,6 @@
package org.onap.policy.models.sim.pdp.handler;
import java.util.List;
-
-
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
@@ -32,8 +31,6 @@ import org.onap.policy.models.pdp.enums.PdpResponseStatus;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.sim.pdp.PdpSimulatorConstants;
import org.onap.policy.models.sim.pdp.comm.PdpStatusPublisher;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* This class supports the handling of pdp update messages.
@@ -42,8 +39,6 @@ import org.slf4j.LoggerFactory;
*/
public class PdpUpdateMessageHandler {
- private static final Logger LOGGER = LoggerFactory.getLogger(PdpUpdateMessageHandler.class);
-
/**
* Method which handles a pdp update event from PAP.
*
@@ -68,11 +63,9 @@ public class PdpUpdateMessageHandler {
pdpStatusContext.setPdpSubgroup(pdpUpdateMsg.getPdpSubgroup());
pdpStatusContext
.setPolicies(new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()));
- if (pdpStatusContext.getState().equals(PdpState.ACTIVE)) {
- if (!pdpUpdateMsg.getPolicies().isEmpty()) {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
- PdpResponseStatus.SUCCESS, "Pdp engine started and policies are running.");
- }
+ if (pdpStatusContext.getState().equals(PdpState.ACTIVE) && !pdpUpdateMsg.getPolicies().isEmpty()) {
+ pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ PdpResponseStatus.SUCCESS, "Pdp engine started and policies are running.");
}
Registry.registerOrReplace(PdpSimulatorConstants.REG_PDP_TOSCA_POLICY_LIST, pdpUpdateMsg.getPolicies());
if (null == pdpResponseDetails) {
diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.java
index 2c5ccebf9..84ae53908 100644
--- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.java
+++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.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.
@@ -21,8 +22,6 @@
package org.onap.policy.models.sim.pdp.parameters;
import java.io.File;
-
-
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
@@ -39,7 +38,7 @@ import org.slf4j.LoggerFactory;
*/
public class PdpSimulatorParameterHandler {
- private static final Logger LOGGER = LoggerFactory.getLogger(PdpSimulatorParameterHandler.class);
+ private static final Logger logger = LoggerFactory.getLogger(PdpSimulatorParameterHandler.class);
private static final Coder CODER = new StandardCoder();
/**
@@ -61,14 +60,14 @@ public class PdpSimulatorParameterHandler {
} catch (final CoderException e) {
final String errorMessage = "error reading parameters from \"" + arguments.getConfigurationFilePath()
+ "\"\n" + "(" + e.getClass().getSimpleName() + "):" + e.getMessage();
- LOGGER.error(errorMessage, e);
+ logger.error(errorMessage);
throw new PdpSimulatorException(errorMessage, e);
}
// The JSON processing returns null if there is an empty file
if (pdpSimulatorParameterGroup == null) {
final String errorMessage = "no parameters found in \"" + arguments.getConfigurationFilePath() + "\"";
- LOGGER.error(errorMessage);
+ logger.error(errorMessage);
throw new PdpSimulatorException(errorMessage);
}
@@ -79,7 +78,7 @@ public class PdpSimulatorParameterHandler {
"validation error(s) on parameters from \"" + arguments.getConfigurationFilePath() + "\"\n";
returnMessage += validationResult.getResult();
- LOGGER.error(returnMessage);
+ logger.error(returnMessage);
throw new PdpSimulatorException(returnMessage);
}
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();