2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2018 Nokia
10 * ================================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.dg.util.impl;
28 import static junit.framework.TestCase.assertTrue;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotNull;
31 import static org.junit.Assert.assertNull;
32 import static org.mockito.BDDMockito.given;
33 import static org.mockito.Matchers.any;
34 import static org.mockito.Matchers.anyMap;
35 import static org.mockito.Matchers.anyString;
36 import static org.mockito.Matchers.eq;
37 import static org.mockito.Mockito.times;
38 import static org.mockito.Mockito.verify;
40 import java.util.HashMap;
41 import java.util.HashSet;
44 import org.junit.Before;
45 import org.junit.Test;
46 import org.junit.runner.RunWith;
47 import org.mockito.Mock;
48 import org.mockito.Mockito;
49 import org.mockito.runners.MockitoJUnitRunner;
50 import org.onap.appc.exceptions.APPCException;
51 import org.onap.ccsdk.sli.adaptors.aai.AAIService;
52 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
53 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
54 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
56 @RunWith(MockitoJUnitRunner.class)
57 public class ExecuteNodeActionImplTest {
59 private static final String resourceType = "resourceType";
60 private static final String prefix = "prefix";
61 private static final String resourceKey = "resourceKey";
62 private static final String attributeName = "attributeName";
63 private static final String attributeValue = "attributeValue";
64 private static final Map<String, String> params = new HashMap<>();
65 private static final SvcLogicContext SVC_LOGIC_CONTEXT = new SvcLogicContext();
66 private static final SvcLogicResource.QueryStatus SUCCESS_STATUS = SvcLogicResource.QueryStatus.SUCCESS;
67 private static final QueryStatus FAILED_STATUS = SvcLogicResource.QueryStatus.FAILURE;
70 private AAIServiceFactory aaiServiceFactory;
72 private AAIService aaiService;
73 private ExecuteNodeActionImpl executeNodeAction;
77 executeNodeAction = new ExecuteNodeActionImpl(aaiServiceFactory);
78 given(aaiServiceFactory.getAAIService()).willReturn(aaiService);
80 params.put("resourceType", resourceType);
81 params.put("prefix", prefix);
82 params.put("resourceKey", resourceKey);
83 params.put("attributeName", attributeName);
84 params.put("attributeValue", attributeValue);
85 params.put("waitTime", "1");
89 public void testWaitMethod() throws Exception {
90 executeNodeAction.waitMethod(params, SVC_LOGIC_CONTEXT);
94 public void testGetResource() throws Exception {
95 given(aaiService.query(any(), Mockito.anyBoolean(),
96 any(), any(), any(), any(),
97 any(SvcLogicContext.class))).willReturn(SUCCESS_STATUS);
99 executeNodeAction.getResource(params, SVC_LOGIC_CONTEXT);
101 verify(aaiService, times(1)).query(resourceType, false, null, resourceKey, prefix, null, SVC_LOGIC_CONTEXT);
102 assertEquals(SUCCESS_STATUS.toString(), SVC_LOGIC_CONTEXT.getAttribute("getResource_result"));
106 public void testPostResource() throws Exception {
107 given(aaiService.update(eq(resourceType), eq(resourceKey), anyMap(),
108 eq(prefix), eq(SVC_LOGIC_CONTEXT))).willReturn(SUCCESS_STATUS);
110 executeNodeAction.postResource(params, SVC_LOGIC_CONTEXT);
112 verify(aaiService, times(1)).update(eq(resourceType), eq(resourceKey), anyMap(), eq(prefix),
113 eq(SVC_LOGIC_CONTEXT));
114 assertEquals(SUCCESS_STATUS.toString(), SVC_LOGIC_CONTEXT.getAttribute("postResource_result"));
118 public void testDeleteResource() throws Exception {
119 given(aaiService.delete(eq(resourceType), eq(resourceKey),
120 eq(SVC_LOGIC_CONTEXT))).willReturn(SUCCESS_STATUS);
122 executeNodeAction.deleteResource(params, SVC_LOGIC_CONTEXT);
124 verify(aaiService, times(1)).delete(eq(resourceType), eq(resourceKey), eq(SVC_LOGIC_CONTEXT));
125 assertEquals(SUCCESS_STATUS.toString(), SVC_LOGIC_CONTEXT.getAttribute("deleteResource_result"));
129 public void testGetVnfHierarchySuccess() throws Exception {
130 given(aaiService.query(any(), Mockito.anyBoolean(),
131 any(), any(), any(), any(),
132 any(SvcLogicContext.class))).willReturn(SUCCESS_STATUS);
134 executeNodeAction.getVnfHierarchy(params, SVC_LOGIC_CONTEXT);
136 assertEquals("0", SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFCCount"));
137 assertEquals("SUCCESS", SVC_LOGIC_CONTEXT.getAttribute("getVnfHierarchy_result"));
140 @Test(expected = APPCException.class)
141 public void testGetVnfHierarchyFailure() throws Exception {
142 given(aaiService.query(any(), Mockito.anyBoolean(),
143 any(), any(), any(), any(),
144 any(SvcLogicContext.class))).willReturn(FAILED_STATUS);
146 executeNodeAction.getVnfHierarchy(params, SVC_LOGIC_CONTEXT);
148 assertEquals("0", SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFCCount"));
149 assertEquals("FAILURE", SVC_LOGIC_CONTEXT.getAttribute("getVnfHierarchy_result"));
150 assertNotNull(SVC_LOGIC_CONTEXT.getAttribute("output.status.message"));
154 public void testPopulateVnfcsDetailsinContext() throws Exception {
155 Map<String, Set<String>> vnfcHierarchyMap = new HashMap<>();
156 Set<String> vServersList = new HashSet<>();
157 vnfcHierarchyMap.put("SMP", vServersList);
158 vServersList.add("smp-0-url");
159 vServersList.add("smp-1-url");
161 given(aaiService.query(eq("vnfc"), eq(false), anyString(), eq("vnfc-name = 'SMP'"),
162 eq("vnfcRetrived"), anyString(), any(SvcLogicContext.class))).willReturn(SUCCESS_STATUS);
164 executeNodeAction.populateVnfcsDetailsinContext(vnfcHierarchyMap, SVC_LOGIC_CONTEXT);
166 assertNull(SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].TYPE"));
167 assertNull(SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].NAME"));
168 assertEquals("2", SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].VM_COUNT"));
169 assertTrue(vServersList.contains(SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].VM[0].URL")));
170 assertTrue(vServersList.contains(SVC_LOGIC_CONTEXT.getAttribute("VNF.VNFC[0].VM[1].URL")));