First part of onap rename
[appc.git] / appc-config / appc-data-services / provider / src / test / java / org / onap / appc / data / services / db / TestDGGeneralDBService.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 package org.onap.appc.data.services.db;
25
26 import static org.junit.Assert.assertEquals;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.util.Enumeration;
30 import java.util.Properties;
31 import org.apache.commons.io.IOUtils;
32 import org.apache.commons.lang.StringEscapeUtils;
33 import org.junit.Test;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
37 import org.onap.appc.data.services.db.DGGeneralDBService;
38
39 public class TestDGGeneralDBService {
40     DGGeneralDBService dbService;
41     private static String STRING_ENCODING = "utf-8";
42
43     // @Before
44     public void setUp() {
45         Properties props = new Properties();
46         InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
47         if (propStr == null) {
48             System.err.println("src/test/resources/svclogic.properties missing");
49         }
50         try {
51             props.load(propStr);
52             propStr.close();
53         } catch (Exception e) {
54             e.printStackTrace();
55             System.err.println("Could not initialize properties");
56         }
57         // Add properties to global properties
58         Enumeration propNames = props.keys();
59         while (propNames.hasMoreElements()) {
60             String propName = (String) propNames.nextElement();
61             System.setProperty(propName, props.getProperty(propName));
62         }
63         dbService = DGGeneralDBService.initialise();
64     }
65
66     @Test(expected = Exception.class)
67     public void testGetUploadConfig() throws SvcLogicException {
68
69         SvcLogicContext ctx = new SvcLogicContext();
70         ctx.setAttribute("vnf-name", "test");
71         ctx.setAttribute("vnf-id", "test");
72         QueryStatus status = dbService.getUploadConfigInfo(ctx, "test");
73         assertEquals(status, "SUCCESS");
74
75     }
76
77     @Test(expected = Exception.class)
78     public void testGetDeviceProtocolByVnfType() throws SvcLogicException {
79         SvcLogicContext ctx = new SvcLogicContext();
80         ctx.setAttribute("vnf-type", "test");
81         QueryStatus status = dbService.getDeviceProtocolByVnfType(ctx, "test");
82         assertEquals(status, "SUCCESS");
83     }
84
85     @Test(expected = Exception.class)
86     public void testGettConfigFileReferenceByFileTypeNVnfType() throws SvcLogicException {
87         SvcLogicContext ctx = new SvcLogicContext();
88         ctx.setAttribute("vnf-type", "test");
89         QueryStatus status = dbService.getConfigFileReferenceByFileTypeNVnfType(ctx, "test", "device_configuration");
90         assertEquals(status, "SUCCESS");
91
92     }
93
94     @Test(expected = Exception.class)
95     public void testGetDeviceAuthenticationByVnfType() throws Exception {
96         SvcLogicContext ctx = new SvcLogicContext();
97         ctx.setAttribute("vnf-type", "test");
98         QueryStatus status = dbService.getDeviceAuthenticationByVnfType(ctx, "test");
99         assertEquals(status, "SUCCESS");
100
101     }
102
103     @Test(expected = Exception.class)
104     public void testGetTemplate() throws Exception {
105         SvcLogicContext ctx = new SvcLogicContext();
106         ctx.setAttribute("vnfc-type", "test");
107         ctx.setAttribute("request-action", "Configure");
108         QueryStatus status = dbService.getTemplate(ctx, "test", "config_template");
109         assertEquals(status, "SUCCESS");
110
111     }
112
113     @Test(expected = Exception.class)
114     public void testGetTemplateByVnfTypeNAction() throws Exception {
115         SvcLogicContext ctx = new SvcLogicContext();
116         ctx.setAttribute("vnf-type", "test");
117         ctx.setAttribute("request-action", "Configure");
118         QueryStatus status = dbService.getTemplateByVnfTypeNAction(ctx, "test", "config_template");
119         assertEquals(status, "SUCCESS");
120
121     }
122
123     @Test(expected = Exception.class)
124     public void testGetTemplateByTemplateName() throws Exception {
125         SvcLogicContext ctx = new SvcLogicContext();
126         ctx.setAttribute("request-action", "Configure");
127         ctx.setAttribute("vnf-type", "test");
128         QueryStatus status = dbService.getTemplateByTemplateName(ctx, "test", "template.json");
129         assertEquals(status, "SUCCESS");
130
131     }
132
133     @Test(expected = Exception.class)
134     public void testGetTemplateByVnfType() throws SvcLogicException {
135
136         SvcLogicContext ctx = new SvcLogicContext();
137         ctx.setAttribute("vnf-type", "test");
138         QueryStatus status = dbService.getTemplateByVnfType(ctx, "test", "config_template");
139         assertEquals(status, "SUCCESS");
140
141     }
142
143     @Test(expected = Exception.class)
144     public void testGetConfigureActionDGByVnfTypeNAction() throws SvcLogicException {
145
146         SvcLogicContext ctx = new SvcLogicContext();
147         ctx.setAttribute("vnf-type", "test");
148         ctx.setAttribute("request-action", "ConfigModify");
149         QueryStatus status = dbService.getConfigureActionDGByVnfTypeNAction(ctx, "test");
150         assertEquals(status, "SUCCESS");
151
152     }
153
154     @Test(expected = Exception.class)
155     public void testGetConfigureActionDGByVnfType() throws SvcLogicException {
156         SvcLogicContext ctx = new SvcLogicContext();
157         ctx.setAttribute("vnf-type", "test");
158         QueryStatus status = dbService.getConfigureActionDGByVnfType(ctx, "test");
159         assertEquals(status, "SUCCESS");
160
161     }
162
163     @Test(expected = Exception.class)
164     public void testGetMaxConfigFileId() throws SvcLogicException {
165
166         SvcLogicContext ctx = new SvcLogicContext();
167         ctx.setAttribute("vnf-id", "test");
168         ctx.setAttribute("vm-name", "test");
169         QueryStatus status = dbService.getMaxConfigFileId(ctx, "test", "device_configuration");
170         assertEquals(status, "SUCCESS");
171
172     }
173
174     @Test(expected = Exception.class)
175     public void testGetConfigFilesByVnfVmNCategory() throws SvcLogicException {
176
177         SvcLogicContext ctx = new SvcLogicContext();
178         ctx.setAttribute("vnf-id", "test");
179         ctx.setAttribute("vm-name", "test");
180         QueryStatus status = dbService.getConfigFilesByVnfVmNCategory(ctx, "test", "device_configuration", "test",
181                 "ibcx0001vm001");
182         assertEquals(status, "SUCCESS");
183
184     }
185
186     @Test(expected = Exception.class)
187     public void testGetDownloadConfigTemplateByVnf() throws SvcLogicException {
188
189         SvcLogicContext ctx = new SvcLogicContext();
190         ctx.setAttribute("vnf-type", "test");
191         QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test");
192         assertEquals(status, "SUCCESS");
193     }
194
195     @Test(expected = Exception.class)
196     public void testSaveConfigTxLog() throws SvcLogicException, IOException {
197
198         SvcLogicContext ctx = new SvcLogicContext();
199         String message = IOUtils.toString(
200                 TestDGGeneralDBService.class.getClassLoader().getResourceAsStream("query/message3.txt"),
201                 STRING_ENCODING);
202         ctx.setAttribute("request-id", "1234");
203         String escapedMessage = StringEscapeUtils.escapeSql(message);
204         ctx.setAttribute("log-message", escapedMessage);
205         ctx.setAttribute("log-message-type", "request");
206         QueryStatus status = dbService.saveConfigTransactionLog(ctx, "test");
207         assertEquals(status, "SUCCESS");
208     }
209
210 }