6a90a7e779cc1ccada032b3fd231be436d25bfdb
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.artifact.handler.node;
26
27 import java.nio.charset.Charset;
28
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;
36
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;
40
41 import java.util.Map;
42 import java.util.HashMap;
43
44 public class ArtifactHandlerNodeTest {
45
46     @Test
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);
67     }
68
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);
81     }
82
83     @Test
84     public void testPopulateProtocolReference() throws Exception {
85         ArtifactHandlerNode ah = new ArtifactHandlerNode();
86         String contentStr =
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);
91     }
92
93     @Test
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");
112     }
113
114     @Test
115     public void testCleanVnfcInstance() throws Exception {
116         ArtifactHandlerNode ah = new ArtifactHandlerNode();
117         SvcLogicContext ctx = new SvcLogicContext();
118         Whitebox.invokeMethod(ah, "cleanVnfcInstance", ctx);
119         assertTrue(true);
120     }
121
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);
128     }
129
130     @Ignore("Test is taking 60 seconds")
131     @Test(expected = Exception.class)
132     public void testStoreUpdateSdcArtifacts() throws Exception {
133         ArtifactHandlerNode ah = new ArtifactHandlerNode();
134         String postDataStr =
135                 "{\"request-information\":{},\"document-parameters\":{\"artifact-name\":\"testArtifact\",\"artifact-contents\":{\"content\":\"TestContent\"}}}";
136         JSONObject postData = new JSONObject(postDataStr);
137         Whitebox.invokeMethod(ah, "storeUpdateSdcArtifacts", postData);
138     }
139
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);
152     }
153
154     @Test
155     public void testCleanArtifactInstanceData() throws Exception {
156         MockArtifactHandlerNode ah = new MockArtifactHandlerNode();
157         SvcLogicContext ctx = new SvcLogicContext();
158         Whitebox.invokeMethod(ah, "cleanArtifactInstanceData", ctx);
159     }
160
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);
168     }
169     
170 }