2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.dg.aai.impl;
27 import org.junit.runner.RunWith;
28 import org.openecomp.appc.dg.aai.Constants;
29 import org.openecomp.appc.dg.aai.impl.AAIPluginImpl;
30 import org.openecomp.appc.dg.common.dao.DAOService;
31 import org.openecomp.appc.dg.common.impl.LicenseManagerImpl;
32 import org.openecomp.appc.exceptions.APPCException;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
35 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
36 import org.osgi.framework.Bundle;
37 import org.osgi.framework.BundleContext;
38 import org.osgi.framework.FrameworkUtil;
39 import org.osgi.framework.ServiceReference;
40 import org.powermock.api.mockito.PowerMockito;
41 import org.powermock.core.classloader.annotations.PrepareForTest;
42 import org.powermock.modules.junit4.PowerMockRunner;
44 import java.util.HashMap;
47 import static org.junit.Assert.*;
50 @RunWith(PowerMockRunner.class)
51 @PrepareForTest({AAIPluginImpl.class, FrameworkUtil.class})
52 public class AAIPluginImplTest {
53 private AAIPluginImpl aaiPlugin;
54 private AAIClientMock aaiClient;
56 private final BundleContext bundleContext= Mockito.mock(BundleContext.class);
57 private final Bundle bundleService=Mockito.mock(Bundle.class);
58 private final ServiceReference sref=Mockito.mock(ServiceReference.class);
60 String prefix = "aai.input.data";
61 String vnfId = "test_VNF";
62 String vnfId1 = "test_VNF1";
63 String vnfId2 = "test_VNF2";
64 String vnfId3 = "test_VNF3";
67 public void setUp() throws NoSuchFieldException, IllegalAccessException {
68 aaiClient = new AAIClientMock();
69 PowerMockito.mockStatic(FrameworkUtil.class);
70 PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
71 PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
72 PowerMockito.when(bundleContext.getServiceReference(Matchers.any(Class.class))).thenReturn(sref);
73 PowerMockito.when(bundleContext.getService(sref)).thenReturn(aaiClient);
74 aaiPlugin = new AAIPluginImpl();
83 public void testPostGenericVnfData() throws Exception {
84 Map<String, String> params = new HashMap<>();
85 params.put(prefix+"."+"license-key-uuid", "123");
86 params.put(prefix+"."+"license-assignment-group-uuid", "1234");
87 params.put(prefix+"."+"data.license-key", "12345");
89 HashMap<String, String> mockAAI = new HashMap<>();
90 aaiClient.setMockAAI(mockAAI);
91 SvcLogicContext ctx = new SvcLogicContext();
92 ctx.setAttribute("aai.vnfID", vnfId);
93 ctx.setAttribute("aai.prefix", prefix);
95 aaiPlugin.postGenericVnfData(params, ctx);
97 Assert.assertEquals("wrong license-key-uuid","123", mockAAI.get("license-key-uuid"));
98 Assert.assertEquals("wrong license-assignment-group-uuid","1234", mockAAI.get("license-assignment-group-uuid"));
99 Assert.assertEquals("wrong data.license-key","12345", mockAAI.get("data.license-key"));
104 public void testPostGenericVnfDataNegativeVnfNotFound() throws Exception {
105 Map<String, String> params = new HashMap<>();
106 params.put(prefix+"."+"license-key-uuid", "123");
107 params.put(prefix+"."+"license-assignment-group-uuid", "1234");
108 params.put(prefix+"."+"data.license-key", "12345");
110 HashMap<String, String> mockAAI = new HashMap<>();
112 aaiClient.setMockAAI(mockAAI);
113 SvcLogicContext ctx = new SvcLogicContext();
114 ctx.setAttribute("aai.vnfID", vnfId1);
115 ctx.setAttribute("aai.prefix", prefix);
118 aaiPlugin.postGenericVnfData(params, ctx);
119 Assert.assertTrue(false);
120 } catch (APPCException e) {
121 Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
128 public void testPostGenericVnfDataNegativeFailure() throws Exception {
129 Map<String, String> params = new HashMap<>();
130 params.put(prefix+"."+"license-key-uuid", "123");
131 params.put(prefix+"."+"license-assignment-group-uuid", "1234");
132 params.put(prefix+"."+"data.license-key", "12345");
134 HashMap<String, String> mockAAI = new HashMap<>();
136 aaiClient.setMockAAI(mockAAI);
137 SvcLogicContext ctx = new SvcLogicContext();
138 ctx.setAttribute("aai.vnfID", vnfId2);
139 ctx.setAttribute("aai.prefix", prefix);
142 aaiPlugin.postGenericVnfData(params, ctx);
143 Assert.assertTrue(false);
144 } catch (APPCException e) {
145 Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
152 public void testPostGenericVnfDataNegativeSvcLogicException() throws Exception {
153 Map<String, String> params = new HashMap<>();
154 params.put(prefix+"."+"license-key-uuid", "123");
155 params.put(prefix+"."+"license-assignment-group-uuid", "1234");
156 params.put(prefix+"."+"data.license-key", "12345");
158 HashMap<String, String> mockAAI = new HashMap<>();
160 aaiClient.setMockAAI(mockAAI);
161 SvcLogicContext ctx = new SvcLogicContext();
162 ctx.setAttribute("aai.vnfID", vnfId3);
163 ctx.setAttribute("aai.prefix", prefix);
166 aaiPlugin.postGenericVnfData(params, ctx);
167 Assert.assertTrue(false);
168 } catch (APPCException e) {
169 Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
175 public void testGetGenericVnfData() throws Exception {
176 String vnfNameKey = "vnf-name";
177 String vnfType = "VSCP";
178 String vnfTypeKey = "vnf-type";
179 String provStatus = "Active";
180 String provStatusKey = "prov-status";
181 String orchestrationStatus = "Running";
182 String orchestrationStatusKey = "orchestration-status";
184 Map<String, String> params = new HashMap<>();
185 HashMap<String, String> mockAAI = new HashMap<>();
186 mockAAI.put(vnfNameKey,vnfId);
187 mockAAI.put(vnfTypeKey,vnfType);
188 mockAAI.put(provStatusKey, provStatus);
189 mockAAI.put(orchestrationStatusKey, orchestrationStatus);
190 aaiClient.setMockAAI(mockAAI);
192 SvcLogicContext ctx = new SvcLogicContext();
193 ctx.setAttribute("aai.vnfID", vnfId);
194 ctx.setAttribute("aai.prefix", prefix);
197 aaiPlugin.getGenericVnfData(params, ctx);
199 Assert.assertEquals("wrong "+vnfNameKey,vnfId, ctx.getAttribute(prefix + "." + vnfNameKey));
200 Assert.assertEquals("wrong "+orchestrationStatusKey,orchestrationStatus, ctx.getAttribute(prefix + "." + orchestrationStatusKey));
201 Assert.assertEquals("wrong "+vnfTypeKey,vnfType, ctx.getAttribute(prefix + "." + vnfTypeKey));
202 Assert.assertEquals("wrong "+provStatusKey,provStatus, ctx.getAttribute(prefix + "." + provStatusKey ));
209 public void testGetGenericVnfDataNegativeVnfNotFound() throws Exception {
211 Map<String, String> params = new HashMap<>();
212 SvcLogicContext ctx = new SvcLogicContext();
213 ctx.setAttribute("aai.vnfID", vnfId1);
214 ctx.setAttribute("aai.prefix", prefix);
218 aaiPlugin.getGenericVnfData(params, ctx);
219 Assert.assertTrue(false);
220 } catch (APPCException e) {
221 Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
227 public void testGetGenericVnfDataNegativeFailure() throws Exception {
229 Map<String, String> params = new HashMap<>();
230 SvcLogicContext ctx = new SvcLogicContext();
231 ctx.setAttribute("aai.vnfID", vnfId2);
232 ctx.setAttribute("aai.prefix", prefix);
235 aaiPlugin.getGenericVnfData(params, ctx);
236 Assert.assertTrue(false);
237 } catch (APPCException e) {
238 Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
244 public void testGetGenericVnfDataNegativeSvcLogicException() throws Exception {
246 Map<String, String> params = new HashMap<>();
247 SvcLogicContext ctx = new SvcLogicContext();
248 ctx.setAttribute("aai.vnfID", vnfId3);
249 ctx.setAttribute("aai.prefix", prefix);
252 aaiPlugin.getGenericVnfData(params, ctx);
253 Assert.assertTrue(false);
254 } catch (APPCException e) {
255 Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));