summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2020-06-02 15:11:57 +0000
committerGerrit Code Review <gerrit@onap.org>2020-06-02 15:11:57 +0000
commitebff4ef04bbd786ced77b121420ce23b8a6f0a7c (patch)
treea1bd88fd4c6f5d9bd1d05c0a350824877eff2fa1
parentfc70cd22f3557540f76559c794a1516785e56151 (diff)
parentfef8fc7996990a2bf1e25c10c4e4d41412e2802d (diff)
Merge "Sonar fixes"
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAuditService.java15
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AbstractAuditServiceTest.java52
2 files changed, 60 insertions, 7 deletions
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAuditService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAuditService.java
index 2f7155bffc..96a0ddc328 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAuditService.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAuditService.java
@@ -21,7 +21,6 @@
package org.onap.so.adapters.tasks.audit;
-import java.util.Optional;
import org.onap.so.objects.audit.AAIObjectAudit;
import org.onap.so.objects.audit.AAIObjectAuditList;
import org.onap.so.utils.ExternalTaskUtils;
@@ -31,14 +30,13 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
+import java.util.Optional;
@Component
public abstract class AbstractAuditService extends ExternalTaskUtils {
private static final Logger logger = LoggerFactory.getLogger(AbstractAuditService.class);
-
-
protected static final String UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI =
"Unable to find all VServers and L-Interaces in A&AI";
@@ -52,12 +50,11 @@ public abstract class AbstractAuditService extends ExternalTaskUtils {
}
/**
- * @param auditHeatStackFailed
* @param auditList
* @return
*/
protected boolean didCreateAuditFail(Optional<AAIObjectAuditList> auditList) {
- if (auditList.get().getAuditList() != null && !auditList.get().getAuditList().isEmpty()) {
+ if (auditList.isPresent() && isAuditListNotNullAndNotEmpty(auditList.get())) {
if (logger.isInfoEnabled()) {
logger.info("Audit Results: {}", auditList.get().toString());
}
@@ -69,12 +66,11 @@ public abstract class AbstractAuditService extends ExternalTaskUtils {
}
/**
- * @param auditHeatStackFailed
* @param auditList
* @return
*/
protected boolean didDeleteAuditFail(AAIObjectAuditList auditList) {
- if (auditList.getAuditList() != null && !auditList.getAuditList().isEmpty()) {
+ if (isAuditListNotNullAndNotEmpty(auditList)) {
if (logger.isInfoEnabled()) {
logger.info("Audit Results: {}", auditList.toString());
}
@@ -84,4 +80,9 @@ public abstract class AbstractAuditService extends ExternalTaskUtils {
return false;
}
}
+
+ private boolean isAuditListNotNullAndNotEmpty(AAIObjectAuditList auditList) {
+ return auditList != null && auditList.getAuditList() != null && !auditList.getAuditList().isEmpty();
+ }
+
}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AbstractAuditServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AbstractAuditServiceTest.java
new file mode 100644
index 0000000000..a93897f83e
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AbstractAuditServiceTest.java
@@ -0,0 +1,52 @@
+package org.onap.so.adapters.tasks.audit;
+
+import org.junit.Test;
+import org.onap.so.objects.audit.AAIObjectAudit;
+import org.onap.so.objects.audit.AAIObjectAuditList;
+import java.util.Optional;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class AbstractAuditServiceTest extends AbstractAuditService {
+
+ private AAIObjectAuditList getAuditListWithObjectWithExistenceStateOf(boolean existState) {
+ AAIObjectAudit auditObject = new AAIObjectAudit();
+ AAIObjectAuditList auditList = new AAIObjectAuditList();
+
+ auditObject.setDoesObjectExist(existState);
+ auditList.getAuditList().add(auditObject);
+
+ return auditList;
+ }
+
+ @Test
+ public void didCreateAuditFail_shouldReturnFalse_whenGivenEmptyAudit() {
+ assertFalse(didCreateAuditFail(Optional.empty()));
+ }
+
+ @Test
+ public void didCreateAuditFail_shouldReturnTrue_whenGivenNotExistingObject() {
+ assertTrue(didCreateAuditFail(Optional.of(getAuditListWithObjectWithExistenceStateOf(false))));
+ }
+
+ @Test
+ public void didCreateAuditFail_shouldReturnFalse_whenGivenExistingObject() {
+ assertFalse(didCreateAuditFail(Optional.of(getAuditListWithObjectWithExistenceStateOf(true))));
+ }
+
+ @Test
+ public void didDeleteAuditFail_shouldReturnFalse_whenGivenNull() {
+ assertFalse(didDeleteAuditFail(null));
+ }
+
+ @Test
+ public void didDeleteAuditFail_shouldReturnTrue_whenGivenExistingObject() {
+ assertTrue(didDeleteAuditFail(getAuditListWithObjectWithExistenceStateOf(true)));
+ }
+
+ @Test
+ public void didDeleteAuditFail_shouldReturnFalse_whenGivenNotExistingObject() {
+ assertFalse(didDeleteAuditFail(getAuditListWithObjectWithExistenceStateOf(false)));
+ }
+
+}