2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.dg.aai.impl;
25 import org.junit.runner.RunWith;
26 import org.openecomp.appc.dg.aai.Constants;
27 import org.openecomp.appc.dg.aai.impl.AAIPluginImpl;
28 import org.openecomp.appc.dg.common.dao.DAOService;
29 import org.openecomp.appc.dg.common.impl.LicenseManagerImpl;
30 import org.openecomp.appc.exceptions.APPCException;
31 import org.openecomp.sdnc.sli.SvcLogicContext;
32 import org.openecomp.sdnc.sli.SvcLogicResource;
33 import org.openecomp.sdnc.sli.aai.AAIClient;
34 import org.osgi.framework.Bundle;
35 import org.osgi.framework.BundleContext;
36 import org.osgi.framework.FrameworkUtil;
37 import org.osgi.framework.ServiceReference;
38 import org.powermock.api.mockito.PowerMockito;
39 import org.powermock.core.classloader.annotations.PrepareForTest;
40 import org.powermock.modules.junit4.PowerMockRunner;
42 import java.util.HashMap;
45 import static org.junit.Assert.*;
48 @RunWith(PowerMockRunner.class)
49 @PrepareForTest({AAIPluginImpl.class, FrameworkUtil.class})
50 public class AAIPluginImplTest {
51 private AAIPluginImpl aaiPlugin;
52 private AAIClientMock aaiClient;
54 private final BundleContext bundleContext= Mockito.mock(BundleContext.class);
55 private final Bundle bundleService=Mockito.mock(Bundle.class);
56 private final ServiceReference sref=Mockito.mock(ServiceReference.class);
58 String prefix = "aai.input.data";
59 String vnfId = "test_VNF";
60 String vnfId1 = "test_VNF1";
61 String vnfId2 = "test_VNF2";
62 String vnfId3 = "test_VNF3";
65 public void setUp() throws NoSuchFieldException, IllegalAccessException {
66 aaiClient = new AAIClientMock();
67 PowerMockito.mockStatic(FrameworkUtil.class);
68 PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
69 PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
70 PowerMockito.when(bundleContext.getServiceReference(Matchers.any(Class.class))).thenReturn(sref);
71 PowerMockito.when(bundleContext.getService(sref)).thenReturn(aaiClient);
72 aaiPlugin = new AAIPluginImpl();
81 public void testPostGenericVnfData() throws Exception {
82 Map<String, String> params = new HashMap<>();
83 params.put(prefix+"."+"license-key-uuid", "123");
84 params.put(prefix+"."+"license-assignment-group-uuid", "1234");
85 params.put(prefix+"."+"data.license-key", "12345");
87 HashMap<String, String> mockAAI = new HashMap<>();
88 aaiClient.setMockAAI(mockAAI);
89 SvcLogicContext ctx = new SvcLogicContext();
90 ctx.setAttribute("aai.vnfID", vnfId);
91 ctx.setAttribute("aai.prefix", prefix);
93 aaiPlugin.postGenericVnfData(params, ctx);
95 Assert.assertEquals("wrong license-key-uuid","123", mockAAI.get("license-key-uuid"));
96 Assert.assertEquals("wrong license-assignment-group-uuid","1234", mockAAI.get("license-assignment-group-uuid"));
97 Assert.assertEquals("wrong data.license-key","12345", mockAAI.get("data.license-key"));
102 public void testPostGenericVnfDataNegativeVnfNotFound() throws Exception {
103 Map<String, String> params = new HashMap<>();
104 params.put(prefix+"."+"license-key-uuid", "123");
105 params.put(prefix+"."+"license-assignment-group-uuid", "1234");
106 params.put(prefix+"."+"data.license-key", "12345");
108 HashMap<String, String> mockAAI = new HashMap<>();
110 aaiClient.setMockAAI(mockAAI);
111 SvcLogicContext ctx = new SvcLogicContext();
112 ctx.setAttribute("aai.vnfID", vnfId1);
113 ctx.setAttribute("aai.prefix", prefix);
116 aaiPlugin.postGenericVnfData(params, ctx);
117 Assert.assertTrue(false);
118 } catch (APPCException e) {
119 Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
126 public void testPostGenericVnfDataNegativeFailure() throws Exception {
127 Map<String, String> params = new HashMap<>();
128 params.put(prefix+"."+"license-key-uuid", "123");
129 params.put(prefix+"."+"license-assignment-group-uuid", "1234");
130 params.put(prefix+"."+"data.license-key", "12345");
132 HashMap<String, String> mockAAI = new HashMap<>();
134 aaiClient.setMockAAI(mockAAI);
135 SvcLogicContext ctx = new SvcLogicContext();
136 ctx.setAttribute("aai.vnfID", vnfId2);
137 ctx.setAttribute("aai.prefix", prefix);
140 aaiPlugin.postGenericVnfData(params, ctx);
141 Assert.assertTrue(false);
142 } catch (APPCException e) {
143 Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
150 public void testPostGenericVnfDataNegativeSvcLogicException() throws Exception {
151 Map<String, String> params = new HashMap<>();
152 params.put(prefix+"."+"license-key-uuid", "123");
153 params.put(prefix+"."+"license-assignment-group-uuid", "1234");
154 params.put(prefix+"."+"data.license-key", "12345");
156 HashMap<String, String> mockAAI = new HashMap<>();
158 aaiClient.setMockAAI(mockAAI);
159 SvcLogicContext ctx = new SvcLogicContext();
160 ctx.setAttribute("aai.vnfID", vnfId3);
161 ctx.setAttribute("aai.prefix", prefix);
164 aaiPlugin.postGenericVnfData(params, ctx);
165 Assert.assertTrue(false);
166 } catch (APPCException e) {
167 Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
173 public void testGetGenericVnfData() throws Exception {
174 String vnfNameKey = "vnf-name";
175 String vnfType = "VSCP";
176 String vnfTypeKey = "vnf-type";
177 String provStatus = "Active";
178 String provStatusKey = "prov-status";
179 String orchestrationStatus = "Running";
180 String orchestrationStatusKey = "orchestration-status";
182 Map<String, String> params = new HashMap<>();
183 HashMap<String, String> mockAAI = new HashMap<>();
184 mockAAI.put(vnfNameKey,vnfId);
185 mockAAI.put(vnfTypeKey,vnfType);
186 mockAAI.put(provStatusKey, provStatus);
187 mockAAI.put(orchestrationStatusKey, orchestrationStatus);
188 aaiClient.setMockAAI(mockAAI);
190 SvcLogicContext ctx = new SvcLogicContext();
191 ctx.setAttribute("aai.vnfID", vnfId);
192 ctx.setAttribute("aai.prefix", prefix);
195 aaiPlugin.getGenericVnfData(params, ctx);
197 Assert.assertEquals("wrong "+vnfNameKey,vnfId, ctx.getAttribute(prefix + "." + vnfNameKey));
198 Assert.assertEquals("wrong "+orchestrationStatusKey,orchestrationStatus, ctx.getAttribute(prefix + "." + orchestrationStatusKey));
199 Assert.assertEquals("wrong "+vnfTypeKey,vnfType, ctx.getAttribute(prefix + "." + vnfTypeKey));
200 Assert.assertEquals("wrong "+provStatusKey,provStatus, ctx.getAttribute(prefix + "." + provStatusKey ));
207 public void testGetGenericVnfDataNegativeVnfNotFound() throws Exception {
209 Map<String, String> params = new HashMap<>();
210 SvcLogicContext ctx = new SvcLogicContext();
211 ctx.setAttribute("aai.vnfID", vnfId1);
212 ctx.setAttribute("aai.prefix", prefix);
216 aaiPlugin.getGenericVnfData(params, ctx);
217 Assert.assertTrue(false);
218 } catch (APPCException e) {
219 Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
225 public void testGetGenericVnfDataNegativeFailure() throws Exception {
227 Map<String, String> params = new HashMap<>();
228 SvcLogicContext ctx = new SvcLogicContext();
229 ctx.setAttribute("aai.vnfID", vnfId2);
230 ctx.setAttribute("aai.prefix", prefix);
233 aaiPlugin.getGenericVnfData(params, ctx);
234 Assert.assertTrue(false);
235 } catch (APPCException e) {
236 Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
242 public void testGetGenericVnfDataNegativeSvcLogicException() throws Exception {
244 Map<String, String> params = new HashMap<>();
245 SvcLogicContext ctx = new SvcLogicContext();
246 ctx.setAttribute("aai.vnfID", vnfId3);
247 ctx.setAttribute("aai.prefix", prefix);
250 aaiPlugin.getGenericVnfData(params, ctx);
251 Assert.assertTrue(false);
252 } catch (APPCException e) {
253 Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));