First part of onap rename
[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.onap.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.Ignore;
35 import org.junit.Test;
36 import org.onap.appc.design.dbervices.DbService;
37 import org.onap.appc.design.dbervices.DesignDBService;
38 import org.onap.appc.design.propertyServices.PropertyUpdateService;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import junit.framework.Assert;
42 import org.powermock.reflect.Whitebox;
43
44 public class TestDBService {
45
46     private final org.slf4j.Logger logger = LoggerFactory.getLogger(TestDBService.class);
47
48     @Ignore("Test is taking 60 seconds")
49     @Test
50     public void testGetDesigns() {
51         try {
52             String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\" }";
53             DesignDBService dbservice = DesignDBService.initialise();
54             dbservice.execute("getDesigns", payload, "1234");
55         } catch (Exception e) {
56         }
57     }
58
59     @Ignore("Test is taking 120 seconds")
60     @Test
61     public void testGetStatus() {
62         try {
63             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
64             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 + " } ";
65             DesignDBService dbservice = DesignDBService.initialise();
66             DbService db = new DbService();
67             Whitebox.invokeMethod(db, "getDbLibService");
68             dbservice.execute("getStatus", payload, "1234");
69         } catch (Exception e) {
70         }
71     }
72
73     @Ignore("Test is taking 120 seconds")
74     @Test
75     public void testUploadArtifact() {
76         try {
77             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
78             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 + " } ";
79             DesignDBService dbservice = DesignDBService.initialise();
80             DbService db = new DbService();
81             Whitebox.invokeMethod(db, "getDbLibService");
82             dbservice.execute("uploadArtifact", payload, "1234");
83         } catch (Exception e) {
84         }
85     }
86
87     @Ignore("Test is taking 120 seconds")
88     @Test
89     public void testGetArtifact() {
90         try {
91             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
92             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 + " } ";
93             DesignDBService design = DesignDBService.initialise();
94             DbService db = new DbService();
95             Whitebox.invokeMethod(db, "getDbLibService");
96             design.execute("getArtifact", payload, "1234");
97         } catch (Exception e) {
98         }
99     }
100
101     @Ignore("Test is taking 120 seconds")
102     @Test
103     public void testSetIncart() {
104         try {
105             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
106             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 + " } ";
107             DesignDBService design = DesignDBService.initialise();
108             DbService db = new DbService();
109             Whitebox.invokeMethod(db, "getDbLibService");
110             design.execute("setInCart", payload, "1234");
111         } catch (Exception e) {
112         }
113     }
114
115     @Ignore("Test is taking 120 seconds")
116     @Test
117     public void testSetProtocolReference() {
118         try {
119             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
120             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 + " } ";
121             DesignDBService design = DesignDBService.initialise();
122             DbService db = new DbService();
123             Whitebox.invokeMethod(db, "getDbLibService");
124             design.execute("setProtocolReference", payload, "1234");
125         } catch (Exception e) {
126         }
127     }
128
129     @Ignore("Test is taking 120 seconds")
130     @Test
131     public void testSetStatus() {
132         try {
133             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
134             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 + " } ";
135             DesignDBService design = DesignDBService.initialise();
136             DbService db = new DbService();
137             Whitebox.invokeMethod(db, "getDbLibService");
138             design.execute("setStatus", payload, "1234");
139         } catch (Exception e) {
140         }
141     }
142
143     @Ignore("Test is taking 120 seconds")
144     @Test
145     public void testGetArtifactReference() {
146         try {
147             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
148             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 + " } ";
149             DesignDBService design = DesignDBService.initialise();
150             DbService db = new DbService();
151             Whitebox.invokeMethod(db, "getDbLibService");
152             design.execute("getArtifactReference", payload, "1234");
153         } catch (Exception e) {
154         }
155     }
156
157     @Ignore("Test is taking 120 seconds")
158     @Test
159     public void testGetGuiReference() {
160         try {
161             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
162             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 + " } ";
163             DesignDBService design = DesignDBService.initialise();
164             DbService db = new DbService();
165             Whitebox.invokeMethod(db, "getDbLibService");
166             design.execute("getGuiReference", payload, "1234");
167         } catch (Exception e) {
168         }
169     }
170
171     @Test
172     public void testPropertyUpdateService() {
173         PropertyUpdateService ps = new PropertyUpdateService();
174     }
175
176     @Test
177     public void testLinkstatusRelationShip() {        
178         try {
179             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
180             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 + " } ";
181             DesignDBService design = DesignDBService.initialise();
182             Whitebox.invokeMethod(design, "linkstatusRelationShip", 1, 1, payload);
183         } catch (Exception e) {
184         }
185     }
186
187     @Test
188     public void testGetSDCReferenceID() {
189         
190         try {
191             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
192             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 + " } ";
193             DesignDBService design = DesignDBService.initialise();
194             Whitebox.invokeMethod(design, "getSDCReferenceID", payload);
195         } catch (Exception e) {
196         }
197     }
198
199     @Test
200     public void testGetDataFromActionStatus() {        
201         try {
202             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
203             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 + " } ";
204             DesignDBService design = DesignDBService.initialise();
205             Whitebox.invokeMethod(design, "getDataFromActionStatus", payload, "Test");
206         } catch (Exception e) {
207         }
208     }
209
210     @Test
211     public void testSetActionStatus() {
212         try {
213             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
214             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 + " } ";
215             DesignDBService design = DesignDBService.initialise();
216             Whitebox.invokeMethod(design, "setActionStatus", payload, "Accepted");
217         } catch (Exception e) {
218         }
219     }
220         
221     @Test
222     public void testGetSDCArtifactIDbyRequestID() {
223         try {
224             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
225             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 + " } ";
226             DesignDBService design = DesignDBService.initialise();
227             Whitebox.invokeMethod(design, "getSDCArtifactIDbyRequestID", "0");
228         } catch (Exception e) {
229         }
230     }
231
232     @Test
233     public void testCreateArtifactTrackingRecord() {
234             try {
235             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
236             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 + " } ";
237             DesignDBService design = DesignDBService.initialise();
238             Whitebox.invokeMethod(design, "createArtifactTrackingRecord",payload,"0",1,1);
239         } catch (Exception e) {
240         }
241     }
242 }