summaryrefslogtreecommitdiffstats
path: root/controlloop/common/model-impl/aai/src
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/model-impl/aai/src')
-rw-r--r--controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java23
-rw-r--r--controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java13
2 files changed, 12 insertions, 24 deletions
diff --git a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java
index be84fdfa8..eb4271b5c 100644
--- a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java
+++ b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java
@@ -22,6 +22,7 @@ package org.onap.policy.aai;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
@@ -68,8 +69,7 @@ public class AaiNqResponseWrapper implements Serializable {
* @return the number of VF modules, or {@code 0} if there are none
*/
public int countVfModules() {
- List<AaiNqInventoryResponseItem> lst = getVfModuleItems(false);
- return (lst == null ? 0 : lst.size());
+ return getVfModuleItems(false).size();
}
/**
@@ -80,11 +80,6 @@ public class AaiNqResponseWrapper implements Serializable {
* which to model it)
*/
public String genVfModuleName() {
- List<AaiNqInventoryResponseItem> lst = getVfModuleItems(false);
- if (lst == null) {
- return null;
- }
-
/*
* Loop through the VF modules, extracting the name prefix and the largest number
* suffix
@@ -92,7 +87,7 @@ public class AaiNqResponseWrapper implements Serializable {
String prefix = null;
int maxSuffix = -1;
- for (AaiNqInventoryResponseItem item : lst) {
+ for (AaiNqInventoryResponseItem item : getVfModuleItems(false)) {
String name = item.getVfModule().getVfModuleName();
Matcher matcher = VF_MODULE_NAME_PAT.matcher(name);
if (matcher.matches()) {
@@ -116,7 +111,7 @@ public class AaiNqResponseWrapper implements Serializable {
*
* @param wantBaseModule {@code true} if the the base VF module(s) is desired,
* {@code false} otherwise
- * @return the list of VF module items, or {@code null} if there are no VF modules
+ * @return the list of VF module items
*/
public List<AaiNqInventoryResponseItem> getVfModuleItems(boolean wantBaseModule) {
// get the list of items
@@ -127,18 +122,18 @@ public class AaiNqResponseWrapper implements Serializable {
} catch (NullPointerException | IndexOutOfBoundsException e) {
logger.debug("no VF modules in AAI response", e);
- return null;
+ return Collections.emptyList();
}
if (itemList == null) {
- return null;
+ return Collections.emptyList();
}
/*
* Walk the items looking for VF modules, allocating the list only when an item is
* found.
*/
- List<AaiNqInventoryResponseItem> vfModuleItems = null;
+ List<AaiNqInventoryResponseItem> vfModuleItems = new ArrayList<>(itemList.size());;
for (AaiNqInventoryResponseItem inventoryResponseItem : itemList) {
AaiNqVfModule vfmod = inventoryResponseItem.getVfModule();
@@ -146,10 +141,6 @@ public class AaiNqResponseWrapper implements Serializable {
continue;
}
- if (vfModuleItems == null) {
- vfModuleItems = new ArrayList<>(itemList.size());
- }
-
if (vfmod.getIsBaseVfModule() == wantBaseModule
&& (wantBaseModule || VF_MODULE_NAME_PAT.matcher(vfmod.getVfModuleName()).matches())) {
vfModuleItems.add(inventoryResponseItem);
diff --git a/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java b/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java
index 9acaa117c..d1e8e964e 100644
--- a/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java
+++ b/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java
@@ -22,7 +22,7 @@ package org.onap.policy.aai;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -207,41 +207,38 @@ public class AaiNqResponseWrapperTest {
// null item
resp = new AaiNqResponseWrapper();
- assertNull(resp.getVfModuleItems(true));
+ assertTrue(resp.getVfModuleItems(true).isEmpty());
// missing item
resp = new AaiNqResponseWrapper();
resp.setAaiNqResponse(new AaiNqResponse());
- assertNull(resp.getVfModuleItems(false));
+ assertTrue(resp.getVfModuleItems(false).isEmpty());
// null item list
resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoItems.json"));
resp.getAaiNqResponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems().get(0)
.getItems().setInventoryResponseItems(null);
- assertNull(resp.getVfModuleItems(false));
+ assertTrue(resp.getVfModuleItems(false).isEmpty());
// no modules
resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoModules.json"));
- assertNull(resp.getVfModuleItems(false));
+ assertTrue(resp.getVfModuleItems(false).isEmpty());
// no names
resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoNames.json"));
List<AaiNqInventoryResponseItem> lst;
lst = resp.getVfModuleItems(false);
- assertNotNull(lst);
assertEquals(0, lst.size());
// base VF modules
resp.setAaiNqResponse(load("AaiNqResponseWrapper-Vserver.json"));
lst = resp.getVfModuleItems(true);
- assertNotNull(lst);
assertEquals(1, lst.size());
assertEquals("Vfmodule_vLBMS-0809-1", lst.get(0).getVfModule().getVfModuleName());
// non base VF modules
resp.setAaiNqResponse(load("AaiNqResponseWrapper-Vserver.json"));
lst = resp.getVfModuleItems(false);
- assertNotNull(lst);
assertEquals(3, lst.size());
int index;
index = 0;