Tests for appc-inbound/design-services
[appc.git] / appc-inbound / appc-design-services / provider / src / test / java / org / onap / appc / design / validator / TestDBService.java
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  * Copyright (C) 2018 IBM
10  * =============================================================================
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  * 
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  * 
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  * 
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.appc.design.validator;
27
28 import static org.junit.Assert.assertTrue;
29
30 import java.io.File;
31 import java.io.InputStream;
32 import java.util.ArrayList;
33 import java.util.Enumeration;
34 import java.util.Properties;
35 import org.apache.commons.io.FileUtils;
36 import org.junit.Before;
37 import org.junit.Ignore;
38 import org.junit.Test;
39 import org.onap.appc.design.dbervices.DbService;
40 import org.onap.appc.design.dbervices.DesignDBService;
41 import org.onap.appc.design.propertyServices.PropertyUpdateService;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44 import junit.framework.Assert;
45 import org.powermock.reflect.Whitebox;
46
47 public class TestDBService {
48
49     private final org.slf4j.Logger logger = LoggerFactory.getLogger(TestDBService.class);
50
51     @Ignore("Test is taking 60 seconds")
52     @Test
53     public void testGetDesigns() {
54         try {
55             String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\" }";
56             DesignDBService dbservice = DesignDBService.initialise();
57             dbservice.execute("getDesigns", payload, "1234");
58         } catch (Exception e) {
59         }
60     }
61
62     @Ignore("Test is taking 120 seconds")
63     @Test
64     public void testGetStatus() {
65         try {
66             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
67             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 + " } ";
68             DesignDBService dbservice = DesignDBService.initialise();
69             DbService db = new DbService();
70             Whitebox.invokeMethod(db, "getDbLibService");
71             dbservice.execute("getStatus", payload, "1234");
72         } catch (Exception e) {
73         }
74     }
75
76     @Ignore("Test is taking 120 seconds")
77     @Test
78     public void testUploadArtifact() {
79         try {
80             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
81             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 + " } ";
82             DesignDBService dbservice = DesignDBService.initialise();
83             DbService db = new DbService();
84             Whitebox.invokeMethod(db, "getDbLibService");
85             dbservice.execute("uploadArtifact", payload, "1234");
86         } catch (Exception e) {
87         }
88     }
89
90     @Ignore("Test is taking 120 seconds")
91     @Test
92     public void testGetArtifact() {
93         try {
94             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
95             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 + " } ";
96             DesignDBService design = DesignDBService.initialise();
97             DbService db = new DbService();
98             Whitebox.invokeMethod(db, "getDbLibService");
99             design.execute("getArtifact", payload, "1234");
100         } catch (Exception e) {
101         }
102     }
103
104     @Ignore("Test is taking 120 seconds")
105     @Test
106     public void testSetIncart() {
107         try {
108             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
109             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 + " } ";
110             DesignDBService design = DesignDBService.initialise();
111             DbService db = new DbService();
112             Whitebox.invokeMethod(db, "getDbLibService");
113             design.execute("setInCart", payload, "1234");
114         } catch (Exception e) {
115         }
116     }
117
118     @Ignore("Test is taking 120 seconds")
119     @Test
120     public void testSetProtocolReference() {
121         try {
122             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
123             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 + " } ";
124             DesignDBService design = DesignDBService.initialise();
125             DbService db = new DbService();
126             Whitebox.invokeMethod(db, "getDbLibService");
127             design.execute("setProtocolReference", payload, "1234");
128         } catch (Exception e) {
129         }
130     }
131
132     @Ignore("Test is taking 120 seconds")
133     @Test
134     public void testSetStatus() {
135         try {
136             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
137             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 + " } ";
138             DesignDBService design = DesignDBService.initialise();
139             DbService db = new DbService();
140             Whitebox.invokeMethod(db, "getDbLibService");
141             design.execute("setStatus", payload, "1234");
142         } catch (Exception e) {
143         }
144     }
145
146     @Ignore("Test is taking 120 seconds")
147     @Test
148     public void testGetArtifactReference() {
149         try {
150             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
151             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 + " } ";
152             DesignDBService design = DesignDBService.initialise();
153             DbService db = new DbService();
154             Whitebox.invokeMethod(db, "getDbLibService");
155             design.execute("getArtifactReference", payload, "1234");
156         } catch (Exception e) {
157         }
158     }
159
160     @Ignore("Test is taking 120 seconds")
161     @Test
162     public void testGetGuiReference() {
163         try {
164             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
165             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 + " } ";
166             DesignDBService design = DesignDBService.initialise();
167             DbService db = new DbService();
168             Whitebox.invokeMethod(db, "getDbLibService");
169             design.execute("getGuiReference", payload, "1234");
170         } catch (Exception e) {
171         }
172     }
173
174     @Test
175     public void testPropertyUpdateService() {
176         PropertyUpdateService ps = new PropertyUpdateService();
177     }
178
179     @Test
180     public void testLinkstatusRelationShip() {        
181         try {
182             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
183             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 + " } ";
184             DesignDBService design = DesignDBService.initialise();
185             Whitebox.invokeMethod(design, "linkstatusRelationShip", 1, 1, payload);
186         } catch (Exception e) {
187         }
188     }
189
190     @Test
191     public void testGetSDCReferenceID() {
192         
193         try {
194             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
195             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 + " } ";
196             DesignDBService design = DesignDBService.initialise();
197             Whitebox.invokeMethod(design, "getSDCReferenceID", payload);
198         } catch (Exception e) {
199         }
200     }
201
202     @Test
203     public void testGetDataFromActionStatus() {        
204         try {
205             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
206             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 + " } ";
207             DesignDBService design = DesignDBService.initialise();
208             Whitebox.invokeMethod(design, "getDataFromActionStatus", payload, "Test");
209         } catch (Exception e) {
210         }
211     }
212
213     @Test
214     public void testSetActionStatus() {
215         try {
216             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
217             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 + " } ";
218             DesignDBService design = DesignDBService.initialise();
219             Whitebox.invokeMethod(design, "setActionStatus", payload, "Accepted");
220         } catch (Exception e) {
221         }
222     }
223         
224     @Test
225     public void testGetSDCArtifactIDbyRequestID() {
226         try {
227             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
228             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 + " } ";
229             DesignDBService design = DesignDBService.initialise();
230             Whitebox.invokeMethod(design, "getSDCArtifactIDbyRequestID", "0");
231         } catch (Exception e) {
232         }
233     }
234
235     @Test
236     public void testCreateArtifactTrackingRecord() {
237             try {
238             String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact"));
239             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 + " } ";
240             DesignDBService design = DesignDBService.initialise();
241             Whitebox.invokeMethod(design, "createArtifactTrackingRecord",payload,"0",1,1);
242         } catch (Exception e) {
243         }
244     }
245     @Test
246     public void testGetAppcTimestampUTC() throws Exception {
247              String requestId = "1234";
248              DesignDBService design = DesignDBService.initialise();
249              String result =  Whitebox.invokeMethod(design, "getAppcTimestampUTC",requestId);
250              assertTrue(result.endsWith("Z"));
251     }
252
253 }