summaryrefslogtreecommitdiffstats
path: root/integrity-audit/src/main/java/org/onap
diff options
context:
space:
mode:
authorTemoc Rodriguez <cr056n@att.com>2017-12-04 11:39:54 -0800
committerTemoc Rodriguez <cr056n@att.com>2017-12-04 11:43:32 -0800
commitd0099f039b0dbf8f14ec2d273290a7c8ff58cb1c (patch)
tree516b0b00d0656314b795439694b391084c639c3e /integrity-audit/src/main/java/org/onap
parent4cd4924f682afe455db9a6416b7513fb9eafbfe0 (diff)
Fix bug where paramsAreBad doesn't update string
Replaced the string parameter with a StringBuilder so that the modified version can be accessed outside the method, since strings are immutable. Added null check for properties. Removed trim on properties in case the property is null. Added junit to test that the modified StringBuilder can be read outside the paramsAreBad method. Issue-ID: POLICY-492 Change-Id: I0550e9d639cbbcc876e6aafb84f6e9a363b653ff Signed-off-by: Temoc Rodriguez <cr056n@att.com>
Diffstat (limited to 'integrity-audit/src/main/java/org/onap')
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java2
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java109
2 files changed, 59 insertions, 52 deletions
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java
index db633400..99503854 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java
@@ -95,7 +95,7 @@ public class DbDAO {
* @throws IntegrityAuditPropertiesException
*/
private void validateProperties(String resourceName, String persistenceUnit, Properties properties) throws IntegrityAuditPropertiesException{
- String badparams="";
+ StringBuilder badparams= new StringBuilder();
if(IntegrityAudit.parmsAreBad(resourceName, persistenceUnit, properties, badparams)){
String msg = "DbDAO: Bad parameters: badparams" + badparams;
throw new IntegrityAuditPropertiesException(msg);
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java
index 50fc6932..424e603d 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java
@@ -67,7 +67,7 @@ public class IntegrityAudit {
public IntegrityAudit(String resourceName, String persistenceUnit, Properties properties) throws IntegrityAuditException {
logger.info("Constructor: Entering and checking for nulls");
- String parmList = "";
+ StringBuilder parmList = new StringBuilder();
if (parmsAreBad(resourceName, persistenceUnit, properties, parmList)) {
logger.error("Constructor: Parms contain nulls; cannot run audit for resourceName="
+ resourceName + ", persistenceUnit=" + persistenceUnit
@@ -117,73 +117,80 @@ public class IntegrityAudit {
* Makes sure we don't try to run the audit with bad parameters.
*/
public static boolean parmsAreBad(String resourceName, String persistenceUnit,
- Properties properties, String badparams) {
+ Properties properties, StringBuilder badparams) {
boolean parmsAreBad = false;
if(resourceName == null || resourceName.isEmpty()){
- badparams = badparams.concat("resourceName ");
+ badparams = badparams.append("resourceName ");
parmsAreBad = true;
}
if(persistenceUnit == null || persistenceUnit.isEmpty()){
- badparams = badparams.concat("persistenceUnit ");
+ badparams = badparams.append("persistenceUnit ");
parmsAreBad = true;
}
- String dbDriver = properties.getProperty(IntegrityAuditProperties.DB_DRIVER).trim();
- if(dbDriver == null || dbDriver.isEmpty()){
- badparams = badparams.concat("dbDriver ");
+ if(properties == null || properties.isEmpty()){
+ badparams = badparams.append("properties ");
parmsAreBad = true;
}
-
- String dbUrl = properties.getProperty(IntegrityAuditProperties.DB_URL).trim();
- if(dbUrl == null || dbUrl.isEmpty()){
- badparams = badparams.concat("dbUrl ");
- parmsAreBad = true;
- }
-
- String dbUser = properties.getProperty(IntegrityAuditProperties.DB_USER).trim();
- if(dbUser == null || dbUser.isEmpty()){
- badparams = badparams.concat("dbUser ");
- parmsAreBad = true;
- }
-
- String dbPwd = properties.getProperty(IntegrityAuditProperties.DB_PWD).trim();
- if(dbPwd == null){ //may be empty
- badparams = badparams.concat("dbPwd ");
- parmsAreBad = true;
- }
-
- String siteName = properties.getProperty(IntegrityAuditProperties.SITE_NAME).trim();
- if(siteName == null || siteName.isEmpty()){
- badparams = badparams.concat("siteName ");
- parmsAreBad = true;
- }
-
- String nodeType = properties.getProperty(IntegrityAuditProperties.NODE_TYPE).trim();
- if(nodeType == null || nodeType.isEmpty()){
- badparams = badparams.concat("nodeType ");
- parmsAreBad = true;
- } else {
- if (!isNodeTypeEnum(nodeType)) {
- String nodetypes = "nodeType must be one of[";
- for (NodeTypeEnum n : NodeTypeEnum.values()) {
- nodetypes = nodetypes.concat(n.toString() + " ");
- }
- badparams = badparams.concat(nodetypes + "] ");
+ else{
+ String dbDriver = properties.getProperty(IntegrityAuditProperties.DB_DRIVER);
+ if(dbDriver == null || dbDriver.isEmpty()){
+ badparams = badparams.append("dbDriver ");
parmsAreBad = true;
}
- }
- if(properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS) != null){ //It is allowed to be null
- try{
- Integer.parseInt(properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS).trim());
- }catch(NumberFormatException nfe){
- badparams = badparams.concat(", auditPeriodSeconds="
- + properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS).trim());
+
+ String dbUrl = properties.getProperty(IntegrityAuditProperties.DB_URL);
+ if(dbUrl == null || dbUrl.isEmpty()){
+ badparams = badparams.append("dbUrl ");
parmsAreBad = true;
}
- }
+
+ String dbUser = properties.getProperty(IntegrityAuditProperties.DB_USER);
+ if(dbUser == null || dbUser.isEmpty()){
+ badparams = badparams.append("dbUser ");
+ parmsAreBad = true;
+ }
+
+ String dbPwd = properties.getProperty(IntegrityAuditProperties.DB_PWD);
+ if(dbPwd == null){ //may be empty
+ badparams = badparams.append("dbPwd ");
+ parmsAreBad = true;
+ }
+
+ String siteName = properties.getProperty(IntegrityAuditProperties.SITE_NAME);
+ if(siteName == null || siteName.isEmpty()){
+ badparams = badparams.append("siteName ");
+ parmsAreBad = true;
+ }
+
+ String nodeType = properties.getProperty(IntegrityAuditProperties.NODE_TYPE);
+ if(nodeType == null || nodeType.isEmpty()){
+ badparams = badparams.append("nodeType ");
+ parmsAreBad = true;
+ } else {
+ nodeType = nodeType.trim();
+ if (!isNodeTypeEnum(nodeType)) {
+ String nodetypes = "nodeType must be one of[";
+ for (NodeTypeEnum n : NodeTypeEnum.values()) {
+ nodetypes = nodetypes.concat(n.toString() + " ");
+ }
+ badparams = badparams.append(nodetypes + "] ");
+ parmsAreBad = true;
+ }
+ }
+ if(properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS) != null){ //It is allowed to be null
+ try{
+ Integer.parseInt(properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS).trim());
+ }catch(NumberFormatException nfe){
+ badparams = badparams.append(", auditPeriodSeconds="
+ + properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS).trim());
+ parmsAreBad = true;
+ }
+ }
+ } // End else
logger.debug("parmsAreBad: exit:"
+ "\nresourceName: " + resourceName
+ "\npersistenceUnit: " + persistenceUnit