2 * ============LICENSE_START=======================================================
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
15 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.design.validator;
28 import static org.junit.Assert.assertTrue;
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;
47 public class TestDBService {
49 private final org.slf4j.Logger logger = LoggerFactory.getLogger(TestDBService.class);
51 @Ignore("Test is taking 60 seconds")
53 public void testGetDesigns() {
55 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\" }";
56 DesignDBService dbservice = DesignDBService.initialise();
57 dbservice.execute("getDesigns", payload, "1234");
58 } catch (Exception e) {
62 @Ignore("Test is taking 120 seconds")
64 public void testGetStatus() {
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) {
76 @Ignore("Test is taking 120 seconds")
78 public void testUploadArtifact() {
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) {
90 @Ignore("Test is taking 120 seconds")
92 public void testGetArtifact() {
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) {
104 @Ignore("Test is taking 120 seconds")
106 public void testSetIncart() {
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) {
118 @Ignore("Test is taking 120 seconds")
120 public void testSetProtocolReference() {
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) {
132 @Ignore("Test is taking 120 seconds")
134 public void testSetStatus() {
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) {
146 @Ignore("Test is taking 120 seconds")
148 public void testGetArtifactReference() {
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) {
160 @Ignore("Test is taking 120 seconds")
162 public void testGetGuiReference() {
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) {
175 public void testPropertyUpdateService() {
176 PropertyUpdateService ps = new PropertyUpdateService();
180 public void testLinkstatusRelationShip() {
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) {
191 public void testGetSDCReferenceID() {
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) {
203 public void testGetDataFromActionStatus() {
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) {
214 public void testSetActionStatus() {
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) {
225 public void testGetSDCArtifactIDbyRequestID() {
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) {
236 public void testCreateArtifactTrackingRecord() {
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) {
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"));