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