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.onap.appc.artifact.handler.node;
27 import java.nio.charset.Charset;
29 import org.apache.commons.io.IOUtils;
30 import org.json.JSONObject;
31 import org.junit.Ignore;
32 import org.junit.Test;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 import org.powermock.reflect.Whitebox;
35 import static org.junit.Assert.assertTrue;
37 import org.onap.appc.artifact.handler.dbservices.MockDBService;
38 import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants;
39 import org.onap.appc.artifact.handler.utils.ArtifactHandlerProviderUtilTest;
42 import java.util.HashMap;
44 public class ArtifactHandlerNodeTest {
47 public void testProcessArtifact() throws Exception {
48 SvcLogicContext ctx = new SvcLogicContext();
49 ctx.setAttribute("test", "test");
50 MockArtifactHandlerNode ah = new MockArtifactHandlerNode();
51 Map<String, String> inParams = new HashMap<String, String>();
52 JSONObject postData = new JSONObject();
53 JSONObject input = new JSONObject();
54 inParams.put("response_prefix", "prefix");
55 JSONObject requestInfo = new JSONObject();
56 JSONObject documentInfo = new JSONObject();
57 String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader()
58 .getResourceAsStream("templates/reference_template"), Charset.defaultCharset());
59 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent);
60 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json");
61 requestInfo.put("RequestInfo", "testValue");
62 input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo);
63 input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo);
64 postData.put("input", input);
65 inParams.put("postData", postData.toString());
66 ah.processArtifact(inParams, ctx);
69 @Ignore("Test is taking 60 seconds")
70 @Test(expected = Exception.class)
71 public void testStoreReferenceData() throws Exception {
72 MockArtifactHandlerNode ah = new MockArtifactHandlerNode();
73 JSONObject documentInfo = new JSONObject();
74 String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader()
75 .getResourceAsStream("templates/reference_template"), Charset.defaultCharset());
76 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent);
77 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json");
78 JSONObject requestInfo = new JSONObject();
79 requestInfo.put("RequestInfo", "testStoreReferenceData");
80 ah.storeReferenceData(requestInfo, documentInfo);
84 public void testPopulateProtocolReference() throws Exception {
85 ArtifactHandlerNode ah = new ArtifactHandlerNode();
87 "{\"action\": \"TestAction\",\"action-level\": \"vnf\",\"scope\": {\"vnf-type\": \"vDBE-I\",\"vnfc-type\": null},\"template\": \"N\",\"device-protocol\": \"REST\"}";
88 JSONObject content = new JSONObject(contentStr);
89 MockDBService dbService = MockDBService.initialise();
90 Whitebox.invokeMethod(ah, "populateProtocolReference", dbService, content);
94 public void testProcessAndStoreCapablitiesArtifact() throws Exception {
95 ArtifactHandlerNode ah = new ArtifactHandlerNode();
96 JSONObject capabilities = new JSONObject();
97 JSONObject documentInfo = new JSONObject();
98 MockDBService dbService = MockDBService.initialise();
99 documentInfo.put(SdcArtifactHandlerConstants.SERVICE_UUID, "testuid");
100 documentInfo.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "testDist");
101 documentInfo.put(SdcArtifactHandlerConstants.SERVICE_NAME, "testName");
102 documentInfo.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "testDesc");
103 documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "testRes");
104 documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "testResIns");
105 documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_VERSION, "testVers");
106 documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "testResType");
107 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "testArtifactUuid");
108 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_VERSION, "testArtifactVers");
109 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "testArtifactDesc");
110 Whitebox.invokeMethod(ah, "processAndStoreCapablitiesArtifact", dbService, documentInfo, capabilities,
111 "artifactName", "someVnf");
115 public void testCleanVnfcInstance() throws Exception {
116 ArtifactHandlerNode ah = new ArtifactHandlerNode();
117 SvcLogicContext ctx = new SvcLogicContext();
118 Whitebox.invokeMethod(ah, "cleanVnfcInstance", ctx);
122 @Ignore("Test is taking 60 seconds")
123 @Test(expected = Exception.class)
124 public void testGetArtifactIDException() throws Exception {
125 ArtifactHandlerNode ah = new ArtifactHandlerNode();
126 String yFileName = "yFileName";
127 Whitebox.invokeMethod(ah, "getArtifactID", yFileName);
130 @Ignore("Test is taking 60 seconds")
131 @Test(expected = Exception.class)
132 public void testStoreUpdateSdcArtifacts() throws Exception {
133 ArtifactHandlerNode ah = new ArtifactHandlerNode();
135 "{\"request-information\":{},\"document-parameters\":{\"artifact-name\":\"testArtifact\",\"artifact-contents\":{\"content\":\"TestContent\"}}}";
136 JSONObject postData = new JSONObject(postDataStr);
137 Whitebox.invokeMethod(ah, "storeUpdateSdcArtifacts", postData);
140 @Ignore("Test is taking 60 seconds")
141 @Test(expected = Exception.class)
142 public void testUpdateStoreArtifacts() throws Exception {
143 MockArtifactHandlerNode ah = new MockArtifactHandlerNode();
144 JSONObject documentInfo = new JSONObject();
145 String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader()
146 .getResourceAsStream("templates/reference_template"), Charset.defaultCharset());
147 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent);
148 documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json");
149 JSONObject requestInfo = new JSONObject();
150 requestInfo.put("RequestInfo", "testupdateStoreArtifacts");
151 ah.updateStoreArtifacts(requestInfo, documentInfo);
155 public void testCleanArtifactInstanceData() throws Exception {
156 MockArtifactHandlerNode ah = new MockArtifactHandlerNode();
157 SvcLogicContext ctx = new SvcLogicContext();
158 Whitebox.invokeMethod(ah, "cleanArtifactInstanceData", ctx);
161 @Ignore("Test is taking 60 seconds")
162 @Test(expected = Exception.class)
163 public void testUpdateYangContents() throws Exception {
164 MockArtifactHandlerNode ah = new MockArtifactHandlerNode();
165 String artifactId = "1";
166 String yangContents = "SomeContent";
167 Whitebox.invokeMethod(ah, "updateYangContents", artifactId, yangContents);