summaryrefslogtreecommitdiffstats
path: root/testsuites/integration/integration-common
diff options
context:
space:
mode:
authoraditya.puthuparambil <aditya.puthuparambil@est.tech>2020-03-04 14:31:19 +0000
committeraditya.puthuparambil <aditya.puthuparambil@est.tech>2020-03-05 14:11:51 +0000
commit4af61a25ecfb60b7caa8d10b284195d3bef90ad4 (patch)
treee968a68e58546c279b899946c8e122e6552b5402 /testsuites/integration/integration-common
parenta9b60303e7e3699cc4df904144592ea6a9b6c586 (diff)
Fixing SONAR bug + code smell
Change-Id: If76ddc860b67e0d8dcd4c48bacb5436ffc773faa Issue-ID: POLICY-1913 Signed-off-by: aditya.puthuparambil <aditya.puthuparambil@est.tech>
Diffstat (limited to 'testsuites/integration/integration-common')
-rw-r--r--testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/java/DefaultTaskLogic.java54
1 files changed, 28 insertions, 26 deletions
diff --git a/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/java/DefaultTaskLogic.java b/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/java/DefaultTaskLogic.java
index e860da7c1..c1c656490 100644
--- a/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/java/DefaultTaskLogic.java
+++ b/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/java/DefaultTaskLogic.java
@@ -1,26 +1,28 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.testsuites.integration.common.model.java;
-import java.util.Random;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
import org.onap.policy.apex.core.engine.executor.context.TaskExecutionContext;
@@ -34,37 +36,37 @@ public class DefaultTaskLogic {
* Gets the event.
*
* @param executor the executor
- * @return the event
+ * @return true , if the event exists
*/
public boolean getEvent(final TaskExecutionContext executor) {
String idString = executor.subject.getId();
executor.logger.debug(idString);
-
+
String albumNameString = executor.getContextAlbum("GlobalContextAlbum").getName();
executor.logger.debug(albumNameString);
-
+
String inFieldsString = executor.inFields.toString();
executor.logger.debug(inFieldsString);
- final Random rand = new Random();
-
- if (executor.inFields.containsKey("TestDecideCaseSelected")) {
- executor.outFields.put("TestActCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
- executor.outFields.put("TestActStateTime", java.lang.System.nanoTime());
- }
- else if (executor.inFields.containsKey("TestEstablishCaseSelected")) {
- executor.outFields.put("TestDecideCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
- executor.outFields.put("TestDecideStateTime", java.lang.System.nanoTime());
+ try {
+ SecureRandom rand = SecureRandom.getInstanceStrong();
+ if (executor.inFields.containsKey("TestDecideCaseSelected")) {
+ executor.outFields.put("TestActCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
+ executor.outFields.put("TestActStateTime", System.nanoTime());
+ } else if (executor.inFields.containsKey("TestEstablishCaseSelected")) {
+ executor.outFields.put("TestDecideCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
+ executor.outFields.put("TestDecideStateTime", System.nanoTime());
+ } else if (executor.inFields.containsKey("TestMatchCaseSelected")) {
+ executor.outFields.put("TestEstablishCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
+ executor.outFields.put("TestEstablishStateTime", System.nanoTime());
+ } else {
+ executor.outFields.put("TestMatchCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
+ executor.outFields.put("TestMatchStateTime", System.nanoTime());
+ }
+ } catch (NoSuchAlgorithmException e) {
+ executor.logger.error("Exception during Random number generation ", e);
+ return false;
}
- else if (executor.inFields.containsKey("TestMatchCaseSelected")) {
- executor.outFields.put("TestEstablishCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
- executor.outFields.put("TestEstablishStateTime", java.lang.System.nanoTime());
- }
- else {
- executor.outFields.put("TestMatchCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
- executor.outFields.put("TestMatchStateTime", java.lang.System.nanoTime());
- }
-
- return true;
+ return true;
}
}