summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-02-21 18:24:20 +0000
committerTakamune Cho <takamune.cho@att.com>2019-02-22 19:37:17 +0000
commit3cef43b0cf7244d26aab5d9752fde518f0970d47 (patch)
tree9d1f06b09b9db803b5b58fb909a7fc2f21fc8b2e
parent57293e84a0aa7405c9688448483d811d707e199a (diff)
Test coverage in ExecuteNodeActionImpl
Increase coverage from 42% to 92% Issue-ID: APPC-1477 Change-Id: Ic9ef407663d0a79ccec8ed7045230c4d734a3cc4 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
-rw-r--r--appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java18
-rw-r--r--appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java52
2 files changed, 62 insertions, 8 deletions
diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java
index 33b9866db..4f517d211 100644
--- a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java
+++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java
@@ -10,6 +10,8 @@
* ================================================================================
* Modifications Copyright (C) 2018 IBM.
* ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
+ * ================================================================================
* 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
@@ -47,7 +49,6 @@ import com.att.eelf.i18n.EELFResourceManager;
public class ExecuteNodeActionImpl implements ExecuteNodeAction {
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(ExecuteNodeActionImpl.class);
private static final String RESOURCE_TYPE_PARAM = "resourceType";
private static final String RESOURCE_KEY_PARAM = "resourceKey";
private static final String PREFIX_PARAM = "prefix";
@@ -62,6 +63,7 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
private static final String ERROR_RETRIEVING_VNFC_HIERARCHY_PARAM = "Error Retrieving VNFC hierarchy";
private static final String RELATED_TO_PROPERTY_LEN_PARAM = "related-to-property_length";
public static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message";
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ExecuteNodeActionImpl.class);
private static Map<String, String> vnfHierarchyMap = new ConcurrentHashMap<>();
private static Map<String, Set<String>> vnfcHierarchyMap = new HashMap<>();
@@ -90,7 +92,8 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
logger.info("DG waits for " + Long.parseLong(waitTime) + " milliseconds completed");
} catch (InterruptedException e) {
logger.error("Error In ExecuteNodeActionImpl for waitMethod() due to InterruptedException: reason = "
- + e.getMessage());
+ + e.getMessage(), e);
+ Thread.currentThread().interrupt();
}
}
@@ -101,7 +104,7 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
String resourceKey = params.get(RESOURCE_KEY_PARAM);
if (logger.isDebugEnabled()) {
- logger.debug("inside getResorce");
+ logger.debug("inside getResource");
logger.debug("Retrieving " + resourceType + " details from A&AI for Key : " + resourceKey);
}
@@ -190,6 +193,7 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
// and tenant-id
String key = vnfCtx.getAttribute(vmKey + RELATIONSHIP_DATA_STR + j + "].relationship-key");
String value = vnfCtx.getAttribute(vmKey + RELATIONSHIP_DATA_STR + j + "].relationship-value");
+
vnfHierarchyMap.put(VNFF_VM_STR + vmCount + "]." + key, value);
if ("vserver.vserver-id".equals(key)) {
vserverID = value;
@@ -223,7 +227,7 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
paramsVm.put(RESOURCE_TYPE_PARAM, "vserver");
paramsVm.put(PREFIX_PARAM, "vmRetrived");
paramsVm.put(RESOURCE_KEY_PARAM, vmRetrivalKey);
- SvcLogicContext vmCtx = new SvcLogicContext();
+ SvcLogicContext vmCtx = getSvcLogicContext();
logger.debug("Retrieving VM details from A&AI");
getResource(paramsVm, vmCtx);
@@ -294,7 +298,7 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
paramsVnf.put(RESOURCE_KEY_PARAM, retrivalVnfKey);
logger.debug("Retrieving VNF details from A&AI");
// Retrive all the relations of VNF
- SvcLogicContext vnfCtx = new SvcLogicContext();
+ SvcLogicContext vnfCtx = getSvcLogicContext();
getResource(paramsVnf, vnfCtx);
if (vnfCtx.getAttribute(GET_RESOURCE_RESULT).equals(SUCCESS_PARAM)) {
trySetHeatStackIDAttribute(ctx, vnfCtx);
@@ -389,4 +393,8 @@ public class ExecuteNodeActionImpl implements ExecuteNodeAction {
vnfcCounter++;
}
}
+
+ protected SvcLogicContext getSvcLogicContext() {
+ return new SvcLogicContext();
+ }
}
diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java
index c6104297b..2e616eef4 100644
--- a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java
+++ b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java
@@ -8,6 +8,8 @@
* ================================================================================
* Modifications Copyright (C) 2018 Nokia
* ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
+ * ================================================================================
* 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
@@ -41,6 +43,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -52,6 +55,10 @@ import org.onap.ccsdk.sli.adaptors.aai.AAIService;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import org.powermock.reflect.Whitebox;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.configuration.EELFLogger.Level;
@RunWith(MockitoJUnitRunner.class)
public class ExecuteNodeActionImplTest {
@@ -65,6 +72,9 @@ public class ExecuteNodeActionImplTest {
private static final SvcLogicContext SVC_LOGIC_CONTEXT = new SvcLogicContext();
private static final SvcLogicResource.QueryStatus SUCCESS_STATUS = SvcLogicResource.QueryStatus.SUCCESS;
private static final QueryStatus FAILED_STATUS = SvcLogicResource.QueryStatus.FAILURE;
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(ExecuteNodeActionImpl.class);
+ private static EELFLogger.Level originalLoggerLevel;
+
@Mock
private AAIServiceFactory aaiServiceFactory;
@@ -83,6 +93,8 @@ public class ExecuteNodeActionImplTest {
params.put("attributeName", attributeName);
params.put("attributeValue", attributeValue);
params.put("waitTime", "1");
+ originalLoggerLevel = logger.isDebugEnabled() ? Level.DEBUG : Level.INFO;
+ logger.setLevel(Level.DEBUG);
}
@Test
@@ -127,11 +139,14 @@ public class ExecuteNodeActionImplTest {
@Test
public void testGetVnfHierarchySuccess() throws Exception {
+ ExecuteNodeActionImpl executeNodeActionSpy = Mockito.spy(executeNodeAction);
given(aaiService.query(any(), Mockito.anyBoolean(),
any(), any(), any(), any(),
any(SvcLogicContext.class))).willReturn(SUCCESS_STATUS);
-
- executeNodeAction.getVnfHierarchy(params, SVC_LOGIC_CONTEXT);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(("vnfRetrived.heat-stack-id"), "TEST");
+ Mockito.when(executeNodeActionSpy.getSvcLogicContext()).thenReturn(ctx);
+ executeNodeActionSpy.getVnfHierarchy(params, SVC_LOGIC_CONTEXT);
assertEquals("0", SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFCCount"));
assertEquals("SUCCESS", SVC_LOGIC_CONTEXT.getAttribute("getVnfHierarchy_result"));
@@ -142,7 +157,6 @@ public class ExecuteNodeActionImplTest {
given(aaiService.query(any(), Mockito.anyBoolean(),
any(), any(), any(), any(),
any(SvcLogicContext.class))).willReturn(FAILED_STATUS);
-
executeNodeAction.getVnfHierarchy(params, SVC_LOGIC_CONTEXT);
assertEquals("0", SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFCCount"));
@@ -169,4 +183,36 @@ public class ExecuteNodeActionImplTest {
assertTrue(vServersList.contains(SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].VM[0].URL")));
assertTrue(vServersList.contains(SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].VM[1].URL")));
}
+
+ @Test
+ public void testGetVserverRelations() throws Exception {
+ ExecuteNodeActionImpl executeNodeActionSpy = Mockito.spy(executeNodeAction);
+ given(aaiService.query(any(), Mockito.anyBoolean(),
+ any(), any(), any(), any(),
+ any(SvcLogicContext.class))).willReturn(SUCCESS_STATUS);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(("vnfRetrived.related-to"), "vserver");
+ ctx.setAttribute("vnfRetrived.relationship-data_length", "1");
+ ctx.setAttribute("vnfRetrived.related-to-property_length", "1");
+ ctx.setAttribute("vnfRetrived.relationship-data[0].relationship-key", "KEY");
+ ctx.setAttribute("vnfRetrived.relationship-data[0].relationship-value", "VALUE");
+ ctx.setAttribute("vnfRetrived.related-to-property[0].property-key", "KEY");
+ ctx.setAttribute("vnfRetrived.related-to-property[0].property-value", "VALUE");
+ ctx.setAttribute("vmRetrived.vserver-selflink", "URL");
+ ctx.setAttribute("vmRetrived.related-to", "vnfc");
+ ctx.setAttribute("vmRetrived.relationship-data_length", "1");
+ ctx.setAttribute("vmRetrived.relationship-data[0].relationship-key", "vnfc.vnfc-name");
+ ctx.setAttribute("vmRetrived.relationship-data[0].relationship-value", "VALUE");
+ Mockito.when(executeNodeActionSpy.getSvcLogicContext()).thenReturn(ctx);
+ executeNodeActionSpy.getVnfHierarchy(params, SVC_LOGIC_CONTEXT);
+
+ assertEquals("1", SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFCCount"));
+ assertEquals("SUCCESS", SVC_LOGIC_CONTEXT.getAttribute("getVnfHierarchy_result"));
+ }
+
+ @AfterClass
+ public static void restoreLogger() {
+ logger.setLevel(originalLoggerLevel);
+ }
+
}