summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestDGGeneralDBService.java
blob: d64f15cbe10bb8a3bae1d1a90a62c611de56ee00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*-
 * ============LICENSE_START=======================================================
 * ONAP : APPC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Copyright (C) 2017 Amdocs
 * =============================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 * ============LICENSE_END=========================================================
 */
package org.openecomp.appc.data.services.db;

import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.junit.Test;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
import org.openecomp.appc.data.services.db.DGGeneralDBService;

public class TestDGGeneralDBService {
    DGGeneralDBService dbService;
    private static String STRING_ENCODING = "utf-8";

    // @Before
    public void setUp() {
        Properties props = new Properties();
        InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
        if (propStr == null) {
            System.err.println("src/test/resources/svclogic.properties missing");
        }
        try {
            props.load(propStr);
            propStr.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("Could not initialize properties");
        }
        // Add properties to global properties
        Enumeration propNames = props.keys();
        while (propNames.hasMoreElements()) {
            String propName = (String) propNames.nextElement();
            System.setProperty(propName, props.getProperty(propName));
        }
        dbService = DGGeneralDBService.initialise();
    }

    @Test(expected = Exception.class)
    public void testGetUploadConfig() throws SvcLogicException {

        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("vnf-name", "test");
        ctx.setAttribute("vnf-id", "test");
        QueryStatus status = dbService.getUploadConfigInfo(ctx, "test");
        assertEquals(status, "SUCCESS");

    }

    @Test(expected = Exception.class)
    public void testGetDeviceProtocolByVnfType() throws SvcLogicException {
        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("vnf-type", "test");
        QueryStatus status = dbService.getDeviceProtocolByVnfType(ctx, "test");
        assertEquals(status, "SUCCESS");
    }

    @Test(expected = Exception.class)
    public void testGettConfigFileReferenceByFileTypeNVnfType() throws SvcLogicException {
        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("vnf-type", "test");
        QueryStatus status = dbService.getConfigFileReferenceByFileTypeNVnfType(ctx, "test", "device_configuration");
        assertEquals(status, "SUCCESS");

    }

    @Test(expected = Exception.class)
    public void testGetDeviceAuthenticationByVnfType() throws Exception {
        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("vnf-type", "test");
        QueryStatus status = dbService.getDeviceAuthenticationByVnfType(ctx, "test");
        assertEquals(status, "SUCCESS");

    }

    @Test(expected = Exception.class)
    public void testGetTemplate() throws Exception {
        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("vnfc-type", "test");
        ctx.setAttribute("request-action", "Configure");
        QueryStatus status = dbService.getTemplate(ctx, "test", "config_template");
        assertEquals(status, "SUCCESS");

    }

    @Test(expected = Exception.class)
    public void testGetTemplateByVnfTypeNAction() throws Exception {
        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("vnf-type", "test");
        ctx.setAttribute("request-action", "Configure");
        QueryStatus status = dbService.getTemplateByVnfTypeNAction(ctx, "test", "config_template");
        assertEquals(status, "SUCCESS");

    }

    @Test(expected = Exception.class)
    public void testGetTemplateByTemplateName() throws Exception {
        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("request-action", "Configure");
        ctx.setAttribute("vnf-type", "test");
        QueryStatus status = dbService.getTemplateByTemplateName(ctx, "test", "template.json");
        assertEquals(status, "SUCCESS");

    }

    @Test(expected = Exception.class)
    public void testGetTemplateByVnfType() throws SvcLogicException {

        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("vnf-type", "test");
        QueryStatus status = dbService.getTemplateByVnfType(ctx, "test", "config_template");
        assertEquals(status, "SUCCESS");

    }

    @Test(expected = Exception.class)
    public void testGetConfigureActionDGByVnfTypeNAction() throws SvcLogicException {

        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("vnf-type", "test");
        ctx.setAttribute("request-action", "ConfigModify");
        QueryStatus status = dbService.getConfigureActionDGByVnfTypeNAction(ctx, "test");
        assertEquals(status, "SUCCESS");

    }

    @Test(expected = Exception.class)
    public void testGetConfigureActionDGByVnfType() throws SvcLogicException {
        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("vnf-type", "test");
        QueryStatus status = dbService.getConfigureActionDGByVnfType(ctx, "test");
        assertEquals(status, "SUCCESS");

    }

    @Test(expected = Exception.class)
    public void testGetMaxConfigFileId() throws SvcLogicException {

        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("vnf-id", "test");
        ctx.setAttribute("vm-name", "test");
        QueryStatus status = dbService.getMaxConfigFileId(ctx, "test", "device_configuration");
        assertEquals(status, "SUCCESS");

    }

    @Test(expected = Exception.class)
    public void testGetConfigFilesByVnfVmNCategory() throws SvcLogicException {

        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("vnf-id", "test");
        ctx.setAttribute("vm-name", "test");
        QueryStatus status = dbService.getConfigFilesByVnfVmNCategory(ctx, "test", "device_configuration", "test",
                "ibcx0001vm001");
        assertEquals(status, "SUCCESS");

    }

    @Test(expected = Exception.class)
    public void testGetDownloadConfigTemplateByVnf() throws SvcLogicException {

        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("vnf-type", "test");
        QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test");
        assertEquals(status, "SUCCESS");
    }

    @Test(expected = Exception.class)
    public void testSaveConfigTxLog() throws SvcLogicException, IOException {

        SvcLogicContext ctx = new SvcLogicContext();
        String message = IOUtils.toString(
                TestDGGeneralDBService.class.getClassLoader().getResourceAsStream("query/message3.txt"),
                STRING_ENCODING);
        ctx.setAttribute("request-id", "1234");
        String escapedMessage = StringEscapeUtils.escapeSql(message);
        ctx.setAttribute("log-message", escapedMessage);
        ctx.setAttribute("log-message-type", "request");
        QueryStatus status = dbService.saveConfigTransactionLog(ctx, "test");
        assertEquals(status, "SUCCESS");
    }

}