2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.design.validator;
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;
43 public class TestDBService {
45 private final org.slf4j.Logger logger = LoggerFactory.getLogger(TestDBService.class);
48 public void testGetDesigns() {
50 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\" }";
51 DesignDBService dbservice = DesignDBService.initialise();
52 dbservice.execute("getDesigns", payload, "1234");
53 } catch (Exception e) {
58 public void testGetStatus() {
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) {
71 public void testUploadArtifact() {
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) {
84 public void testGetArtifact() {
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) {
97 public void testSetIncart() {
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) {
110 public void testSetProtocolReference() {
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) {
123 public void testSetStatus() {
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) {
136 public void testGetArtifactReference() {
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) {
149 public void testGetGuiReference() {
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) {
162 public void testPropertyUpdateService() {
163 PropertyUpdateService ps = new PropertyUpdateService();
167 public void testLinkstatusRelationShip() {
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) {
178 public void testGetSDCReferenceID() {
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, "getSDCReferenceID", payload);
185 } catch (Exception e) {
190 public void testGetDataFromActionStatus() {
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) {
201 public void testSetActionStatus() {
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) {
212 public void testGetSDCArtifactIDbyRequestID() {
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, "getSDCArtifactIDbyRequestID", "0");
218 } catch (Exception e) {
223 public void testCreateArtifactTrackingRecord() {
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) {