Address sonar issues in common
Addressed the following sonar issues:
- missing assertion in junit test case
- disable sonars about setAccessible() as it's required for jackson
emulation
- sleep in junit
- don't use wild-cards (e.g., "*") with java.util Pattern
- use re2j instead of java.util Pattern
- use String methods (e.g., startsWith())
- duplicate method bodies
- duplicate code in Coder classes
- string concatenation in logger calls
- UTF-8 encoding
- return primitive instead of boxed primitive
- add assertion to tests
- renamed support methods from doTestXxx to verifyXxx
- cognitive complexity
- use AtomicRef instead of volatile
- use specific Functionals (e.g., IntConsumer)
- function always returns the same value
- serializable vs transient
Issue-ID: POLICY-2305
Change-Id: I08eb7aa495a80bdc1d26827ba17a7946c83b9828
Signed-off-by: Jim Hahn <jrh3@att.com>
diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java b/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java
index 174b491..39ec6bd 100644
--- a/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java
+++ b/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -83,7 +83,10 @@
this.gson = gson;
this.fullName = getQualifiedName(field);
- field.setAccessible(true);
+ /*
+ * Turning off sonar, as this is required for emulation of "jackson".
+ */
+ field.setAccessible(true); // NOSONAR
}
/**
@@ -100,7 +103,10 @@
this.gson = gson;
this.fullName = getQualifiedName(accessor);
- accessor.setAccessible(true);
+ /*
+ * Turning off sonar, as this is required for emulation of "jackson".
+ */
+ accessor.setAccessible(true); // NOSONAR
}
/**
diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/FieldDeserializer.java b/gson/src/main/java/org/onap/policy/common/gson/internal/FieldDeserializer.java
index 14a432d..123b019 100644
--- a/gson/src/main/java/org/onap/policy/common/gson/internal/FieldDeserializer.java
+++ b/gson/src/main/java/org/onap/policy/common/gson/internal/FieldDeserializer.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -49,7 +49,10 @@
this.field = field;
- field.setAccessible(true);
+ /*
+ * Turning off sonar, as this is required for emulation of "jackson".
+ */
+ field.setAccessible(true); // NOSONAR
}
@Override
@@ -62,7 +65,10 @@
Object value = fromJsonTree(jsonEl);
try {
- field.set(target, value);
+ /*
+ * Turning off sonar, as this is required for emulation of "jackson".
+ */
+ field.set(target, value); // NOSONAR
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new JsonParseException(makeError(SET_ERR), e);
diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/FieldSerializer.java b/gson/src/main/java/org/onap/policy/common/gson/internal/FieldSerializer.java
index 1c9d8b3..348ef5a 100644
--- a/gson/src/main/java/org/onap/policy/common/gson/internal/FieldSerializer.java
+++ b/gson/src/main/java/org/onap/policy/common/gson/internal/FieldSerializer.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -50,7 +50,10 @@
this.field = field;
- field.setAccessible(true);
+ /*
+ * Turning off sonar, as this is required for emulation of "jackson".
+ */
+ field.setAccessible(true); // NOSONAR
}
@Override
diff --git a/gson/src/test/java/org/onap/policy/common/gson/MapDoubleAdapterFactoryTest.java b/gson/src/test/java/org/onap/policy/common/gson/MapDoubleAdapterFactoryTest.java
index 79631c5..30d9946 100644
--- a/gson/src/test/java/org/onap/policy/common/gson/MapDoubleAdapterFactoryTest.java
+++ b/gson/src/test/java/org/onap/policy/common/gson/MapDoubleAdapterFactoryTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -21,6 +21,7 @@
package org.onap.policy.common.gson;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -104,8 +105,8 @@
map = gson.fromJson(json, MyDoubleMap.class);
// everything should still be Double - check by simply accessing
- map.data.get("plainDouble");
- map.data.get("doubleAsInt");
+ assertNotNull(map.data.get("plainDouble"));
+ assertNotNull(map.data.get("doubleAsInt"));
}
@Test
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java
index a7b7fd8..f69173f 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java
@@ -174,22 +174,8 @@
compareMineWithTheirs(persistenceUnit, iaeList, myIae, misMatchedMap, clazzName, myEntries);
// Time check
- if ((AuditorTime.getInstance().getMillis() - startTime) >= DB_AUDIT_UPDATE_MS) {
- // update the timestamp
- dbDao.setLastUpdated();
- // reset the startTime
- startTime = AuditorTime.getInstance().getMillis();
- } else {
- // sleep a couple seconds to break up the activity
- if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Sleeping " + DB_AUDIT_SLEEP_MS + "ms");
- }
- sleep();
- if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Waking from sleep");
- }
- }
- } // end: for(String clazzName: classNameList)
+ startTime = timeCheck("First", startTime);
+ }
// check if misMatchedMap is empty
if (misMatchedMap.isEmpty()) {
@@ -197,8 +183,6 @@
if (logger.isDebugEnabled()) {
logger.debug("dbAudit: Exiting, misMatchedMap is empty");
}
- // we are done
- return;
} else {
if (logger.isDebugEnabled()) {
logger.debug("dbAudit: Doing another comparison; misMatchedMap.size()=" + misMatchedMap.size());
@@ -258,6 +242,25 @@
}
}
+ private long timeCheck(String type, long startTime) throws IntegrityAuditException {
+ if ((AuditorTime.getInstance().getMillis() - startTime) >= DB_AUDIT_UPDATE_MS) {
+ // update the timestamp
+ dbDao.setLastUpdated();
+ // reset the startTime
+ return AuditorTime.getInstance().getMillis();
+ } else {
+ // sleep a couple seconds to break up the activity
+ if (logger.isDebugEnabled()) {
+ logger.debug("dbAudit: " + type + " comparison; sleeping " + DB_AUDIT_SLEEP_MS + "ms");
+ }
+ sleep();
+ if (logger.isDebugEnabled()) {
+ logger.debug("dbAudit: " + type + " comparison; waking from sleep");
+ }
+ return startTime;
+ }
+ }
+
/**
* Creates properties for the other db node.
* @param iae target DB node
@@ -310,21 +313,7 @@
errorCount += recompareMineWithTheirs(resourceName, persistenceUnit, iaeList, myIae, clazzName,
keySet, myEntries);
// Time check
- if ((AuditorTime.getInstance().getMillis() - startTime) >= DB_AUDIT_UPDATE_MS) {
- // update the timestamp
- dbDao.setLastUpdated();
- // reset the startTime
- startTime = AuditorTime.getInstance().getMillis();
- } else {
- // sleep a couple seconds to break up the activity
- if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Second comparison; sleeping " + DB_AUDIT_SLEEP_MS + "ms");
- }
- sleep();
- if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Second comparison; waking from sleep");
- }
- }
+ startTime = timeCheck("Second", startTime);
}
if (errorCount != 0) {
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java
index 959a4e7..fda7e4a 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@@ -95,7 +96,7 @@
TextFileUtils.getTextFileAsString("testingLogs/common-modules/integrity-audit/logging-pattern-test.log")
.substring(23);
String expectedLoggedString = TextFileUtils
- .getTextFileAsString("src/test/resources/" + loggerString + "-test.expectedlog").substring(23);
+ .getTextFileAsString("src/test/resources/" + loggerString + "-test.expectedlog").substring(23).trim();
assertThat(actualLoggedString).contains(expectedLoggedString);
}
diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java
index d96aa44..3cb708e 100644
--- a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java
+++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java
@@ -31,6 +31,8 @@
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
+import java.util.function.IntConsumer;
+import java.util.function.LongConsumer;
import java.util.function.Supplier;
import javax.management.JMX;
import javax.management.MBeanServerConnection;
@@ -102,7 +104,7 @@
/**
* Set to {@code null} if to stop running.
*/
- private volatile Thread fpManager = null;
+ private AtomicReference<Thread> fpManager = new AtomicReference<>();
// The forward progress counter is incremented as the
// process being monitored makes forward progress
@@ -212,9 +214,8 @@
logger.error("{}", msg);
throw new IntegrityMonitorException("IntegrityMonitor constructor exception: " + msg);
}
- instance = this;
- IntegrityMonitor.resourceName = resourceName;
+ setInstance(this, resourceName);
/*
* Validate that the properties file contains all the needed properties. Throws an
@@ -248,71 +249,14 @@
try {
// if ForwardProgress entry exists for resourceName, update it. If
// not found, create a new entry
- Query fquery = em.createQuery(QUERY_STRING);
- fquery.setParameter("rn", resourceName);
-
- @SuppressWarnings("rawtypes")
- List fpList = fquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
- ForwardProgressEntity fpx = null;
- if (!fpList.isEmpty()) {
- // ignores multiple results
- fpx = (ForwardProgressEntity) fpList.get(0);
- // refresh the object from DB in case cached data was returned
- em.refresh(fpx);
- if (logger.isDebugEnabled()) {
- logger.debug("Resource {} exists and will be updated - old fpc= {}, lastUpdated= {}", resourceName,
- fpx.getFpcCount(), fpx.getLastUpdated());
- }
- fpx.setFpcCount(fpCounter);
- } else {
- // Create a forward progress object
- logger.debug("Adding resource {} to ForwardProgress table", resourceName);
- fpx = new ForwardProgressEntity();
- }
- // update/set columns in entry
- fpx.setResourceName(resourceName);
- em.persist(fpx);
- // flush to the DB
- synchronized (imFlushLock) {
- em.flush();
- }
+ createOrUpdateForwardProgress(resourceName);
// if ResourceRegistration entry exists for resourceName, update it.
// If not found, create a new entry
- Query rquery = em.createQuery("Select r from ResourceRegistrationEntity r where r.resourceName=:rn");
- rquery.setParameter("rn", resourceName);
-
- @SuppressWarnings("rawtypes")
- List rrList = rquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
- ResourceRegistrationEntity rrx = null;
- if (!rrList.isEmpty()) {
- // ignores multiple results
- rrx = (ResourceRegistrationEntity) rrList.get(0);
- // refresh the object from DB in case cached data was returned
- em.refresh(rrx);
- if (logger.isDebugEnabled()) {
- logger.debug("Resource {} exists and will be updated - old url= {}, createdDate={}", resourceName,
- rrx.getResourceUrl(), rrx.getCreatedDate());
- }
- rrx.setLastUpdated(MonitorTime.getInstance().getDate());
- } else {
- // register resource by adding entry to table in DB
- logger.debug("Adding resource {} to ResourceRegistration table", resourceName);
- rrx = new ResourceRegistrationEntity();
- }
- // update/set columns in entry
- rrx.setResourceName(resourceName);
- rrx.setResourceUrl(jmxUrl);
- rrx.setNodeType(nodeType);
- rrx.setSite(siteName);
- em.persist(rrx);
- // flush to the DB
- synchronized (imFlushLock) {
- et.commit();
- }
+ createOrUpdateResourceReg(resourceName, jmxUrl, et);
} catch (Exception e) {
- logger.error("IntegrityMonitor constructor DB table update failed with exception: ", e);
+ logger.error("IntegrityMonitor constructor DB table update threw an exception");
try {
if (et.isActive()) {
synchronized (imFlushLock) {
@@ -325,6 +269,85 @@
throw e;
}
+ makeStateManager(resourceName);
+
+ // create management bean
+ makeManagementBean(resourceName);
+
+ // set now as the last time the refreshStateAudit ran
+ IntegrityMonitor.this.refreshStateAuditLastRunDate = MonitorTime.getInstance().getDate();
+
+ fpManager.set(new Thread(this::runFpManager));
+ fpManager.get().start();
+
+ }
+
+ protected void createOrUpdateForwardProgress(String resourceName) {
+ Query fquery = em.createQuery(QUERY_STRING);
+ fquery.setParameter("rn", resourceName);
+
+ @SuppressWarnings("rawtypes")
+ List fpList = fquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
+ ForwardProgressEntity fpx = null;
+ if (!fpList.isEmpty()) {
+ // ignores multiple results
+ fpx = (ForwardProgressEntity) fpList.get(0);
+ // refresh the object from DB in case cached data was returned
+ em.refresh(fpx);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Resource {} exists and will be updated - old fpc= {}, lastUpdated= {}", resourceName,
+ fpx.getFpcCount(), fpx.getLastUpdated());
+ }
+ fpx.setFpcCount(fpCounter);
+ } else {
+ // Create a forward progress object
+ logger.debug("Adding resource {} to ForwardProgress table", resourceName);
+ fpx = new ForwardProgressEntity();
+ }
+ // update/set columns in entry
+ fpx.setResourceName(resourceName);
+ em.persist(fpx);
+ // flush to the DB
+ synchronized (imFlushLock) {
+ em.flush();
+ }
+ }
+
+ protected void createOrUpdateResourceReg(String resourceName, String jmxUrl, EntityTransaction et) {
+ Query rquery = em.createQuery("Select r from ResourceRegistrationEntity r where r.resourceName=:rn");
+ rquery.setParameter("rn", resourceName);
+
+ @SuppressWarnings("rawtypes")
+ List rrList = rquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
+ ResourceRegistrationEntity rrx = null;
+ if (!rrList.isEmpty()) {
+ // ignores multiple results
+ rrx = (ResourceRegistrationEntity) rrList.get(0);
+ // refresh the object from DB in case cached data was returned
+ em.refresh(rrx);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Resource {} exists and will be updated - old url= {}, createdDate={}", resourceName,
+ rrx.getResourceUrl(), rrx.getCreatedDate());
+ }
+ rrx.setLastUpdated(MonitorTime.getInstance().getDate());
+ } else {
+ // register resource by adding entry to table in DB
+ logger.debug("Adding resource {} to ResourceRegistration table", resourceName);
+ rrx = new ResourceRegistrationEntity();
+ }
+ // update/set columns in entry
+ rrx.setResourceName(resourceName);
+ rrx.setResourceUrl(jmxUrl);
+ rrx.setNodeType(nodeType);
+ rrx.setSite(siteName);
+ em.persist(rrx);
+ // flush to the DB
+ synchronized (imFlushLock) {
+ et.commit();
+ }
+ }
+
+ protected void makeStateManager(String resourceName) throws IntegrityMonitorException {
try {
// create instance of StateManagement class and pass emf to it
stateManager = new StateManagement(emf, resourceName);
@@ -340,20 +363,19 @@
} catch (StateManagementException e) {
throw new IntegrityMonitorException(e);
}
+ }
- // create management bean
+ protected void makeManagementBean(String resourceName) {
try {
new ComponentAdmin(resourceName, this, stateManager);
} catch (Exception e) {
logger.error("ComponentAdmin constructor exception: {}", e.toString(), e);
}
+ }
- // set now as the last time the refreshStateAudit ran
- IntegrityMonitor.this.refreshStateAuditLastRunDate = MonitorTime.getInstance().getDate();
-
- fpManager = new Thread(this::runFpManager);
- fpManager.start();
-
+ private static void setInstance(IntegrityMonitor newInstance, String newResourceName) {
+ instance = newInstance;
+ resourceName = newResourceName;
}
/**
@@ -377,7 +399,8 @@
if (instance == null) {
logger.debug("Creating new instance of IntegrityMonitor");
- instance = new IntegrityMonitor(resourceName, properties);
+ // note: new() will populate "instance"
+ new IntegrityMonitor(resourceName, properties);
}
return instance;
}
@@ -409,7 +432,7 @@
synchronized (getInstanceLock) {
if (isUnitTesting() && instance != null && instance.fpManager != null) {
// Stop the FPManager thread
- Thread fpm = instance.fpManager;
+ Thread fpm = instance.fpManager.get();
instance.fpManager = null;
fpm.interrupt();
@@ -1296,7 +1319,7 @@
return propValue.trim();
}
- private static void setInt(Properties props, String propName, Consumer<Integer> setter) {
+ private static void setInt(Properties props, String propName, IntConsumer setter) {
String propValue = props.getProperty(propName);
if (StringUtils.isBlank(propValue)) {
return;
@@ -1309,7 +1332,7 @@
}
}
- private static void setLong(Properties props, String propName, Consumer<Long> setter) {
+ private static void setLong(Properties props, String propName, LongConsumer setter) {
String propValue = props.getProperty(propName);
if (StringUtils.isBlank(propValue)) {
return;
diff --git a/integrity-monitor/src/main/resources/logback.xml b/integrity-monitor/src/main/resources/logback.xml
index 1d49863..c7f1b50 100644
--- a/integrity-monitor/src/main/resources/logback.xml
+++ b/integrity-monitor/src/main/resources/logback.xml
@@ -2,7 +2,7 @@
============LICENSE_START=======================================================
Integrity Monitor
================================================================================
- Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ Copyright (C) 2017-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.
@@ -147,8 +147,6 @@
<maxFileSize>5MB</maxFileSize>
</triggeringPolicy>
<encoder>
- <!-- <pattern>"%d{HH:mm:ss.SSS} [%thread] %-5level %logger{1024} -
- %msg%n"</pattern> -->
<pattern>${defaultPattern}</pattern>
</encoder>
</appender>
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxy.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxy.java
index 9aabad5..6f3094f 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxy.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxy.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-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.
@@ -449,21 +449,21 @@
@Override
public boolean lock() {
+ boolean shouldLock;
synchronized (this) {
- if (this.locked) {
- return true;
- }
-
+ shouldLock = !this.locked;
this.locked = true;
}
- for (final TopicSource source : this.getTopicSources()) {
- source.lock();
- }
+ if (shouldLock) {
+ for (final TopicSource source : this.getTopicSources()) {
+ source.lock();
+ }
- for (final TopicSink sink : this.getTopicSinks()) {
- sink.lock();
+ for (final TopicSink sink : this.getTopicSinks()) {
+ sink.lock();
+ }
}
return true;
@@ -471,20 +471,21 @@
@Override
public boolean unlock() {
- synchronized (this) {
- if (!this.locked) {
- return true;
- }
+ boolean shouldUnlock;
+ synchronized (this) {
+ shouldUnlock = this.locked;
this.locked = false;
}
- for (final TopicSource source : this.getTopicSources()) {
- source.unlock();
- }
+ if (shouldUnlock) {
+ for (final TopicSource source : this.getTopicSources()) {
+ source.unlock();
+ }
- for (final TopicSink sink : this.getTopicSinks()) {
- sink.unlock();
+ for (final TopicSink sink : this.getTopicSinks()) {
+ sink.unlock();
+ }
}
return true;
@@ -579,4 +580,4 @@
logger.debug("No sink for topic: {}", topicName, ex);
}
-}
\ No newline at end of file
+}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpoint.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpoint.java
index 73c6165..833574a 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpoint.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpoint.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -94,16 +94,13 @@
logger.info("{}: starting", this);
synchronized (this) {
+ if (!this.alive) {
+ if (locked) {
+ throw new IllegalStateException(this + " is locked.");
+ }
- if (this.alive) {
- return true;
+ this.alive = true;
}
-
- if (locked) {
- throw new IllegalStateException(this + " is locked.");
- }
-
- this.alive = true;
}
return true;
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSink.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSink.java
index e94bdff..1666990 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSink.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSink.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2018-2019 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -84,17 +84,14 @@
logger.info("{}: starting", this);
synchronized (this) {
+ if (!this.alive) {
+ if (locked) {
+ throw new IllegalStateException(this + " is locked.");
+ }
- if (this.alive) {
- return true;
+ this.init();
+ this.alive = true;
}
-
- if (locked) {
- throw new IllegalStateException(this + " is locked.");
- }
-
- this.init();
- this.alive = true;
}
return true;
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSource.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSource.java
index 510ddaa..d0d25a2 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSource.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSource.java
@@ -225,7 +225,7 @@
try {
fetchAllMessages();
} catch (IOException | RuntimeException e) {
- logger.error("{}: cannot fetch because of ", this, e.getMessage(), e);
+ logger.error("{}: cannot fetch", this, e);
}
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/RestServer.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/RestServer.java
index 7274735..6776a32 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/RestServer.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/RestServer.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -125,7 +125,7 @@
}
private String getValue(final String value) {
- if (value != null && value.matches("[$][{].*[}]$")) {
+ if (value != null && value.startsWith("${") && value.endsWith("}")) {
return System.getenv(value.substring(2, value.length() - 1));
}
return value;
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java
index 0255c10..5264b2f 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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,7 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -65,7 +66,9 @@
new CambriaConsumerWrapper(makeBuilder().apiKey(null).apiSecret(null).build());
new CambriaConsumerWrapper(makeBuilder().userName(null).build());
new CambriaConsumerWrapper(makeBuilder().password(null).build());
- new CambriaConsumerWrapper(makeBuilder().userName(null).password(null).build());
+
+ assertThatCode(() -> new CambriaConsumerWrapper(makeBuilder().userName(null).password(null).build()))
+ .doesNotThrowAnyException();
}
@Test
@@ -101,7 +104,8 @@
// set filter several times to cause different branches of close() to be executed
for (int count = 0; count < 3; ++count) {
cons.close();
- cons.setFilter("close=" + count);
+ final int count2 = count;
+ assertThatCode(() -> cons.setFilter("close=" + count2)).doesNotThrowAnyException();
}
}
@@ -110,7 +114,8 @@
// set filter several times to cause different branches to be executed
CambriaConsumerWrapper cons = new CambriaConsumerWrapper(builder.build());
for (int count = 0; count < 3; ++count) {
- cons.setFilter("set-filter=" + count);
+ final int count2 = count;
+ assertThatCode(() -> cons.setFilter("set-filter=" + count2)).doesNotThrowAnyException();
}
}
@@ -122,7 +127,7 @@
@Test
public void testDmaapConsumerWrapper() throws Exception {
// verify that different wrappers can be built
- new DmaapAafConsumerWrapper(makeBuilder().build());
+ assertThatCode(() -> new DmaapAafConsumerWrapper(makeBuilder().build())).doesNotThrowAnyException();
}
@Test(expected = IllegalArgumentException.class)
@@ -167,7 +172,7 @@
@Test
public void testDmaapConsumerWrapperClose() throws Exception {
- new DmaapAafConsumerWrapper(makeBuilder().build()).close();
+ assertThatCode(() -> new DmaapAafConsumerWrapper(makeBuilder().build()).close()).doesNotThrowAnyException();
}
@Test
@@ -179,7 +184,8 @@
public void testDmaapAafConsumerWrapper() throws Exception {
// verify that different wrappers can be built
new DmaapAafConsumerWrapper(makeBuilder().useHttps(true).build());
- new DmaapAafConsumerWrapper(makeBuilder().useHttps(false).build());
+ assertThatCode(() -> new DmaapAafConsumerWrapper(makeBuilder().useHttps(false).build()))
+ .doesNotThrowAnyException();
}
@Test(expected = IllegalArgumentException.class)
@@ -207,7 +213,8 @@
addProps.put(ROUTE_PROP, MY_ROUTE);
new DmaapDmeConsumerWrapper(makeBuilder().build());
- new DmaapDmeConsumerWrapper(makeBuilder().partner(null).build());
+ assertThatCode(() -> new DmaapDmeConsumerWrapper(makeBuilder().partner(null).build()))
+ .doesNotThrowAnyException();
}
@Test(expected = IllegalArgumentException.class)
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusPublisherTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusPublisherTest.java
index 5a933e9..513673b 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusPublisherTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusPublisherTest.java
@@ -20,6 +20,7 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -66,7 +67,8 @@
new CambriaPublisherWrapper(makeBuilder().apiKey(null).apiSecret(null).build());
new CambriaPublisherWrapper(makeBuilder().userName(null).build());
new CambriaPublisherWrapper(makeBuilder().password(null).build());
- new CambriaPublisherWrapper(makeBuilder().userName(null).password(null).build());
+ assertThatCode(() -> new CambriaPublisherWrapper(makeBuilder().userName(null).password(null).build()))
+ .doesNotThrowAnyException();
}
@Test
@@ -109,7 +111,8 @@
// verify with different constructor arguments
new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASS, true);
new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASS, false);
- new DmaapPublisherWrapper(ProtocolTypeConstants.DME2, servers, MY_TOPIC, MY_USERNAME, MY_PASS, true) {};
+ assertThatCode(() -> new DmaapPublisherWrapper(ProtocolTypeConstants.DME2, servers, MY_TOPIC, MY_USERNAME,
+ MY_PASS, true) {}).doesNotThrowAnyException();
}
@Test(expected = IllegalArgumentException.class)
@@ -188,7 +191,7 @@
new DmaapDmePublisherWrapper(makeBuilder().partner(null).build());
addProps.put("null-value", null);
- new DmaapDmePublisherWrapper(makeBuilder().build());
+ assertThatCode(() -> new DmaapDmePublisherWrapper(makeBuilder().build())).doesNotThrowAnyException();
}
@Test(expected = IllegalArgumentException.class)
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java
index 0102804..0a2a5d3 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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,7 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -53,7 +54,7 @@
@Test
public void testSerialize() {
- new GsonTestUtils().compareGson(base, BusTopicBaseTest.class);
+ assertThatCode(() -> new GsonTestUtils().compareGson(base, BusTopicBaseTest.class)).doesNotThrowAnyException();
}
@Test
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java
index 634ee76..e6eec79 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java
@@ -20,6 +20,7 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -61,7 +62,8 @@
@Test
public void testSerialize() {
- new GsonTestUtils().compareGson(sink, InlineBusTopicSinkTest.class);
+ assertThatCode(() -> new GsonTestUtils().compareGson(sink, InlineBusTopicSinkTest.class))
+ .doesNotThrowAnyException();
}
@Test
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineDmaapTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineDmaapTopicSinkTest.java
index d9bc990..239bf33 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineDmaapTopicSinkTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineDmaapTopicSinkTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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,7 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -51,7 +52,8 @@
@Test
public void testSerialize() {
- new GsonTestUtils().compareGson(sink, InlineDmaapTopicSinkTest.class);
+ assertThatCode(() -> new GsonTestUtils().compareGson(sink, InlineDmaapTopicSinkTest.class))
+ .doesNotThrowAnyException();
}
@Test
@@ -70,7 +72,7 @@
sink = new InlineDmaapTopicSink(makeBuilder().environment(null).aftEnvironment(null).latitude(null)
.longitude(null).partner(null).build());
sink.init();
- sink.shutdown();
+ assertThatCode(() -> sink.shutdown()).doesNotThrowAnyException();
}
@Test
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineUebTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineUebTopicSinkTest.java
index a45504f..674f379 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineUebTopicSinkTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineUebTopicSinkTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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,7 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -51,7 +52,8 @@
@Test
public void testSerialize() {
- new GsonTestUtils().compareGson(sink, InlineUebTopicSinkTest.class);
+ assertThatCode(() -> new GsonTestUtils().compareGson(sink, InlineUebTopicSinkTest.class))
+ .doesNotThrowAnyException();
}
@Test
@@ -61,7 +63,7 @@
@Test
public void testInit() {
- sink.init();
+ assertThatCode(() -> sink.init()).doesNotThrowAnyException();
}
@Test
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java
index 16d74df..1e95924 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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,7 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -72,7 +73,8 @@
@Test
public void testSerialize() {
- new GsonTestUtils().compareGson(source, SingleThreadedBusTopicSourceTest.class);
+ assertThatCode(() -> new GsonTestUtils().compareGson(source, SingleThreadedBusTopicSourceTest.class))
+ .doesNotThrowAnyException();
}
@Test
@@ -163,7 +165,8 @@
new SingleThreadedBusTopicSourceImpl(makeBuilder().consumerGroup(null).build());
new SingleThreadedBusTopicSourceImpl(makeBuilder().consumerInstance(null).build());
new SingleThreadedBusTopicSourceImpl(makeBuilder().fetchTimeout(-1).build());
- new SingleThreadedBusTopicSourceImpl(makeBuilder().fetchLimit(-1).build());
+ assertThatCode(() -> new SingleThreadedBusTopicSourceImpl(makeBuilder().fetchLimit(-1).build()))
+ .doesNotThrowAnyException();
}
@Test
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSourceTest.java
index b7faf16..c7d3002 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSourceTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSourceTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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,7 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -53,7 +54,8 @@
@Test
public void testSerialize() {
- new GsonTestUtils().compareGson(source, SingleThreadedDmaapTopicSourceTest.class);
+ assertThatCode(() -> new GsonTestUtils().compareGson(source, SingleThreadedDmaapTopicSourceTest.class))
+ .doesNotThrowAnyException();
}
@Test
@@ -75,9 +77,10 @@
@Test
public void testInit() {
// verify with different parameters
- new SingleThreadedDmaapTopicSource(makeBuilder().userName(null).build()).shutdown();
new SingleThreadedDmaapTopicSource(makeBuilder().environment(null).aftEnvironment(null).latitude(null)
.longitude(null).partner(null).build()).shutdown();
+ assertThatCode(() -> new SingleThreadedDmaapTopicSource(makeBuilder().userName(null).build()).shutdown())
+ .doesNotThrowAnyException();
}
@Test(expected = IllegalArgumentException.class)
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedUebTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedUebTopicSourceTest.java
index 2ff353b..6536d0e 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedUebTopicSourceTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedUebTopicSourceTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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,7 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -51,7 +52,8 @@
@Test
public void testSerialize() {
- new GsonTestUtils().compareGson(source, SingleThreadedUebTopicSourceTest.class);
+ assertThatCode(() -> new GsonTestUtils().compareGson(source, SingleThreadedUebTopicSourceTest.class))
+ .doesNotThrowAnyException();
}
@Test
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBaseTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBaseTest.java
index 0cf1486..67b84ea 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBaseTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBaseTest.java
@@ -20,6 +20,7 @@
package org.onap.policy.common.endpoints.event.comm.bus.internal;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -97,7 +98,7 @@
@Test
public void testSerialize() {
- new GsonTestUtils().compareGson(base, TopicBaseTest.class);
+ assertThatCode(() -> new GsonTestUtils().compareGson(base, TopicBaseTest.class)).doesNotThrowAnyException();
}
@Test
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java
index e202b11..cbe5a5a 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@
package org.onap.policy.common.endpoints.http.server.test;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.Assert.assertEquals;
@@ -346,7 +347,7 @@
server.addFilterClass("/*", TestFilter.class.getName());
// ensure we can serialize the server
- new GsonTestUtils().compareGson(server, HttpServerTest.class);
+ assertThatCode(() -> new GsonTestUtils().compareGson(server, HttpServerTest.class)).doesNotThrowAnyException();
}
@Test
diff --git a/pom.xml b/pom.xml
index 330daa2..dc73625 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.onap.policy.parent</groupId>
<artifactId>integration</artifactId>
- <version>3.1.1</version>
+ <version>3.1.2-SNAPSHOT</version>
<relativePath />
</parent>
diff --git a/utils-test/pom.xml b/utils-test/pom.xml
index 6576627..9b428e7 100644
--- a/utils-test/pom.xml
+++ b/utils-test/pom.xml
@@ -37,6 +37,10 @@
<dependencies>
<dependency>
+ <groupId>com.google.re2j</groupId>
+ <artifactId>re2j</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-jexl3</artifactId>
<version>3.0</version>
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java b/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java
index 6ae42fa..01206c3 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java
@@ -27,6 +27,8 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
+import com.google.re2j.Matcher;
+import com.google.re2j.Pattern;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -37,8 +39,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.apache.commons.jexl3.JexlBuilder;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlEngine;
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java b/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java
index 0fba944..f051a10 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java
@@ -2,7 +2,7 @@
* ============LICENSE_START====================================================
* Common Utils-Test
* =============================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 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.
@@ -40,7 +40,7 @@
private static Logger logger =
LoggerFactory.getLogger(ThrowablesTester.class);
- public static final String EXPECTED_EXCEPTION_MSG =
+ public static final String EXPECTED_EXCEPTION_MSG =
"expected exception";
private static final String EXPECTED_SUPPRESSED_EXCEPTION_MSG =
"expected suppressed exception";
@@ -530,8 +530,7 @@
} catch (NoSuchMethodException | SecurityException e) {
// this constructor is not defined so nothing to test
- logger.debug("skipped test, no constructor for: "
- + claz + " due to: " + e);
+ logger.debug("skipped test, no constructor for: {}", claz, e);
return null;
}
}
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/time/PseudoScheduledExecutorService.java b/utils-test/src/main/java/org/onap/policy/common/utils/time/PseudoScheduledExecutorService.java
index 4f9b32c..847b058 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/time/PseudoScheduledExecutorService.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/time/PseudoScheduledExecutorService.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -86,7 +86,7 @@
@Override
public boolean isTerminated() {
- return shutdown;
+ return isShutdown();
}
@Override
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java b/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java
index 5002edf..f4b36a0 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java
@@ -298,7 +298,7 @@
logger.info("enqueue work item {}", item);
synchronized (updateLock) {
queue.add(item);
- updateLock.notify();
+ updateLock.notifyAll();
}
}
diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java
index cd6edf7..2eb0736 100644
--- a/utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java
+++ b/utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Common Utils-Test
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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.
@@ -376,21 +376,6 @@
// create some threads to get extractions
addThread(tend, err, xtxt -> app.getExtracted());
- // create some threads to clear extractions
- addThread(tend, err, xtxt -> {
- app.clearExtractions();
-
- // don't want to clear the list too frequently
- // so sleep a bit in between
- try {
- Thread.sleep(10L + Integer.valueOf(xtxt));
-
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw e;
- }
- });
-
/*
* Finally ready to start.
*/
diff --git a/utils/pom.xml b/utils/pom.xml
index 745b95d..4d6184a 100644
--- a/utils/pom.xml
+++ b/utils/pom.xml
@@ -65,6 +65,10 @@
<artifactId>guava</artifactId>
</dependency>
<dependency>
+ <groupId>com.google.re2j</groupId>
+ <artifactId>re2j</artifactId>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
diff --git a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java
index 2548dea..7f5e3b8 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java
@@ -40,8 +40,6 @@
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
-import lombok.AccessLevel;
-import lombok.Getter;
import org.onap.policy.common.gson.DoubleConverter;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
@@ -53,28 +51,44 @@
/**
* Gson object used to encode and decode messages.
*/
- @Getter(AccessLevel.PROTECTED)
- private static final Gson GSON;
+ private static final Gson GSON_STD;
/**
* Gson object used to encode messages in "pretty" format.
*/
- @Getter(AccessLevel.PROTECTED)
- private static final Gson GSON_PRETTY;
+ private static final Gson GSON_STD_PRETTY;
static {
GsonBuilder builder = GsonMessageBodyHandler.configBuilder(
new GsonBuilder().registerTypeAdapter(StandardCoderObject.class, new StandardTypeAdapter()));
- GSON = builder.create();
- GSON_PRETTY = builder.setPrettyPrinting().create();
+ GSON_STD = builder.create();
+ GSON_STD_PRETTY = builder.setPrettyPrinting().create();
}
/**
+ * Gson object used to encode and decode messages.
+ */
+ protected final Gson gson;
+
+ /**
+ * Gson object used to encode messages in "pretty" format.
+ */
+ protected final Gson gsonPretty;
+
+ /**
* Constructs the object.
*/
public StandardCoder() {
- super();
+ this(GSON_STD, GSON_STD_PRETTY);
+ }
+
+ /**
+ * Constructs the object.
+ */
+ protected StandardCoder(Gson gson, Gson gsonPretty) {
+ this.gson = gson;
+ this.gsonPretty = gsonPretty;
}
@Override
@@ -213,13 +227,13 @@
* @return the encoded object
*/
protected String toPrettyJson(Object object) {
- return GSON_PRETTY.toJson(object);
+ return gsonPretty.toJson(object);
}
@Override
public StandardCoderObject toStandard(Object object) throws CoderException {
try {
- return new StandardCoderObject(GSON.toJsonTree(object));
+ return new StandardCoderObject(gson.toJsonTree(object));
} catch (RuntimeException e) {
throw new CoderException(e);
@@ -229,7 +243,7 @@
@Override
public <T> T fromStandard(StandardCoderObject sco, Class<T> clazz) throws CoderException {
try {
- return GSON.fromJson(sco.getData(), clazz);
+ return gson.fromJson(sco.getData(), clazz);
} catch (RuntimeException e) {
throw new CoderException(e);
@@ -287,7 +301,7 @@
* @return a json element representing the object
*/
protected JsonElement toJsonTree(Object object) {
- return GSON.toJsonTree(object);
+ return gson.toJsonTree(object);
}
/**
@@ -297,7 +311,7 @@
* @return a json string representing the object
*/
protected String toJson(Object object) {
- return GSON.toJson(object);
+ return gson.toJson(object);
}
/**
@@ -307,7 +321,7 @@
* @param object object to be encoded
*/
protected void toJson(Writer target, Object object) {
- GSON.toJson(object, object.getClass(), target);
+ gson.toJson(object, object.getClass(), target);
}
/**
@@ -318,7 +332,7 @@
* @return the object represented by the given json element
*/
protected <T> T fromJson(JsonElement json, Class<T> clazz) {
- return convertFromDouble(clazz, GSON.fromJson(json, clazz));
+ return convertFromDouble(clazz, gson.fromJson(json, clazz));
}
/**
@@ -329,7 +343,7 @@
* @return the object represented by the given json string
*/
protected <T> T fromJson(String json, Class<T> clazz) {
- return convertFromDouble(clazz, GSON.fromJson(json, clazz));
+ return convertFromDouble(clazz, gson.fromJson(json, clazz));
}
/**
@@ -340,7 +354,7 @@
* @return the object represented by the given json string
*/
protected <T> T fromJson(Reader source, Class<T> clazz) {
- return convertFromDouble(clazz, GSON.fromJson(source, clazz));
+ return convertFromDouble(clazz, gson.fromJson(source, clazz));
}
/**
diff --git a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoderInstantAsMillis.java b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoderInstantAsMillis.java
index fbb53b9..27b239b 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoderInstantAsMillis.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoderInstantAsMillis.java
@@ -22,12 +22,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-import java.io.Reader;
-import java.io.Writer;
import java.time.Instant;
-import lombok.AccessLevel;
-import lombok.Getter;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.common.gson.InstantAsMillisTypeAdapter;
@@ -40,14 +35,12 @@
/**
* Gson object used to encode and decode messages.
*/
- @Getter(AccessLevel.PROTECTED)
- private static final Gson GSON;
+ private static final Gson GSON_INSTANT;
/**
* Gson object used to encode messages in "pretty" format.
*/
- @Getter(AccessLevel.PROTECTED)
- private static final Gson GSON_PRETTY;
+ private static final Gson GSON_INSTANT_PRETTY;
static {
GsonBuilder builder = GsonMessageBodyHandler
@@ -55,71 +48,14 @@
new StandardTypeAdapter()))
.registerTypeAdapter(Instant.class, new InstantAsMillisTypeAdapter());
- GSON = builder.create();
- GSON_PRETTY = builder.setPrettyPrinting().create();
+ GSON_INSTANT = builder.create();
+ GSON_INSTANT_PRETTY = builder.setPrettyPrinting().create();
}
/**
* Constructs the object.
*/
public StandardCoderInstantAsMillis() {
- super();
- }
-
- @Override
- protected String toPrettyJson(Object object) {
- return GSON_PRETTY.toJson(object);
- }
-
- @Override
- public StandardCoderObject toStandard(Object object) throws CoderException {
- try {
- return new StandardCoderObject(GSON.toJsonTree(object));
-
- } catch (RuntimeException e) {
- throw new CoderException(e);
- }
- }
-
- @Override
- public <T> T fromStandard(StandardCoderObject sco, Class<T> clazz) throws CoderException {
- try {
- return GSON.fromJson(sco.getData(), clazz);
-
- } catch (RuntimeException e) {
- throw new CoderException(e);
- }
- }
-
- // the remaining methods are wrappers that can be overridden by junit tests
-
- @Override
- protected JsonElement toJsonTree(Object object) {
- return GSON.toJsonTree(object);
- }
-
- @Override
- protected String toJson(Object object) {
- return GSON.toJson(object);
- }
-
- @Override
- protected void toJson(Writer target, Object object) {
- GSON.toJson(object, object.getClass(), target);
- }
-
- @Override
- protected <T> T fromJson(JsonElement json, Class<T> clazz) {
- return convertFromDouble(clazz, GSON.fromJson(json, clazz));
- }
-
- @Override
- protected <T> T fromJson(String json, Class<T> clazz) {
- return convertFromDouble(clazz, GSON.fromJson(json, clazz));
- }
-
- @Override
- protected <T> T fromJson(Reader source, Class<T> clazz) {
- return convertFromDouble(clazz, GSON.fromJson(source, clazz));
+ super(GSON_INSTANT, GSON_INSTANT_PRETTY);
}
}
diff --git a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoderObject.java b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoderObject.java
index 7f0f058..5d68263 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoderObject.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoderObject.java
@@ -35,7 +35,11 @@
/**
* Data wrapped by this.
*/
- private final JsonElement data;
+ /*
+ * this should not be transient, but since it isn't serializable, we're stuck with it
+ * until there's time to address the issue
+ */
+ private final transient JsonElement data;
/**
* Constructs the object.
diff --git a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardValCoder.java b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardValCoder.java
index 85505a9..647a615 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardValCoder.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardValCoder.java
@@ -65,7 +65,7 @@
* The validator strips off the "pretty" stuff (i.e., spaces), thus we have to validate and generate the pretty
* JSON in separate steps.
*/
- getGSON().toJson(object, object.getClass(), validatorApi.createJsonWriter(validator, new StringWriter()));
+ gson.toJson(object, object.getClass(), validatorApi.createJsonWriter(validator, new StringWriter()));
return super.toPrettyJson(object);
}
@@ -79,18 +79,18 @@
@Override
protected void toJson(@NonNull Writer target, @NonNull Object object) {
- getGSON().toJson(object, object.getClass(), validatorApi.createJsonWriter(validator, target));
+ gson.toJson(object, object.getClass(), validatorApi.createJsonWriter(validator, target));
}
@Override
protected <T> T fromJson(@NonNull Reader source, @NonNull Class<T> clazz) {
- return convertFromDouble(clazz, getGSON().fromJson(validatorApi.createJsonReader(validator, source), clazz));
+ return convertFromDouble(clazz, gson.fromJson(validatorApi.createJsonReader(validator, source), clazz));
}
@Override
protected <T> T fromJson(String json, Class<T> clazz) {
StringReader reader = new StringReader(json);
- return convertFromDouble(clazz, getGSON().fromJson(validatorApi.createJsonReader(validator, reader), clazz));
+ return convertFromDouble(clazz, gson.fromJson(validatorApi.createJsonReader(validator, reader), clazz));
}
/**
diff --git a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardYamlCoder.java b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardYamlCoder.java
index 1bcf6ac..c437596 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardYamlCoder.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardYamlCoder.java
@@ -34,7 +34,7 @@
* Constructs the object.
*/
public StandardYamlCoder() {
- translator = new YamlJsonTranslator(getGSON());
+ translator = new YamlJsonTranslator(gson);
}
@Override
diff --git a/utils/src/main/java/org/onap/policy/common/utils/resources/ResourceUtils.java b/utils/src/main/java/org/onap/policy/common/utils/resources/ResourceUtils.java
index 365efab..58e2baf 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/resources/ResourceUtils.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/resources/ResourceUtils.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@@ -100,7 +101,7 @@
resourceOutputStreamBuffer.write(resourceBuffer, 0, length);
}
} catch (final IOException e) {
- LOGGER.debug("error reading resource stream \"{}\" : " + e.getMessage(), resourceName, e);
+ LOGGER.debug("error reading resource stream {}", resourceName, e);
return null;
}
@@ -130,7 +131,7 @@
return urlToResource.openStream();
} catch (final IOException e) {
// Any of many IO exceptions such as the resource is a directory
- LOGGER.debug("error attaching resource \"{}\" to stream : " + e.getMessage(), resourceName, e);
+ LOGGER.debug("error attaching resource {}", resourceName, e);
return null;
}
}
@@ -164,7 +165,7 @@
return url;
}
} catch (final Exception e) {
- LOGGER.debug("error getting URL resource \"{}\" : " + e.getMessage(), e);
+ LOGGER.debug("error getting URL resource {}", resourceName, e);
return null;
}
}
@@ -199,7 +200,7 @@
return null;
}
} catch (final Exception e) {
- LOGGER.debug("error finding resource \"{}\" : " + e.getMessage(), e);
+ LOGGER.debug("error finding resource {}", resourceName, e);
return null;
}
}
@@ -288,6 +289,8 @@
*/
public static Set<String> getDirectoryContentsJar(final URL jarResourceDirectoryUrl,
final String resourceDirectoryName) {
+ String dirNameWithSlash = resourceDirectoryName + "/";
+ int minLength = dirNameWithSlash.length() + 1;
File jarResourceDirectory = new File(jarResourceDirectoryUrl.getPath());
String jarFileName = jarResourceDirectory.getParent().replaceFirst("^file:", "").replaceFirst("!.*$", "");
@@ -297,10 +300,14 @@
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
- JarEntry je = entries.nextElement();
+ /*
+ * Ignore sonar issue, as the entries are not being expanded here.
+ */
+ JarEntry je = entries.nextElement(); // NOSONAR
+ String jeName = je.getName();
- if (je.getName().matches("^" + resourceDirectoryName + "\\/.+")) {
- localDirectorySet.add(je.getName());
+ if (jeName.length() >= minLength && jeName.startsWith(dirNameWithSlash)) {
+ localDirectorySet.add(jeName);
}
}
} catch (IOException ioe) {
diff --git a/utils/src/main/java/org/onap/policy/common/utils/resources/TextFileUtils.java b/utils/src/main/java/org/onap/policy/common/utils/resources/TextFileUtils.java
index 01af7fd..c5b8c98 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/resources/TextFileUtils.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/resources/TextFileUtils.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@@ -25,6 +26,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
/**
@@ -34,7 +36,6 @@
* @author Liam Fallon (liam.fallon@est.tech)
*/
public abstract class TextFileUtils {
- private static final String UTF_8 = "UTF-8";
private static final int READER_CHAR_BUFFER_SIZE_4096 = 4096;
private TextFileUtils() {
@@ -50,7 +51,7 @@
*/
public static String getTextFileAsString(final String textFilePath) throws IOException {
final File textFile = new File(textFilePath);
- return new String(Files.readAllBytes(textFile.toPath()), UTF_8);
+ return Files.readString(textFile.toPath());
}
/**
@@ -77,7 +78,7 @@
* @throws IOException on errors reading text from the file
*/
public static void putStringAsFile(final String outString, final File textFile) throws IOException {
- Files.write(textFile.toPath(), outString.getBytes(UTF_8));
+ Files.writeString(textFile.toPath(), outString);
}
/**
@@ -88,7 +89,7 @@
* @throws IOException on errors reading text from the file
*/
public static String getStreamAsString(final InputStream textStream) throws IOException {
- return getReaderAsString(new InputStreamReader(textStream, UTF_8));
+ return getReaderAsString(new InputStreamReader(textStream, StandardCharsets.UTF_8));
}
/**
diff --git a/utils/src/main/java/org/onap/policy/common/utils/security/CryptoUtils.java b/utils/src/main/java/org/onap/policy/common/utils/security/CryptoUtils.java
index 416c73a..af5b3d4 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/security/CryptoUtils.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/security/CryptoUtils.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -62,9 +62,9 @@
/**
* Used to generate a random "iv". Strong randomness is not needed, as this is only
- * used as a "salt".
+ * used as a "salt". (Thus sonar is disabled.)
*/
- private static final Random RANDOM = new Random();
+ private static final Random RANDOM = new Random(); // NOSONAR
/**
* CryptoUtils - encryption tool constructor.
@@ -228,7 +228,7 @@
* The encrypted string or plain text value
* @return boolean value indicate if string prefix with enc: or not
*/
- public static Boolean isEncrypted(String value) {
+ public static boolean isEncrypted(String value) {
return (value != null && value.startsWith("enc:"));
}
diff --git a/utils/src/main/java/org/onap/policy/common/utils/services/ServiceManager.java b/utils/src/main/java/org/onap/policy/common/utils/services/ServiceManager.java
index 5c8c01d..78fe853 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/services/ServiceManager.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/services/ServiceManager.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -58,6 +58,7 @@
/**
* Constructs the object.
+ *
* @param name the manager's name, used for logging purposes
*/
public ServiceManager(String name) {
@@ -215,8 +216,13 @@
}
}
+ /*
+ * Cannot use a plain Runnable, because it can't throw exceptions. Could use a
+ * Callable, instead, but then all of the lambda expressions become rather messy, thus
+ * we'll stick with RunnableWithEx, and just disable the sonar warning.
+ */
@FunctionalInterface
public static interface RunnableWithEx {
- void run() throws Exception;
+ void run() throws Exception; // NOSONAR
}
}
diff --git a/utils/src/main/java/org/onap/policy/common/utils/validation/Version.java b/utils/src/main/java/org/onap/policy/common/utils/validation/Version.java
index 41ff832..efbf937 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/validation/Version.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/validation/Version.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP COMMON
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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");
@@ -21,8 +21,8 @@
package org.onap.policy.common.utils.validation;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import com.google.re2j.Matcher;
+import com.google.re2j.Pattern;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
diff --git a/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyAccessExceptionTest.java b/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyAccessExceptionTest.java
index 190fddd..27b0e85 100644
--- a/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyAccessExceptionTest.java
+++ b/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyAccessExceptionTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine - Common Modules
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 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.
* 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.
@@ -28,46 +28,46 @@
public class PropertyAccessExceptionTest extends SupportBasicPropertyExceptionTester {
/**
- * Test method for
+ * Test method for
* {@link org.onap.policy.common.utils.properties.exception.PropertyAccessException#PropertyAccessException
* (java.lang.String, java.lang.String)}.
*/
@Test
public void testPropertyAccessExceptionStringField() {
- doTestPropertyExceptionStringField_AllPopulated( new PropertyAccessException(PROPERTY, FIELD));
- doTestPropertyExceptionStringField_NullProperty( new PropertyAccessException(null, FIELD));
- doTestPropertyExceptionStringField_NullField( new PropertyAccessException(PROPERTY, null));
- doTestPropertyExceptionStringField_BothNull( new PropertyAccessException(null, null));
+ verifyPropertyExceptionStringField_AllPopulated( new PropertyAccessException(PROPERTY, FIELD));
+ verifyPropertyExceptionStringField_NullProperty( new PropertyAccessException(null, FIELD));
+ verifyPropertyExceptionStringField_NullField( new PropertyAccessException(PROPERTY, null));
+ verifyPropertyExceptionStringField_BothNull( new PropertyAccessException(null, null));
}
/**
- * Test method for
+ * Test method for
* {@link org.onap.policy.common.utils.properties.exception.PropertyAccessException#PropertyAccessException
* (java.lang.String, java.lang.String, java.lang.String)}.
*/
@Test
public void testPropertyAccessExceptionStringFieldString() {
- doTestPropertyExceptionStringFieldString(new PropertyAccessException(PROPERTY, FIELD, MESSAGE));
+ verifyPropertyExceptionStringFieldString(new PropertyAccessException(PROPERTY, FIELD, MESSAGE));
}
/**
- * Test method for
+ * Test method for
* {@link org.onap.policy.common.utils.properties.exception.PropertyAccessException#PropertyAccessException
* (java.lang.String, java.lang.String, java.lang.Throwable)}.
*/
@Test
public void testPropertyAccessExceptionStringFieldThrowable() {
- doTestPropertyExceptionStringFieldThrowable(new PropertyAccessException(PROPERTY, FIELD, THROWABLE));
+ verifyPropertyExceptionStringFieldThrowable(new PropertyAccessException(PROPERTY, FIELD, THROWABLE));
}
/**
- * Test method for
+ * Test method for
* {@link org.onap.policy.common.utils.properties.exception.PropertyAccessException#PropertyAccessException
* (java.lang.String, java.lang.String, java.lang.String, java.lang.Throwable)}.
*/
@Test
public void testPropertyAccessExceptionStringFieldStringThrowable() {
- doTestPropertyExceptionStringFieldStringThrowable(
+ verifyPropertyExceptionStringFieldStringThrowable(
new PropertyAccessException(PROPERTY, FIELD, MESSAGE, THROWABLE));
}
diff --git a/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyAnnotationExceptionTest.java b/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyAnnotationExceptionTest.java
index c480391..9187976 100644
--- a/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyAnnotationExceptionTest.java
+++ b/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyAnnotationExceptionTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine - Common Modules
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 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.
* 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.
@@ -34,10 +34,10 @@
*/
@Test
public void testPropertyExceptionStringField() {
- doTestPropertyExceptionStringField_AllPopulated(new PropertyAnnotationException(PROPERTY, FIELD));
- doTestPropertyExceptionStringField_NullProperty(new PropertyAnnotationException(null, FIELD));
- doTestPropertyExceptionStringField_NullField(new PropertyAnnotationException(PROPERTY, null));
- doTestPropertyExceptionStringField_BothNull(new PropertyAnnotationException(null, null));
+ verifyPropertyExceptionStringField_AllPopulated(new PropertyAnnotationException(PROPERTY, FIELD));
+ verifyPropertyExceptionStringField_NullProperty(new PropertyAnnotationException(null, FIELD));
+ verifyPropertyExceptionStringField_NullField(new PropertyAnnotationException(PROPERTY, null));
+ verifyPropertyExceptionStringField_BothNull(new PropertyAnnotationException(null, null));
}
/**
@@ -47,7 +47,7 @@
*/
@Test
public void testPropertyExceptionStringFieldString() {
- doTestPropertyExceptionStringFieldString(new PropertyAnnotationException(PROPERTY, FIELD, MESSAGE));
+ verifyPropertyExceptionStringFieldString(new PropertyAnnotationException(PROPERTY, FIELD, MESSAGE));
}
/**
@@ -57,7 +57,7 @@
*/
@Test
public void testPropertyExceptionStringFieldThrowable() {
- doTestPropertyExceptionStringFieldThrowable(new PropertyAnnotationException(PROPERTY, FIELD, THROWABLE));
+ verifyPropertyExceptionStringFieldThrowable(new PropertyAnnotationException(PROPERTY, FIELD, THROWABLE));
}
/**
@@ -67,7 +67,7 @@
*/
@Test
public void testPropertyExceptionStringFieldStringThrowable() {
- doTestPropertyExceptionStringFieldStringThrowable(
+ verifyPropertyExceptionStringFieldStringThrowable(
new PropertyAnnotationException(PROPERTY, FIELD, MESSAGE, THROWABLE));
}
diff --git a/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyExceptionTest.java b/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyExceptionTest.java
index 9055aeb..9166749 100644
--- a/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyExceptionTest.java
+++ b/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyExceptionTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine - Common Modules
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 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.
* 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.
@@ -34,10 +34,10 @@
*/
@Test
public void testPropertyExceptionStringField() {
- doTestPropertyExceptionStringField_AllPopulated(new PropertyException(PROPERTY, FIELD));
- doTestPropertyExceptionStringField_NullProperty(new PropertyException(null, FIELD));
- doTestPropertyExceptionStringField_NullField(new PropertyException(PROPERTY, null));
- doTestPropertyExceptionStringField_BothNull(new PropertyException(null, null));
+ verifyPropertyExceptionStringField_AllPopulated(new PropertyException(PROPERTY, FIELD));
+ verifyPropertyExceptionStringField_NullProperty(new PropertyException(null, FIELD));
+ verifyPropertyExceptionStringField_NullField(new PropertyException(PROPERTY, null));
+ verifyPropertyExceptionStringField_BothNull(new PropertyException(null, null));
}
/**
@@ -47,7 +47,7 @@
*/
@Test
public void testPropertyExceptionStringFieldString() {
- doTestPropertyExceptionStringFieldString(new PropertyException(PROPERTY, FIELD, MESSAGE));
+ verifyPropertyExceptionStringFieldString(new PropertyException(PROPERTY, FIELD, MESSAGE));
}
/**
@@ -57,7 +57,7 @@
*/
@Test
public void testPropertyExceptionStringFieldThrowable() {
- doTestPropertyExceptionStringFieldThrowable(new PropertyException(PROPERTY, FIELD, THROWABLE));
+ verifyPropertyExceptionStringFieldThrowable(new PropertyException(PROPERTY, FIELD, THROWABLE));
}
/**
@@ -67,7 +67,7 @@
*/
@Test
public void testPropertyExceptionStringFieldStringThrowable() {
- doTestPropertyExceptionStringFieldStringThrowable(new PropertyException(PROPERTY, FIELD, MESSAGE, THROWABLE));
+ verifyPropertyExceptionStringFieldStringThrowable(new PropertyException(PROPERTY, FIELD, MESSAGE, THROWABLE));
}
}
diff --git a/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyInvalidExceptionTest.java b/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyInvalidExceptionTest.java
index 69ab1bd..3edd7ff 100644
--- a/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyInvalidExceptionTest.java
+++ b/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyInvalidExceptionTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine - Common Modules
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 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.
* 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.
@@ -34,10 +34,10 @@
*/
@Test
public void testPropertyExceptionStringField() {
- doTestPropertyExceptionStringField_AllPopulated(new PropertyInvalidException(PROPERTY, FIELD));
- doTestPropertyExceptionStringField_NullProperty(new PropertyInvalidException(null, FIELD));
- doTestPropertyExceptionStringField_NullField(new PropertyInvalidException(PROPERTY, null));
- doTestPropertyExceptionStringField_BothNull(new PropertyInvalidException(null, null));
+ verifyPropertyExceptionStringField_AllPopulated(new PropertyInvalidException(PROPERTY, FIELD));
+ verifyPropertyExceptionStringField_NullProperty(new PropertyInvalidException(null, FIELD));
+ verifyPropertyExceptionStringField_NullField(new PropertyInvalidException(PROPERTY, null));
+ verifyPropertyExceptionStringField_BothNull(new PropertyInvalidException(null, null));
}
/**
@@ -47,7 +47,7 @@
*/
@Test
public void testPropertyExceptionStringFieldString() {
- doTestPropertyExceptionStringFieldString(new PropertyInvalidException(PROPERTY, FIELD, MESSAGE));
+ verifyPropertyExceptionStringFieldString(new PropertyInvalidException(PROPERTY, FIELD, MESSAGE));
}
/**
@@ -57,7 +57,7 @@
*/
@Test
public void testPropertyExceptionStringFieldThrowable() {
- doTestPropertyExceptionStringFieldThrowable(new PropertyInvalidException(PROPERTY, FIELD, THROWABLE));
+ verifyPropertyExceptionStringFieldThrowable(new PropertyInvalidException(PROPERTY, FIELD, THROWABLE));
}
/**
@@ -67,7 +67,7 @@
*/
@Test
public void testPropertyExceptionStringFieldStringThrowable() {
- doTestPropertyExceptionStringFieldStringThrowable(
+ verifyPropertyExceptionStringFieldStringThrowable(
new PropertyInvalidException(PROPERTY, FIELD, MESSAGE, THROWABLE));
}
diff --git a/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyMissingExceptionTest.java b/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyMissingExceptionTest.java
index 81a7c36..948bc18 100644
--- a/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyMissingExceptionTest.java
+++ b/utils/src/test/java/org/onap/policy/common/utils/properties/exception/PropertyMissingExceptionTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine - Common Modules
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 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.
* 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.
@@ -34,10 +34,10 @@
*/
@Test
public void testPropertyExceptionStringField() {
- doTestPropertyExceptionStringField_AllPopulated(new PropertyMissingException(PROPERTY, FIELD));
- doTestPropertyExceptionStringField_NullProperty(new PropertyMissingException(null, FIELD));
- doTestPropertyExceptionStringField_NullField(new PropertyMissingException(PROPERTY, null));
- doTestPropertyExceptionStringField_BothNull(new PropertyMissingException(null, null));
+ verifyPropertyExceptionStringField_AllPopulated(new PropertyMissingException(PROPERTY, FIELD));
+ verifyPropertyExceptionStringField_NullProperty(new PropertyMissingException(null, FIELD));
+ verifyPropertyExceptionStringField_NullField(new PropertyMissingException(PROPERTY, null));
+ verifyPropertyExceptionStringField_BothNull(new PropertyMissingException(null, null));
}
}
diff --git a/utils/src/test/java/org/onap/policy/common/utils/properties/exception/SupportBasicPropertyExceptionTester.java b/utils/src/test/java/org/onap/policy/common/utils/properties/exception/SupportBasicPropertyExceptionTester.java
index f584292..be3f818 100644
--- a/utils/src/test/java/org/onap/policy/common/utils/properties/exception/SupportBasicPropertyExceptionTester.java
+++ b/utils/src/test/java/org/onap/policy/common/utils/properties/exception/SupportBasicPropertyExceptionTester.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine - Common Modules
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 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.
@@ -53,42 +53,42 @@
* Methods to perform various tests on the except subclass.
*/
- protected void doTestPropertyExceptionStringField_AllPopulated(PropertyException ex) {
+ protected void verifyPropertyExceptionStringField_AllPopulated(PropertyException ex) {
standardTests(ex);
}
- protected void doTestPropertyExceptionStringField_NullProperty(PropertyException ex) {
+ protected void verifyPropertyExceptionStringField_NullProperty(PropertyException ex) {
assertEquals(null, ex.getPropertyName());
assertEquals(FIELD, ex.getFieldName());
assertNotNull(ex.getMessage());
assertNotNull(ex.toString());
}
- protected void doTestPropertyExceptionStringField_NullField(PropertyException ex) {
+ protected void verifyPropertyExceptionStringField_NullField(PropertyException ex) {
assertEquals(PROPERTY, ex.getPropertyName());
assertEquals(null, ex.getFieldName());
assertNotNull(ex.getMessage());
assertNotNull(ex.toString());
}
- protected void doTestPropertyExceptionStringField_BothNull(PropertyException ex) {
+ protected void verifyPropertyExceptionStringField_BothNull(PropertyException ex) {
assertEquals(null, ex.getPropertyName());
assertEquals(null, ex.getFieldName());
assertNotNull(ex.getMessage());
assertNotNull(ex.toString());
}
- protected void doTestPropertyExceptionStringFieldString(PropertyException ex) {
+ protected void verifyPropertyExceptionStringFieldString(PropertyException ex) {
standardTests(ex);
standardMessageTests(ex);
}
- protected void doTestPropertyExceptionStringFieldThrowable(PropertyException ex) {
+ protected void verifyPropertyExceptionStringFieldThrowable(PropertyException ex) {
standardTests(ex);
standardThrowableTests(ex);
}
- protected void doTestPropertyExceptionStringFieldStringThrowable(PropertyException ex) {
+ protected void verifyPropertyExceptionStringFieldStringThrowable(PropertyException ex) {
standardTests(ex);
standardMessageTests(ex);
standardThrowableTests(ex);