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) 2019 Ericsson
 
  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.artifact.handler.node;
 
  28 import org.apache.commons.io.IOUtils;
 
  29 import org.json.JSONArray;
 
  30 import org.json.JSONObject;
 
  31 import org.junit.Before;
 
  32 import org.junit.Ignore;
 
  33 import org.junit.Rule;
 
  34 import org.junit.Test;
 
  35 import org.junit.rules.ExpectedException;
 
  36 import org.junit.runner.RunWith;
 
  37 import org.mockito.Mockito;
 
  38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  39 import org.onap.sdnc.config.params.transformer.tosca.ArtifactProcessorImpl;
 
  40 import org.onap.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
 
  41 import org.powermock.api.mockito.PowerMockito;
 
  42 import org.powermock.core.classloader.annotations.PrepareForTest;
 
  43 import org.powermock.modules.junit4.PowerMockRunner;
 
  44 import org.powermock.reflect.Whitebox;
 
  45 import org.onap.appc.artifact.handler.dbservices.DBService;
 
  46 import org.onap.appc.artifact.handler.dbservices.MockDBService;
 
  47 import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants;
 
  48 import org.onap.appc.yang.YANGGenerator;
 
  49 import org.onap.appc.yang.impl.YANGGeneratorFactory;
 
  50 import org.onap.appc.artifact.handler.utils.ArtifactHandlerProviderUtilTest;
 
  52 import java.util.HashMap;
 
  53 import java.io.IOException;
 
  54 import java.nio.charset.Charset;
 
  56 import static org.junit.Assert.assertEquals;
 
  57 import static org.junit.Assert.assertFalse;
 
  58 import static org.junit.Assert.assertNotNull;
 
  59 import static org.junit.Assert.assertNull;
 
  60 import static org.junit.Assert.assertTrue;
 
  61 import static org.junit.Assert.fail;
 
  64 @RunWith(PowerMockRunner.class)
 
  65 @PrepareForTest({DBService.class, YANGGeneratorFactory.class})
 
  66 public class ArtifactHandlerNodeTest {
 
  68     private ArtifactHandlerNode artifactHandlerNode;
 
  69     private DBService dbServiceMock;
 
  72     public ExpectedException expectedEx = ExpectedException.none();
 
  75     public void setUp() throws Exception {
 
  76         artifactHandlerNode = Mockito.spy(new ArtifactHandlerNode());
 
  77         PowerMockito.mockStatic(DBService.class);
 
  78         dbServiceMock = Mockito.mock(DBService.class);
 
  79         Mockito.doReturn("12345").when(dbServiceMock).getInternalVersionNumber(Mockito.any(), Mockito.anyString(), Mockito.anyString());
 
  80         PowerMockito.when(DBService.initialise()).thenReturn(dbServiceMock);
 
  81         PowerMockito.mockStatic(YANGGeneratorFactory.class);
 
  82         YANGGenerator yangGeneratorMock = Mockito.mock(YANGGenerator.class);
 
  83         PowerMockito.when(YANGGeneratorFactory.getYANGGenerator()).thenReturn(yangGeneratorMock);
 
  84         ArtifactProcessorImpl artifactProcessorMock = Mockito.mock(ArtifactProcessorImpl.class);
 
  85         Mockito.doReturn(artifactProcessorMock).when(artifactHandlerNode).getArtifactProcessorImpl();
 
  89     public void testProcessArtifact() throws Exception {
 
  90         SvcLogicContext ctx = new SvcLogicContext();
 
  91         ctx.setAttribute("test", "test");
 
  92         Map<String, String> inParams = new HashMap<>();
 
  93         JSONObject postData = new JSONObject();
 
  94         JSONObject input = new JSONObject();
 
  95         inParams.put("response_prefix", "prefix");
 
  96         JSONObject requestInfo = new JSONObject();
 
  97         JSONObject documentInfo = getDocumentInfo("templates/reference_template");
 
  98         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json");
 
  99         requestInfo.put("RequestInfo", "testValue");
 
 100         requestInfo.put("request-id","testREQUEST_ID");
 
 101         input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo);
 
 102         input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo);
 
 103         postData.put("input", input);
 
 104         inParams.put("postData", postData.toString());
 
 105         artifactHandlerNode.processArtifact(inParams, ctx);
 
 106         assertNull(ctx.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY));
 
 110     public void testPopulateProtocolReference() throws Exception {
 
 111         ArtifactHandlerNode ah = new ArtifactHandlerNode();
 
 113                 "{\"action\": \"TestAction\",\"action-level\": \"vnf\",\"scope\": {\"vnf-type\": \"vDBE-I\",\"vnfc-type\": null},\"template\": \"N\",\"device-protocol\": \"REST\"}";
 
 114         JSONObject content = new JSONObject(contentStr);
 
 115         MockDBService dbService = MockDBService.initialise();
 
 116         Whitebox.invokeMethod(ah, "populateProtocolReference", dbService, content);
 
 120     public void testCleanVnfcInstance() throws Exception {
 
 121         ArtifactHandlerNode ah = new ArtifactHandlerNode();
 
 122         SvcLogicContext ctx = new SvcLogicContext();
 
 123         Whitebox.invokeMethod(ah, "cleanVnfcInstance", ctx);
 
 128     public void testStoreUpdateSdcArtifacts() throws Exception {
 
 129         ArtifactHandlerNode ah = new ArtifactHandlerNode();
 
 131                 "{\"request-information\":{\"request-id\": \"12345\"},\"document-parameters\":{\"artifact-name\":\"testArtifact\",\"artifact-contents\":{\"content\":\"TestContent\"}}}";
 
 132         JSONObject postData = new JSONObject(postDataStr);
 
 133         expectedEx.expect(ArtifactHandlerInternalException.class);
 
 134         Whitebox.invokeMethod(ah, "storeUpdateSdcArtifacts", postData);
 
 138     public void testUpdateYangContents() throws Exception {
 
 139         String artifactId = "1";
 
 140         String yangContents = "SomeContent";
 
 141         Whitebox.invokeMethod(artifactHandlerNode, "updateYangContents", artifactId, yangContents);
 
 142         Mockito.verify(dbServiceMock).updateYangContents(Mockito.any(SvcLogicContext.class),
 
 143                 Mockito.anyString(), Mockito.anyString());
 
 147     public void testProcessVmList() throws Exception{
 
 148         String contentStr = "{\r\n\t\"action\": \"ConfigScaleOut\",\r\n\t\"action-level\": \"VNF\",\r\n\t\"scope\": "
 
 149                 + "{\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\": "
 
 150                 + "[\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\": "
 
 151                 + "\"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\": "
 
 152                 + "\"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\": "
 
 153                 + "\"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\": "
 
 154                 + "\"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\": "
 
 155                 + "\"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\": "
 
 156                 + "[{\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\": "
 
 157                 + "\"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\": "
 
 158                 + "\"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\": "
 
 159                 + "\"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\": "
 
 160                 + "\"PD_JunitTESTv_parameter_yang.json\",\r\n\t\t\"artifact-type\": \"PD_definations\"\r\n\t}]\r\n}";
 
 161         JSONObject content=new JSONObject(contentStr);
 
 162         MockDBService dbService = MockDBService.initialise();
 
 163         SvcLogicContext context = new SvcLogicContext();
 
 164         artifactHandlerNode.processVmList(content, context, dbService);
 
 168     public void testProcessConfigTypeActions() throws Exception{
 
 169         String contentStr = "{\"action\": \"ConfigScaleOut\"}";
 
 170         JSONObject content=new JSONObject(contentStr);
 
 171         MockDBService dbService = MockDBService.initialise();
 
 172         SvcLogicContext context = new SvcLogicContext();
 
 173         context.setAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL,"Test");
 
 174         artifactHandlerNode.processConfigTypeActions(content, dbService, context);
 
 178     public void testProcessActionLists() throws Exception {
 
 179         String contentStr = "{\r\n\t\"action\": \"HealthCheck\",\r\n\t\"action-level\": \"vm\",\r\n\t\"scope\":"
 
 180                 + " {\r\n\t\t\"vnf-type\": \"vDBE-I\",\r\n\t\t\"vnfc-type\": null\r\n\t},\r\n\t\"template\": "
 
 181                 + "\"N\",\r\n\t\"device-protocol\": \"REST\",\r\n\t\"vnfc-function-code-list\": [\"SSC\", \"MMSC\"]\r\n}";
 
 182         JSONObject content = new JSONObject(contentStr);
 
 183         JSONArray vmActionVnfcFunctionCodesList = new JSONArray();
 
 184         JSONArray vnfActionList = new JSONArray();
 
 185         JSONArray vfModuleActionList = new JSONArray();
 
 186         JSONArray vnfcActionList = new JSONArray();
 
 187         String[] actionLevels = { "vnf", "vm", "vf-module", "vnfc" };
 
 188         for (String actionLevel : actionLevels) {
 
 189             artifactHandlerNode.processActionLists(content, actionLevel, vnfcActionList, vfModuleActionList,
 
 190                     vnfActionList, vmActionVnfcFunctionCodesList);
 
 195     public void testIsCapabilityArtifactNeeded() throws Exception {
 
 196         String scopeObjStr1= "{\"vnf-type\":\"someVnf\",\"vnfc-type\":\"somVnfc\"}";
 
 197         String scopeObjStr2= "{\"vnf-type\":\"someVnf\",\"vnfc-type\":\"\"}";
 
 198         JSONObject scope1 = new JSONObject(scopeObjStr1);
 
 199         JSONObject scope2 = new JSONObject(scopeObjStr2);
 
 200         SvcLogicContext context = new SvcLogicContext();
 
 201         artifactHandlerNode.setVnfcTypeInformation(scope1, context);
 
 202         assertFalse(artifactHandlerNode.isCapabilityArtifactNeeded(context));
 
 203         artifactHandlerNode.setVnfcTypeInformation(scope2, context);
 
 204         assertTrue(artifactHandlerNode.isCapabilityArtifactNeeded(context));
 
 208     public void testProcessArtifactListsWithMultipleTemplates() throws Exception {
 
 209         String contentStr = "{\r\n\t\t\"action\": \"ConfigScaleOut\",\r\n\t\t\"action-level\": \"vnf\",\r\n\t\t\"scope\": {\r\n\t\t\t\"vnf-type\": "
 
 210                 + "\"vCfgSO-0405\",\r\n\t\t\t\"vnfc-type\": \"\"\r\n\t\t},\r\n\t\t\"template\": \"Y\",\r\n\t\t\"vm\": [{\r\n\t\t\t\"template-id\": "
 
 211                 + "\"TID-0405-EZ\",\r\n\t\t\t\"vm-instance\": 1,\r\n\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": \"1\",\r\n\t\t\t\t\"vnfc-function-code\": "
 
 212                 + "\"Cfg-ez\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\t\"group-notation-type\": \"first-vnfc-name\",\r\n\t\t\t\t\"group-notation-value\":"
 
 213                 + " \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vCfg-0405-ez\"\r\n\t\t\t}]\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"template-id\": "
 
 214                 + "\"TID-0405-EZ\",\r\n\t\t\t\"vm-instance\": 2,\r\n\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": \"1\",\r\n\t\t\t\t\"vnfc-function-code\": "
 
 215                 + "\"Cfg-ez\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\t\"group-notation-type\": \"first-vnfc-name\",\r\n\t\t\t\t\"group-notation-value\":"
 
 216                 + " \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vCfg-0405-ez\"\r\n\t\t\t}]\r\n\t\t}],\r\n\t\t\"device-protocol\": \"ANSIBLE\",\r\n\t\t\"user-name\": \"root\","
 
 217                 + "\r\n\t\t\"port-number\": \"22\",\r\n\t\t\"artifact-list\": [{\r\n\t\t\t\"artifact-name\": \"template_ConfigScaleOut_vCfgSO-0405_0.0.1V_TID-0405-EZ.json\","
 
 218                 + "\r\n\t\t\t\"artifact-type\": \"config_template\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"artifact-name\": \"pd_ConfigScaleOut_vCfgSO-0405_0.0.1V_TID-0405-EZ.yaml\","
 
 219                 + "\r\n\t\t\t\"artifact-type\": \"parameter_definitions\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"artifact-name\": "
 
 220                 + "\"template_ConfigScaleOut_vCfgSO-0405_0.0.1V_TID-0405-EZ-2.json\",\r\n\t\t\t\"artifact-type\": \"config_template\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"artifact-name\": "
 
 221                 + "\"pd_ConfigScaleOut_vCfgSO-0405_0.0.1V_TID-0405-EZ-2.yaml\",\r\n\t\t\t\"artifact-type\": \"parameter_definitions\"\r\n\t\t}],\r\n\t\t\"template-id-list\":"
 
 222                 + " [\"TID-0405-EZ\",\r\n\t\t\"TID-0405-EZ-2\"],\r\n\t\t\"scopeType\": \"vnf-type\"\r\n\t}";
 
 223         JSONObject content = new JSONObject(contentStr);
 
 224         MockDBService dbService = MockDBService.initialise();
 
 225         SvcLogicContext context = new SvcLogicContext();
 
 226         context.setAttribute("vnf-type", "someVnf");
 
 227         context.setAttribute("action", "ConfigScaleOut");
 
 228         artifactHandlerNode.processArtifactList(content, dbService, context, null);
 
 232     public void testProcessArtifactListsWithVnfcTypeList() throws Exception {
 
 233         String contentStr = "{\r\n\t\"action\": \"Configure\",\r\n\t\"action-level\": \"vnf\",\r\n\t\"scope\": {\r\n\t\t\"vnf-type\": "
 
 234                 + "\"newtypeofvnf\",\r\n\t\t\"vnfc-type-list\": [\"vnfctype1\",\"vnfctype2\"]\r\n\t},\r\n\t\"template\": \"Y\",\r\n\t\"vm\":"
 
 235                 + " [{\r\n\t\t\t\"vm-instance\": 1,\r\n\t\t\t\"template-id\": \"vnfctype1\",\r\n\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": "
 
 236                 + "\"1\",\r\n\t\t\t\t\"vnfc-function-code\": \"fcx\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\t\"group-notation-type\": "
 
 237                 + "\"first-vnfc-name\",\r\n\t\t\t\t\"group-notation-value\": \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vDBE\"\r\n\t\t\t}]\r\n\t\t},"
 
 238                 + "\r\n\t\t{\r\n\t\t\t\"vm-instance\": 1,\r\n\t\t\t\"template-id\": \"vnfctype2\",\r\n\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": "
 
 239                 + "\"1\",\r\n\t\t\t\t\"vnfc-function-code\": \"fcx\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\t\"group-notation-type\": "
 
 240                 + "\"first-vnfc-name\",\r\n\t\t\t\t\"group-notation-value\": \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vDBE\"\r\n\t\t\t}]\r\n\t\t},"
 
 241                 + "\r\n\t\t{\r\n\t\t\t\"vm-instance\": 2,\r\n\t\t\t\"template-id\": \"vnfctype2\",\r\n\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": "
 
 242                 + "\"1\",\r\n\t\t\t\t\"vnfc-function-code\": \"fcx\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\t\"group-notation-type\": "
 
 243                 + "\"first-vnfc-name\",\r\n\t\t\t\t\"group-notation-value\": \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vDBE\"\r\n\t\t\t}]\r\n\t\t}\r\n\t],"
 
 244                 + "\r\n\t\"device-protocol\": \"NETCONF-XML\",\r\n\t\"user-name\": \"netconf\",\r\n\t\"port-number\": \"20\",\r\n\t\"artifact-list\": "
 
 245                 + "[{\r\n\t\t\t\"artifact-name\": \"template_ConfigScaleOut_newtypeofvnf_0.0.1V_vnfctype1.xml\",\r\n\t\t\t\"artifact-type\": "
 
 246                 + "\"config_template\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"artifact-name\": \"pd_ConfigScaleOut_newtypeofvnf_0.0.1V_vnfctype1.yaml\","
 
 247                 + "\r\n\t\t\t\"artifact-type\": \"parameter_definitions\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"artifact-name\": "
 
 248                 + "\"template_ConfigScaleOut_newtypeofvnf_0.0.1V_vnfctype2.xml\",\r\n\t\t\t\"artifact-type\": "
 
 249                 + "\"config_template\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"artifact-name\": \"pd_ConfigScaleOut_newtypeofvnf_0.0.1V_vnfctype2.yaml\","
 
 250                 + "\r\n\t\t\t\"artifact-type\": \"parameter_definitions\"\r\n\t\t}\r\n\t],\r\n\t\"scopeType\": \"vnf-type\"\r\n}";
 
 251         JSONObject content = new JSONObject(contentStr);
 
 252         MockDBService dbService = MockDBService.initialise();
 
 253         SvcLogicContext context = new SvcLogicContext();
 
 254         context.setAttribute("vnf-type", "someVnf");
 
 255         context.setAttribute("action", "Configure");
 
 256         JSONObject scope = (JSONObject)content.get("scope");
 
 257         JSONArray vnfcTypeList = artifactHandlerNode.setVnfcTypeInformation(scope, context);
 
 258         artifactHandlerNode.processArtifactList(content, dbService, context, vnfcTypeList);
 
 259         JSONArray vnfcLists = scope.getJSONArray("vnfc-type-list");        
 
 260         assertEquals(vnfcLists.toString(), "[\"vnfctype1\",\"vnfctype2\"]");
 
 261         assertEquals(context.getAttribute("vnfc-type"),"vnfctype2");
 
 262         assertNotNull (vnfcTypeList);
 
 266     public void testProcessArtifactPdArtifactName() throws IOException, ArtifactProcessorException {
 
 267         SvcLogicContext ctx = new SvcLogicContext();
 
 268         ctx.setAttribute("test", "test");
 
 269         Map<String, String> inParams = new HashMap<>();
 
 270         JSONObject postData = new JSONObject();
 
 271         JSONObject input = new JSONObject();
 
 272         inParams.put("response_prefix", "prefix");
 
 273         JSONObject requestInfo = new JSONObject();
 
 274         JSONObject documentInfo = getDocumentInfo("templates/pd_template");
 
 275         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "pd_Junit.json");
 
 276         requestInfo.put("RequestInfo", "testValue");
 
 277         requestInfo.put("request-id","testREQUEST_ID");
 
 278         input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo);
 
 279         input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo);
 
 280         postData.put("input", input);
 
 281         inParams.put("postData", postData.toString());
 
 282         artifactHandlerNode.processArtifact(inParams, ctx);
 
 283         Mockito.verify(dbServiceMock, Mockito.times(2)).initialise();
 
 286     private JSONObject getDocumentInfo(String filename) throws IOException {
 
 287         JSONObject documentInfo = new JSONObject();
 
 288         String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader()
 
 289                 .getResourceAsStream(filename), Charset.defaultCharset());
 
 290         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent);
 
 291         documentInfo.put(SdcArtifactHandlerConstants.SERVICE_UUID, "12345");
 
 292         documentInfo.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "12345");
 
 293         documentInfo.put(SdcArtifactHandlerConstants.SERVICE_NAME, "12345");
 
 294         documentInfo.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "12345");
 
 295         documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "12345");        
 
 296         documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "12345");
 
 297         documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_VERSION, "12345");
 
 298         documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "12345");
 
 299         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "12345");
 
 300         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_TYPE, "12345");
 
 301         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_VERSION, "12345");
 
 302         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "12345");
 
 308     public void testValidateAnsibleAdminArtifact() throws Exception {
 
 309         String contentStr = "{\"fqdn-list\":[{\"vnf-management-server-fqdn\":\"fqdn-value1 url:port\",\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\","
 
 310           + "\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]},{\"region-id\":\"san4b\","
 
 311           + "\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]}]},{\"cloud-owner\":\"nc1.0\",\"region-id-list\":[{\"region-id\":\"san4a\","
 
 312           + "\"tenant-id-list\":[\"tenantuuid3\",\"tenantuuid4\"]}]}],\"description\":\"fqdn for east zone Production\",\"username\":\"attuid\","
 
 313           + "\"create-date\":\"\",\"modify-username\":\"\",\"modify-date\":\"\"},{\"vnf-management-server-fqdn\":\"fqdn-value2 url:port\","
 
 314           + "\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\",\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid5\","
 
 315           + "\"tenantuuid6\"]},{\"region-id\":\"san4b\",\"tenant-id-list\":[\"tenantuuid5\",\"tenantuuid6\"]}]},{\"cloud-owner\":\"nc1.0\","
 
 316           + "\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid7\",\"tenantuuid8\"]}]}],"
 
 317           + "\"description\":\"fqdn for east zone Test\",\"username\":\"attuid\",\"create-date\":\"\","
 
 318           + "\"modify-username\":\"\",\"modify-date\":\"\"}]}";
 
 320         JSONObject documentInfo = new JSONObject();       
 
 321         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, contentStr);
 
 322         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "ansible_admin_FQDN_Artifact_0.0.1V.json");
 
 323         artifactHandlerNode.validateAnsibleAdminArtifact(documentInfo);
 
 327     public void testValidateAnsibleAdminArtifactWithException() throws Exception {
 
 328        String contentStrOne = "{\"fqdn-list\":[{\"vnf-management-server-fqdn\":\"fqdn-value1 url:port\",\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\","
 
 329          + "\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]},{\"region-id\":\"san4b\","
 
 330          + "\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]}]},{\"cloud-owner\":\"nc1.0\",\"region-id-list\":[{\"region-id\":\"san4a\","
 
 331          + "\"tenant-id-list\":[\"tenantuuid3\",\"tenantuuid4\"]}]}],\"description\":\"fqdn for east zone Production\",\"username\":\"attuid\","
 
 332          + "\"create-date\":\"\",\"modify-username\":\"\",\"modify-date\":\"\"},{\"vnf-management-server-fqdn\":\"fqdn-value2 url:port\","
 
 333          + "\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\",\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid1\","
 
 334          + "\"tenantuuid6\"]},{\"region-id\":\"san4b\",\"tenant-id-list\":[\"tenantuuid5\",\"tenantuuid6\"]}]},{\"cloud-owner\":\"nc1.0\","
 
 335          + "\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid7\",\"tenantuuid8\"]}]}],"
 
 336          + "\"description\":\"fqdn for east zone Test\",\"username\":\"attuid\",\"create-date\":\"\","
 
 337          + "\"modify-username\":\"\",\"modify-date\":\"\"}]}";
 
 338        JSONObject documentInfoOne = new JSONObject();       
 
 339        documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, contentStrOne);
 
 340        documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "ansible_admin_FQDN_Artifact_0.0.1V.json");
 
 343            artifactHandlerNode.validateAnsibleAdminArtifact(documentInfoOne);
 
 344            fail("Missing exception");
 
 345            }catch(ArtifactHandlerInternalException e) {
 
 346             assertTrue(e.getMessage().contains("Validation Failure"));
 
 352     public void testValidateAnsibleAdminArtifactWithJSONException() throws Exception {
 
 353         String contentStrOne = "{\"fqdn-list\":[{\"vnf-management-server-fqdn\":\"fqdn-value1 url:port\",\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\"}";           
 
 355         JSONObject documentInfoOne = new JSONObject();       
 
 356         documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, contentStrOne);
 
 357         documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "ansible_admin_FQDN_Artifact_0.0.1V.json");
 
 360             artifactHandlerNode.validateAnsibleAdminArtifact(documentInfoOne);
 
 361             fail("Missing exception");
 
 362         }catch(ArtifactHandlerInternalException je) {
 
 363           assertTrue(je.getMessage().contains("JSON Exception"));
 
 370     public void testProcessArtifactWithException() throws Exception {
 
 371         SvcLogicContext ctx = new SvcLogicContext();
 
 372         ctx.setAttribute("test", "test");
 
 373         Map<String, String> inParams = new HashMap<>();
 
 374         JSONObject postData = new JSONObject();
 
 375         JSONObject input = new JSONObject();
 
 376         inParams.put("response_prefix", "prefix");
 
 377         JSONObject requestInfo = new JSONObject();
 
 378         JSONObject documentInfo = new JSONObject();
 
 379         String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader()
 
 380                 .getResourceAsStream("templates/reference_template"), Charset.defaultCharset());
 
 381         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent);
 
 382         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "");
 
 383         requestInfo.put("RequestInfo", "testValue");
 
 384         requestInfo.put("request-id","testREQUEST_ID");
 
 385         input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo);
 
 386         input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo);
 
 387         postData.put("input", input);
 
 388         inParams.put("postData", postData.toString());
 
 390             artifactHandlerNode.processArtifact(inParams, ctx);
 
 391             fail("Missing exception");
 
 392         }catch(Exception e) {
 
 393           assertTrue(e.getMessage().contains("Missing Artifact Name"));
 
 398     public void testProcessArtifactWithExceptionforAnsible() throws Exception {
 
 399         SvcLogicContext ctx = new SvcLogicContext();
 
 400         ctx.setAttribute("test", "test");
 
 401         Map<String, String> inParams = new HashMap<>();
 
 402         JSONObject postData = new JSONObject();
 
 403         JSONObject input = new JSONObject();
 
 404         inParams.put("response_prefix", "prefix");
 
 405         JSONObject requestInfo = new JSONObject();
 
 406         JSONObject documentInfo = new JSONObject();
 
 407         String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader()
 
 408                 .getResourceAsStream("templates/reference_template"), Charset.defaultCharset());
 
 409         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent);
 
 410         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "ansible_admin_FQDN_Artifact_0.0.2V.json");
 
 411         requestInfo.put("RequestInfo", "testValue");
 
 412         requestInfo.put("request-id","testREQUEST_ID");
 
 413         input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo);
 
 414         input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo);
 
 415         postData.put("input", input);
 
 416         inParams.put("postData", postData.toString());
 
 419              artifactHandlerNode.processArtifact(inParams, ctx);
 
 420              fail("Missing exception");
 
 421         }catch(Exception e) {
 
 422            assertTrue(e.getMessage().contains("JSON Exception:ansible admin"));
 
 427     public void testProcessAndStoreCapablitiesArtifact() throws Exception {
 
 428         ArtifactHandlerNode ah = new ArtifactHandlerNode();
 
 429         JSONObject capabilities = new JSONObject();
 
 430         JSONObject documentInfo = new JSONObject();
 
 431         MockDBService dbService = MockDBService.initialise();
 
 432         documentInfo.put(SdcArtifactHandlerConstants.SERVICE_UUID, "testuid");
 
 433         documentInfo.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "testDist");
 
 434         documentInfo.put(SdcArtifactHandlerConstants.SERVICE_NAME, "testName");
 
 435         documentInfo.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "testDesc");
 
 436         documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "testRes");
 
 437         documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "testResIns");
 
 438         documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_VERSION, "testVers");
 
 439         documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "testResType");
 
 440         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "testArtifactUuid");
 
 441         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_VERSION, "testArtifactVers");
 
 442         documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "testArtifactDesc");
 
 443         Whitebox.invokeMethod(ah, "processAndStoreCapabilitiesArtifact", dbService, documentInfo, capabilities,
 
 444                 "artifactName", "someVnf");