2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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.onap.appc.artifact.handler.node;
27 import org.apache.commons.io.IOUtils;
28 import org.json.JSONArray;
29 import org.json.JSONObject;
30 import org.junit.Before;
31 import org.junit.Ignore;
32 import org.junit.Test;
33 import org.mockito.Mockito;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
35 import org.powermock.reflect.Whitebox;
36 import org.onap.appc.artifact.handler.dbservices.MockDBService;
37 import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants;
38 import org.onap.appc.artifact.handler.utils.ArtifactHandlerProviderUtilTest;
40 import java.util.HashMap;
41 import java.nio.charset.Charset;
43 import static org.junit.Assert.assertFalse;
44 import static org.junit.Assert.assertTrue;
46 public class ArtifactHandlerNodeTest {
48 private ArtifactHandlerNode artifactHandlerNode;
51 public void setUp() throws Exception {
52 artifactHandlerNode = Mockito.spy(ArtifactHandlerNode.class);
53 Mockito.doReturn(true)
54 .when(artifactHandlerNode)
55 .updateStoreArtifacts(Mockito.any(JSONObject.class), Mockito.any(JSONObject.class));
56 Mockito.doReturn(true)
57 .when(artifactHandlerNode)
58 .storeReferenceData(Mockito.any(JSONObject.class), Mockito.any(JSONObject.class));
62 public void testProcessArtifact() throws Exception {
63 SvcLogicContext ctx = new SvcLogicContext();
64 ctx.setAttribute("test", "test");
65 Map<String, String> inParams = new HashMap<>();
66 JSONObject postData = new JSONObject();
67 JSONObject input = new JSONObject();
68 inParams.put("response_prefix", "prefix");
69 JSONObject requestInfo = new JSONObject();
70 JSONObject documentInfo = new JSONObject();
71 String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader()
72 .getResourceAsStream("templates/reference_template"), Charset.defaultCharset());
73 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent);
74 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json");
75 requestInfo.put("RequestInfo", "testValue");
76 input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo);
77 input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo);
78 postData.put("input", input);
79 inParams.put("postData", postData.toString());
80 artifactHandlerNode.processArtifact(inParams, ctx);
83 @Ignore("Test is taking 60 seconds")
84 @Test(expected = Exception.class)
85 public void testStoreReferenceData() throws Exception {
86 JSONObject documentInfo = new JSONObject();
87 String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader()
88 .getResourceAsStream("templates/reference_template"), Charset.defaultCharset());
89 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent);
90 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json");
91 JSONObject requestInfo = new JSONObject();
92 requestInfo.put("RequestInfo", "testStoreReferenceData");
93 artifactHandlerNode.storeReferenceData(requestInfo, documentInfo);
97 public void testPopulateProtocolReference() throws Exception {
98 ArtifactHandlerNode ah = new ArtifactHandlerNode();
100 "{\"action\": \"TestAction\",\"action-level\": \"vnf\",\"scope\": {\"vnf-type\": \"vDBE-I\",\"vnfc-type\": null},\"template\": \"N\",\"device-protocol\": \"REST\"}";
101 JSONObject content = new JSONObject(contentStr);
102 MockDBService dbService = MockDBService.initialise();
103 Whitebox.invokeMethod(ah, "populateProtocolReference", dbService, content);
107 public void testProcessAndStoreCapablitiesArtifact() throws Exception {
108 ArtifactHandlerNode ah = new ArtifactHandlerNode();
109 JSONObject capabilities = new JSONObject();
110 JSONObject documentInfo = new JSONObject();
111 MockDBService dbService = MockDBService.initialise();
112 documentInfo.put(SdcArtifactHandlerConstants.SERVICE_UUID, "testuid");
113 documentInfo.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "testDist");
114 documentInfo.put(SdcArtifactHandlerConstants.SERVICE_NAME, "testName");
115 documentInfo.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "testDesc");
116 documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "testRes");
117 documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "testResIns");
118 documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_VERSION, "testVers");
119 documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "testResType");
120 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "testArtifactUuid");
121 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_VERSION, "testArtifactVers");
122 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "testArtifactDesc");
123 Whitebox.invokeMethod(ah, "processAndStoreCapabilitiesArtifact", dbService, documentInfo, capabilities,
124 "artifactName", "someVnf");
128 public void testCleanVnfcInstance() throws Exception {
129 ArtifactHandlerNode ah = new ArtifactHandlerNode();
130 SvcLogicContext ctx = new SvcLogicContext();
131 Whitebox.invokeMethod(ah, "cleanVnfcInstance", ctx);
135 @Ignore("Test is taking 60 seconds")
136 @Test(expected = Exception.class)
137 public void testGetArtifactIDException() throws Exception {
138 ArtifactHandlerNode ah = new ArtifactHandlerNode();
139 String yFileName = "yFileName";
140 Whitebox.invokeMethod(ah, "getArtifactID", yFileName);
143 @Ignore("Test is taking 60 seconds")
144 @Test(expected = Exception.class)
145 public void testStoreUpdateSdcArtifacts() throws Exception {
146 ArtifactHandlerNode ah = new ArtifactHandlerNode();
148 "{\"request-information\":{},\"document-parameters\":{\"artifact-name\":\"testArtifact\",\"artifact-contents\":{\"content\":\"TestContent\"}}}";
149 JSONObject postData = new JSONObject(postDataStr);
150 Whitebox.invokeMethod(ah, "storeUpdateSdcArtifacts", postData);
153 @Ignore("Test is taking 60 seconds")
154 @Test(expected = Exception.class)
155 public void testUpdateStoreArtifacts() throws Exception {
156 JSONObject documentInfo = new JSONObject();
157 String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader()
158 .getResourceAsStream("templates/reference_template"), Charset.defaultCharset());
159 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent);
160 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json");
161 JSONObject requestInfo = new JSONObject();
162 requestInfo.put("RequestInfo", "testupdateStoreArtifacts");
163 artifactHandlerNode.updateStoreArtifacts(requestInfo, documentInfo);
167 public void testCleanArtifactInstanceData() throws Exception {
168 SvcLogicContext ctx = new SvcLogicContext();
169 Whitebox.invokeMethod(artifactHandlerNode, "cleanArtifactInstanceData", ctx);
172 @Ignore("Test is taking 60 seconds")
173 @Test(expected = Exception.class)
174 public void testUpdateYangContents() throws Exception {
175 String artifactId = "1";
176 String yangContents = "SomeContent";
177 Whitebox.invokeMethod(artifactHandlerNode, "updateYangContents", artifactId, yangContents);
181 public void testProcessVmList() throws Exception{
182 String contentStr = "{\r\n\t\"action\": \"ConfigScaleOut\",\r\n\t\"action-level\": \"VNF\",\r\n\t\"scope\": "
183 + "{\r\n\t\t\"vnf-type\": \"ScaleOutVNF\",\r\n\t\t\"vnfc-type\": \"\"\r\n\t},\r\n\t\"template\": \"Y\",\r\n\t\"vm\": "
184 + "[\r\n\t{ \r\n\t\t\"vm-instance\": 1,\r\n\t\t\"template-id\":\"id1\",\r\n\t\t\r\n\t\t\"vnfc\": [{\r\n\t\t\t\"vnfc-instance\": 1,\r\n\t\t\t\"vnfc-type\": \"t1\",\r\n\t\t\t\"vnfc-function-code\": "
185 + "\"Testdbg\",\r\n\t\t\t\"group-notation-type\": \"GNType\",\r\n\t\t\t\"ipaddress-v4-oam-vip\": \"N\",\r\n\t\t\t\"group-notation-value\": "
186 + "\"GNValue\"\r\n\t\t}]\r\n\t},\r\n\t{ \r\n\t\t\"vm-instance\": 1,\r\n\t\t\"template-id\":\"id2\",\r\n\t\t\r\n\t\t\"vnfc\": [{\r\n\t\t\t\"vnfc-instance\": 1,\r\n\t\t\t\"vnfc-type\": "
187 + "\"t1\",\r\n\t\t\t\"vnfc-function-code\": \"Testdbg\",\r\n\t\t\t\"group-notation-type\": \"GNType\",\r\n\t\t\t\"ipaddress-v4-oam-vip\": \"N\",\r\n\t\t\t\"group-notation-value\": "
188 + "\"GNValue\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"vnfc-instance\": 2,\r\n\t\t\t\"vnfc-type\": \"t2\",\r\n\t\t\t\"vnfc-function-code\": \"Testdbg\",\r\n\t\t\t\"group-notation-type\": "
189 + "\"GNType\",\r\n\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\"group-notation-value\": \"GNValue\"\r\n\t\t}]\r\n\t},\r\n\t{\r\n\t\t\"vm-instance\": 2,\r\n\t\t\"template-id\":\"id3\",\r\n\t\t\"vnfc\": "
190 + "[{\r\n\t\t\t\"vnfc-instance\": 1,\r\n\t\t\t\"vnfc-type\": \"t3\",\r\n\t\t\t\"vnfc-function-code\": \"Testdbg\",\r\n\t\t\t\"group-notation-type\": "
191 + "\"GNType\",\r\n\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\"group-notation-value\": \"GNValue\"\r\n\t\t}]\r\n\t}],\r\n\t\"device-protocol\": "
192 + "\"TEST-PROTOCOL\",\r\n\t\"user-name\": \"Testnetconf\",\r\n\t\"port-number\": \"22\",\r\n\t\"artifact-list\": [{\r\n\t\t\"artifact-name\": \"Testv_template.json\",\r\n\t\t\"artifact-type\": "
193 + "\"Testconfig_template\"\r\n\t},\r\n\t{\r\n\t\t\"artifact-name\": \"TESTv_parameter_definitions.json\",\r\n\t\t\"artifact-type\": \"Testparameter_definitions\"\r\n\t},\r\n\t{\r\n\t\t\"artifact-name\": "
194 + "\"PD_JunitTESTv_parameter_yang.json\",\r\n\t\t\"artifact-type\": \"PD_definations\"\r\n\t}]\r\n}";
195 JSONObject content=new JSONObject(contentStr);
196 MockDBService dbService = MockDBService.initialise();
197 SvcLogicContext context = new SvcLogicContext();
198 artifactHandlerNode.processVmList(content, context, dbService);
202 public void testProcessConfigTypeActions() throws Exception{
203 String contentStr = "{\"action\": \"ConfigScaleOut\"}";
204 JSONObject content=new JSONObject(contentStr);
205 MockDBService dbService = MockDBService.initialise();
206 SvcLogicContext context = new SvcLogicContext();
207 context.setAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL,"Test");
208 artifactHandlerNode.processConfigTypeActions(content, dbService, context);
212 public void testProcessArtifactLists() throws Exception{
213 String contentStr = "{\r\n\t\"action\": \"ConfigScaleOut\",\r\n\t\"action-level\": \"VNF\",\r\n\t\"scope\": "
214 + "{\r\n\t\t\"vnf-type\": \"ScaleOutVNF\",\r\n\t\t\"vnfc-type\": \"\"\r\n\t},\r\n\t\"template\": \"Y\",\r\n\t\"vm\": "
215 + "[\r\n\t{ \r\n\t\t\"vm-instance\": 1,\r\n\t\t\"template-id\":\"id1\",\r\n\t\t\r\n\t\t\"vnfc\": [{\r\n\t\t\t\"vnfc-instance\": 1,\r\n\t\t\t\"vnfc-type\": \"t1\",\r\n\t\t\t\"vnfc-function-code\": "
216 + "\"Testdbg\",\r\n\t\t\t\"group-notation-type\": \"GNType\",\r\n\t\t\t\"ipaddress-v4-oam-vip\": \"N\",\r\n\t\t\t\"group-notation-value\": "
217 + "\"GNValue\"\r\n\t\t}]\r\n\t},\r\n\t{ \r\n\t\t\"vm-instance\": 1,\r\n\t\t\"template-id\":\"id2\",\r\n\t\t\r\n\t\t\"vnfc\": [{\r\n\t\t\t\"vnfc-instance\": 1,\r\n\t\t\t\"vnfc-type\": "
218 + "\"t1\",\r\n\t\t\t\"vnfc-function-code\": \"Testdbg\",\r\n\t\t\t\"group-notation-type\": \"GNType\",\r\n\t\t\t\"ipaddress-v4-oam-vip\": \"N\",\r\n\t\t\t\"group-notation-value\": "
219 + "\"GNValue\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"vnfc-instance\": 2,\r\n\t\t\t\"vnfc-type\": \"t2\",\r\n\t\t\t\"vnfc-function-code\": \"Testdbg\",\r\n\t\t\t\"group-notation-type\": "
220 + "\"GNType\",\r\n\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\"group-notation-value\": \"GNValue\"\r\n\t\t}]\r\n\t},\r\n\t{\r\n\t\t\"vm-instance\": 2,\r\n\t\t\"template-id\":\"id3\",\r\n\t\t\"vnfc\": "
221 + "[{\r\n\t\t\t\"vnfc-instance\": 1,\r\n\t\t\t\"vnfc-type\": \"t3\",\r\n\t\t\t\"vnfc-function-code\": \"Testdbg\",\r\n\t\t\t\"group-notation-type\": "
222 + "\"GNType\",\r\n\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\"group-notation-value\": \"GNValue\"\r\n\t\t}]\r\n\t}],\r\n\t\"device-protocol\": "
223 + "\"TEST-PROTOCOL\",\r\n\t\"user-name\": \"Testnetconf\",\r\n\t\"port-number\": \"22\",\r\n\t\"artifact-list\": [{\r\n\t\t\"artifact-name\": \"Testv_template.json\",\r\n\t\t\"artifact-type\": "
224 + "\"Testconfig_template\"\r\n\t},\r\n\t{\r\n\t\t\"artifact-name\": \"TESTv_parameter_definitions.json\",\r\n\t\t\"artifact-type\": \"Testparameter_definitions\"\r\n\t},\r\n\t{\r\n\t\t\"artifact-name\": "
225 + "\"PD_JunitTESTv_parameter_yang.json\",\r\n\t\t\"artifact-type\": \"PD_definations\"\r\n\t}]\r\n}";
226 JSONObject content=new JSONObject(contentStr);
227 MockDBService dbService = MockDBService.initialise();
228 SvcLogicContext context = new SvcLogicContext();
229 artifactHandlerNode.processArtifactList(content,dbService,context);
233 public void testProcessActionLists() throws Exception {
234 String contentStr = "{\r\n\t\"action\": \"HealthCheck\",\r\n\t\"action-level\": \"vm\",\r\n\t\"scope\":"
235 + " {\r\n\t\t\"vnf-type\": \"vDBE-I\",\r\n\t\t\"vnfc-type\": null\r\n\t},\r\n\t\"template\": "
236 + "\"N\",\r\n\t\"device-protocol\": \"REST\",\r\n\t\"vnfc-function-code-list\": [\"SSC\", \"MMSC\"]\r\n}";
237 JSONObject content = new JSONObject(contentStr);
238 JSONArray vmActionVnfcFunctionCodesList = new JSONArray();
239 JSONArray vnfActionList = new JSONArray();
240 JSONArray vfModuleActionList = new JSONArray();
241 JSONArray vnfcActionList = new JSONArray();
242 String[] actionLevels = { "vnf", "vm", "vf-module", "vnfc" };
243 for (String actionLevel : actionLevels) {
244 artifactHandlerNode.processActionLists(content, actionLevel, vnfcActionList, vfModuleActionList,
245 vnfActionList, vmActionVnfcFunctionCodesList);
250 public void testIsCapabilityArtifactNeeded() throws Exception {
251 String scopeObjStr1= "{\"vnf-type\":\"someVnf\",\"vnfc-type\":\"somVnfc\"}";
252 String scopeObjStr2= "{\"vnf-type\":\"someVnf\",\"vnfc-type\":\"\"}";
253 JSONObject scope1 = new JSONObject(scopeObjStr1);
254 JSONObject scope2 = new JSONObject(scopeObjStr2);
255 SvcLogicContext context = new SvcLogicContext();
256 assertFalse(artifactHandlerNode.isCapabilityArtifactNeeded(scope1, context));
257 assertTrue(artifactHandlerNode.isCapabilityArtifactNeeded(scope2, context));