Added New Junit Cases for APPC Design Services
[appc.git] / appc-inbound / appc-design-services / provider / src / test / java / org / openecomp / appc / design / validator / TestDBService.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.design.validator;
26
27 import java.io.File;
28 import java.io.InputStream;
29 import java.util.ArrayList;
30 import java.util.Enumeration;
31 import java.util.Properties;
32 import org.apache.commons.io.FileUtils;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.openecomp.appc.design.dbervices.DbService;
36 import org.openecomp.appc.design.dbervices.DesignDBService;
37 import org.openecomp.appc.design.propertyServices.PropertyUpdateService;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import junit.framework.Assert;
41 import org.powermock.reflect.Whitebox;
42
43 public class TestDBService {
44
45     private final org.slf4j.Logger logger = LoggerFactory.getLogger(TestDBService.class);
46
47     @Test
48     public void testGetDesigns() {
49         try {
50             String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\" }";
51             DesignDBService dbservice = DesignDBService.initialise();
52             dbservice.execute("getDesigns", payload, "1234");
53         } catch (Exception e) {
54         }
55     }
56
57     @Test
58     public void testGetStatus() {
59         try {
60             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
61             String payload = " { \"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\":  "+ content + " } ";
62             DesignDBService dbservice = DesignDBService.initialise();
63             DbService db = new DbService();
64             Whitebox.invokeMethod(db, "getDbLibService");
65             dbservice.execute("getStatus", payload, "1234");
66         } catch (Exception e) {
67         }
68     }
69
70     @Test
71     public void testUploadArtifact() {
72         try {
73             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
74             String payload = " { \"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\":  "+ content + " } ";
75             DesignDBService dbservice = DesignDBService.initialise();
76             DbService db = new DbService();
77             Whitebox.invokeMethod(db, "getDbLibService");
78             dbservice.execute("uploadArtifact", payload, "1234");
79         } catch (Exception e) {
80         }
81     }
82
83     @Test
84     public void testGetArtifact() {
85         try {
86             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
87             String payload = " { \"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\":  "+ content + " } ";
88             DesignDBService design = DesignDBService.initialise();
89             DbService db = new DbService();
90             Whitebox.invokeMethod(db, "getDbLibService");
91             design.execute("getArtifact", payload, "1234");
92         } catch (Exception e) {
93         }
94     }
95
96     @Test
97     public void testSetIncart() {
98         try {
99             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
100             String payload = " { \"userID\": \"0000\",\"action-level\":\"VNf\",\"protocol\":\"Test\", \"inCart\":\"Y\",\"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\":  "+ content + " } ";
101             DesignDBService design = DesignDBService.initialise();
102             DbService db = new DbService();
103             Whitebox.invokeMethod(db, "getDbLibService");
104             design.execute("setInCart", payload, "1234");
105         } catch (Exception e) {
106         }
107     }
108
109     @Test
110     public void testSetProtocolReference() {
111         try {
112             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
113             String payload = " { \"userID\": \"0000\",\"action-level\":\"VNf\",\"protocol\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\":  "+ content + " } ";
114             DesignDBService design = DesignDBService.initialise();
115             DbService db = new DbService();
116             Whitebox.invokeMethod(db, "getDbLibService");
117             design.execute("setProtocolReference", payload, "1234");
118         } catch (Exception e) {
119         }
120     }
121
122     @Test
123     public void testSetStatus() {
124         try {
125             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
126             String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\":  "+ content + " } ";
127             DesignDBService design = DesignDBService.initialise();
128             DbService db = new DbService();
129             Whitebox.invokeMethod(db, "getDbLibService");
130             design.execute("setStatus", payload, "1234");
131         } catch (Exception e) {
132         }
133     }
134
135     @Test
136     public void testGetArtifactReference() {
137         try {
138             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
139             String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\":  "+ content + " } ";
140             DesignDBService design = DesignDBService.initialise();
141             DbService db = new DbService();
142             Whitebox.invokeMethod(db, "getDbLibService");
143             design.execute("getArtifactReference", payload, "1234");
144         } catch (Exception e) {
145         }
146     }
147
148     @Test
149     public void testGetGuiReference() {
150         try {
151             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
152             String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\":  "+ content + " } ";
153             DesignDBService design = DesignDBService.initialise();
154             DbService db = new DbService();
155             Whitebox.invokeMethod(db, "getDbLibService");
156             design.execute("getGuiReference", payload, "1234");
157         } catch (Exception e) {
158         }
159     }
160
161     @Test
162     public void testPropertyUpdateService() {
163         PropertyUpdateService ps = new PropertyUpdateService();
164     }
165
166     @Test
167     public void testLinkstatusRelationShip() {        
168         try {
169             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
170             String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\":  "+ content + " } ";
171             DesignDBService design = DesignDBService.initialise();
172             Whitebox.invokeMethod(design, "linkstatusRelationShip", 1, 1, payload);
173         } catch (Exception e) {
174         }
175     }
176
177     @Test
178     public void testGetASDCReferenceID() {
179         
180         try {
181             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
182             String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\":  "+ content + " } ";
183             DesignDBService design = DesignDBService.initialise();
184             Whitebox.invokeMethod(design, "getASDCReferenceID", payload);
185         } catch (Exception e) {
186         }
187     }
188
189     @Test
190     public void testGetDataFromActionStatus() {        
191         try {
192             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
193             String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\":  "+ content + " } ";
194             DesignDBService design = DesignDBService.initialise();
195             Whitebox.invokeMethod(design, "getDataFromActionStatus", payload, "Test");
196         } catch (Exception e) {
197         }
198     }
199
200     @Test
201     public void testSetActionStatus() {
202         try {
203             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
204             String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\":  "+ content + " } ";
205             DesignDBService design = DesignDBService.initialise();
206             Whitebox.invokeMethod(design, "setActionStatus", payload, "Accepted");
207         } catch (Exception e) {
208         }
209     }
210         
211     @Test
212     public void testGetASDCArtifactIDbyRequestID() {
213         try {
214             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
215             String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\":  "+ content + " } ";
216             DesignDBService design = DesignDBService.initialise();
217             Whitebox.invokeMethod(design, "getASDCArtifactIDbyRequestID", "0");
218         } catch (Exception e) {
219         }
220     }
221
222     @Test
223     public void testCreateArtifactTrackingRecord() {
224             try {
225             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
226             String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\":  "+ content + " } ";
227             DesignDBService design = DesignDBService.initialise();
228             Whitebox.invokeMethod(design, "createArtifactTrackingRecord",payload,"0",1,1);
229         } catch (Exception e) {
230         }
231     }
232 }