2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017-2018 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  * ============LICENSE_END=========================================================
 
  23 package org.onap.appc.data.services.db;
 
  25 import static org.junit.Assert.assertEquals;
 
  26 import java.io.IOException;
 
  27 import org.apache.commons.io.IOUtils;
 
  28 import org.apache.commons.lang.StringEscapeUtils;
 
  29 import org.junit.Test;
 
  30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 
  32 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
 
  33 import org.onap.appc.data.services.db.DGGeneralDBService;
 
  35 public class TestDGGeneralDBService {
 
  36     DGGeneralDBService dbService;
 
  37     private static String STRING_ENCODING = "utf-8";
 
  40     public void testGetUploadConfig() throws SvcLogicException {
 
  42         SvcLogicContext ctx = new SvcLogicContext();
 
  43         ctx.setAttribute("vnf-name", "test");
 
  44         ctx.setAttribute("vnf-id", "test");
 
  45         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
  46         QueryStatus status = dbService.getUploadConfigInfo(ctx, "test");
 
  47         assertEquals(status, QueryStatus.SUCCESS);
 
  52     public void testGetDeviceProtocolByVnfType() throws SvcLogicException {
 
  53         SvcLogicContext ctx = new SvcLogicContext();
 
  54         ctx.setAttribute("vnf-type", "test");
 
  55         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
  56         QueryStatus status = dbService.getDeviceProtocolByVnfType(ctx, "test");
 
  57         assertEquals(status, QueryStatus.SUCCESS);
 
  61     public void testGettConfigFileReferenceByFileTypeNVnfType() throws SvcLogicException {
 
  62         SvcLogicContext ctx = new SvcLogicContext();
 
  63         ctx.setAttribute("vnf-type", "test");
 
  64         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
  65         QueryStatus status = dbService.getConfigFileReferenceByFileTypeNVnfType(ctx, "test", "device_configuration");
 
  66         assertEquals(status, QueryStatus.SUCCESS);
 
  71     public void testGetDeviceAuthenticationByVnfType() throws Exception {
 
  72         SvcLogicContext ctx = new SvcLogicContext();
 
  73         ctx.setAttribute("vnf-type", "test");
 
  74         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
  75         QueryStatus status = dbService.getDeviceAuthenticationByVnfType(ctx, "test");
 
  76         assertEquals(status, QueryStatus.SUCCESS);
 
  81     public void testGetTemplate() throws Exception {
 
  82         SvcLogicContext ctx = new SvcLogicContext();
 
  83         ctx.setAttribute("vnfc-type", "test");
 
  84         ctx.setAttribute("request-action", "Configure");
 
  85         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
  86         QueryStatus status = dbService.getTemplate(ctx, "test", "config_template");
 
  87         assertEquals(status, QueryStatus.SUCCESS);
 
  92     public void testGetTemplateByVnfTypeNAction() throws Exception {
 
  93         SvcLogicContext ctx = new SvcLogicContext();
 
  94         ctx.setAttribute("vnf-type", "test");
 
  95         ctx.setAttribute("request-action", "ConfigScaleOut");
 
  96         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
  97         QueryStatus status = dbService.getTemplateByVnfTypeNAction(ctx, "test", "config_template");
 
  98         assertEquals(status, QueryStatus.SUCCESS);
 
 103     public void testGetTemplateByTemplateName() throws Exception {
 
 104         SvcLogicContext ctx = new SvcLogicContext();
 
 105         ctx.setAttribute("request-action", "Configure");
 
 106         ctx.setAttribute("vnf-type", "test");
 
 107         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
 108         QueryStatus status = dbService.getTemplateByTemplateName(ctx, "test", "template.json");
 
 109         assertEquals(status, QueryStatus.SUCCESS);
 
 114     public void testGetTemplateByVnfType() throws SvcLogicException {
 
 116         SvcLogicContext ctx = new SvcLogicContext();
 
 117         ctx.setAttribute("vnf-type", "test");
 
 118         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
 119         QueryStatus status = dbService.getTemplateByVnfType(ctx, "test", "config_template");
 
 120         assertEquals(status, QueryStatus.SUCCESS);
 
 125     public void testGetConfigureActionDGByVnfTypeNAction() throws SvcLogicException {
 
 127         SvcLogicContext ctx = new SvcLogicContext();
 
 128         ctx.setAttribute("vnf-type", "test");
 
 129         ctx.setAttribute("request-action", "ConfigModify");
 
 130         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
 131         QueryStatus status = dbService.getConfigureActionDGByVnfTypeNAction(ctx, "test");
 
 132         assertEquals(status, QueryStatus.SUCCESS);
 
 137     public void testGetConfigureActionDGByVnfType() throws SvcLogicException {
 
 138         SvcLogicContext ctx = new SvcLogicContext();
 
 139         ctx.setAttribute("vnf-type", "test");
 
 140         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
 141         QueryStatus status = dbService.getConfigureActionDGByVnfType(ctx, "test");
 
 142         assertEquals(status, QueryStatus.SUCCESS);
 
 147     public void testGetMaxConfigFileId() throws SvcLogicException {
 
 149         SvcLogicContext ctx = new SvcLogicContext();
 
 150         ctx.setAttribute("vnf-id", "test");
 
 151         ctx.setAttribute("vm-name", "test");
 
 152         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
 153         QueryStatus status = dbService.getMaxConfigFileId(ctx, "test", "device_configuration");
 
 154         assertEquals(status, QueryStatus.SUCCESS);
 
 159     public void testGetConfigFilesByVnfVmNCategory() throws SvcLogicException {
 
 161         SvcLogicContext ctx = new SvcLogicContext();
 
 162         ctx.setAttribute("vnf-id", "test");
 
 163         ctx.setAttribute("vm-name", "test");
 
 164         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
 165         QueryStatus status = dbService.getConfigFilesByVnfVmNCategory(ctx, "test", "device_configuration", "test",
 
 167         assertEquals(status, QueryStatus.SUCCESS);
 
 172     public void testGetDownloadConfigTemplateByVnf() throws SvcLogicException {
 
 174         SvcLogicContext ctx = new SvcLogicContext();
 
 175         ctx.setAttribute("vnf-type", "test");
 
 176         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
 177         QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test");
 
 178         assertEquals(status, QueryStatus.SUCCESS);
 
 182     public void testSaveConfigTxLog() throws SvcLogicException, IOException {
 
 184         SvcLogicContext ctx = new SvcLogicContext();
 
 185         String message = IOUtils.toString(
 
 186                 TestDGGeneralDBService.class.getClassLoader().getResourceAsStream("query/message3.txt"),
 
 188         ctx.setAttribute("request-id", "1234");
 
 189         String escapedMessage = StringEscapeUtils.escapeSql(message);
 
 190         ctx.setAttribute("log-message", escapedMessage);
 
 191         ctx.setAttribute("log-message-type", "request");
 
 192         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
 193         QueryStatus status = dbService.saveConfigTransactionLog(ctx, "test");
 
 194         assertEquals(status, QueryStatus.SUCCESS);
 
 198     public void testGetVnfcReferenceByVnfTypeNActionWithTemplateModelId() throws Exception {
 
 199         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
 200         SvcLogicContext ctx = new SvcLogicContext();
 
 201         String prefix="test";
 
 202         String templateModelId = "template001";
 
 203         dbService.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, prefix, templateModelId);
 
 207     public void testGetTemplateWithTemplateModelId() throws Exception {
 
 208         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
 209         SvcLogicContext ctx = new SvcLogicContext();
 
 210         String prefix="test";
 
 211         String templateModelId = "template001";
 
 212         String fileCategory="testCategory";
 
 213         dbService.getTemplateWithTemplateModelId(ctx, prefix, fileCategory, templateModelId);
 
 217     public void testgetTemplateByVnfTypeNActionWithTemplateModelId() throws Exception {
 
 218         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
 
 219         SvcLogicContext ctx = new SvcLogicContext();
 
 220         String prefix="test";
 
 221         String templateModelId = "template001";
 
 222         String fileCategory="testCategory";
 
 223         dbService.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, prefix, fileCategory, templateModelId);