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