2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 IBM
6 * =============================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.design.validator;
24 import static org.junit.Assert.*;
26 import java.sql.ResultSet;
27 import java.util.HashMap;
30 import org.junit.Before;
31 import org.junit.Ignore;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.mockito.Mockito;
36 import static org.mockito.Mockito.when;
37 import org.mockito.runners.MockitoJUnitRunner;
38 import org.onap.appc.design.dbervices.DbService;
39 import org.onap.appc.design.dbervices.DesignDBService;
40 import org.onap.appc.design.services.util.ArtifactHandlerClient;
41 import org.powermock.core.classloader.annotations.PrepareForTest;
42 import org.powermock.reflect.Whitebox;
44 @RunWith(MockitoJUnitRunner.class)
45 @PrepareForTest(DesignDBService.class)
46 public class TestDesignDBServices {
48 private DesignDBService designDbService;
50 private DesignDBService spyDesign;
53 private DbService dbservice;
59 private ArtifactHandlerClient artifactHandlerClient;
62 public void setUp() throws Exception {
63 Map<String, String> outputMessage = new HashMap<>();
64 designDbService = DesignDBService.initialise();
65 Whitebox.setInternalState(designDbService, "dbservice", dbservice);
66 // Whitebox.setInternalState(designDbService, "ac",
67 // artifactHandlerClient);
68 Mockito.doReturn(outputMessage).when(artifactHandlerClient).execute(Mockito.anyString(), Mockito.anyString());
69 when(dbservice.getDBData(Mockito.anyString(), Mockito.anyList())).thenReturn(rs);
70 when(rs.next()).thenReturn(true, true, false);
71 Mockito.doReturn(true).when(dbservice).updateDBData(Mockito.anyString(), Mockito.anyList());
73 spyDesign = Mockito.spy(designDbService);
77 public void testSetStatus() throws Exception {
78 String payload = "{\"userID\": \"1234\", \"vnf-type\" : \"DesigTest-VNF\",\"artifact_status\":\"TestArtifactStatus\",\"action_status\":\"TestAction\",\"vnfc-type\":\"TestVnfc\" }";
79 String json = Whitebox.invokeMethod(spyDesign, "setStatus", payload, "1234");
80 assertEquals(true, json.contains("1234"));
84 public void testGetDesigns() throws Exception {
85 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"artifact_status\":\"TestArtifactStatus\",\"action_status\":\"TestAction\" }";
86 String result = Whitebox.invokeMethod(spyDesign, "getDesigns", payload, "1234");
87 assertEquals(true, result.contains("0000"));
91 public void testGetDesignsWithFilter() throws Exception {
92 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"filter\":\"TestFilter\" }";
93 String result = Whitebox.invokeMethod(spyDesign, "getDesigns", payload, "1234");
94 assertEquals(true, result.contains("0000"));
98 public void testSetInCartr() throws Exception {
99 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"inCart\":\"TestInCart\",\"vnfc-type\":\"TestVnfc\"}";
100 String result = Whitebox.invokeMethod(spyDesign, "setInCart", payload, "1234");
101 assertEquals(true, result.contains("success"));
105 public void testSetProtocolReference() throws Exception {
106 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"action\":\"TestAction\",\"action-level\":\"TestLevel\",\"protocol\":\"TestProtocol\",\"vnfc-type\":\"TestVnfc\",\"template\":\"TestTemplate\"}";
107 String result = Whitebox.invokeMethod(spyDesign, "setProtocolReference", payload, "1234");
108 assertEquals(true, result.contains("success"));
112 @Test(expected = ExceptionInInitializerError.class)
113 public void TestUploadArtifact() throws Exception {
114 String payload = " { \"userID\": \"00000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": \"TestContents\"} ";
115 Whitebox.invokeMethod(spyDesign, "uploadArtifact", payload, "1234");
119 public void testLinkstatusRelationShip() throws Exception {
120 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"action\":\"TestAction\",\"action-level\":\"TestLevel\",\"protocol\":\"TestProtocol\",\"vnfc-type\":\"TestVnfc\",\"template\":\"TestTemplate\"}";
121 String result = Whitebox.invokeMethod(spyDesign, "linkstatusRelationShip", 0, 0, payload);
122 assertEquals(null, result);
126 public void testGetSDCReferenceID() throws Exception {
127 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"action\":\"TestAction\",\"action-level\":\"TestLevel\",\"protocol\":\"TestProtocol\",\"vnfc-type\":\"TestVnfc\",\"artifact-type\" :\"DESIGNTOOL-TEST\", \"artifact-name\":\"DesignRestArtifact_reference\"}";
128 int result = Whitebox.invokeMethod(spyDesign, "getSDCReferenceID", payload);
129 assertEquals(0, result);
133 public void testgetDataFromActionStatus() throws Exception {
134 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"action\":\"TestAction\",\"action-level\":\"TestLevel\",\"protocol\":\"TestProtocol\",\"vnfc-type\":\"TestVnfc\",\"artifact-type\" :\"DESIGNTOOL-TEST\", \"artifact-name\":\"DesignRestArtifact_reference\"}";
135 String result = Whitebox.invokeMethod(spyDesign, "getDataFromActionStatus", payload, "Data");
136 assertEquals(null, result);
140 public void testsetActionStatus() throws Exception {
141 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"action\":\"TestAction\",\"action-level\":\"TestLevel\",\"protocol\":\"TestProtocol\",\"vnfc-type\":\"TestVnfc\",\"template\":\"TestTemplate\"}";
142 String result = Whitebox.invokeMethod(spyDesign, "setActionStatus", payload, "Status");
143 assertEquals(null, result);
147 public void testcreateArtifactTrackingRecord() throws Exception {
148 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"action\":\"TestAction\",\"technology\":\"TestTech\",\"action-level\":\"TestLevel\",\"protocol\":\"TestProtocol\",\"vnfc-type\":\"TestVnfc\",\"template\":\"TestTemplate\"}";
149 String result = Whitebox.invokeMethod(spyDesign, "createArtifactTrackingRecord", payload, "1234", 0, 0);
150 assertEquals(null, result);
154 public void testgetSDCArtifactIDbyRequestID() throws Exception {
155 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"action\":\"TestAction\",\"action-level\":\"TestLevel\",\"protocol\":\"TestProtocol\",\"vnfc-type\":\"TestVnfc\",\"artifact-type\" :\"DESIGNTOOL-TEST\", \"artifact-name\":\"DesignRestArtifact_reference\"}";
156 int result = Whitebox.invokeMethod(spyDesign, "getSDCArtifactIDbyRequestID", payload);
157 assertEquals(0, result);
160 @Test(expected = Exception.class)
161 public void testgetArtifact() throws Exception {
162 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"action\":\"TestAction\",\"action-level\":\"TestLevel\",\"protocol\":\"TestProtocol\",\"vnfc-type\":\"TestVnfc\",\"artifact-type\" :\"DESIGNTOOL-TEST\", \"artifact-name\":\"DesignRestArtifact_reference\"}";
163 String result = Whitebox.invokeMethod(spyDesign, "getArtifact", payload, "1234");
167 public void testgetStatus() throws Exception {
168 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"action\":\"TestAction\",\"action-level\":\"TestLevel\",\"protocol\":\"TestProtocol\",\"vnfc-type\":\"TestVnfc\",\"artifact-type\" :\"DESIGNTOOL-TEST\", \"artifact-name\":\"DesignRestArtifact_reference\"}";
169 String result = Whitebox.invokeMethod(spyDesign, "getStatus", payload, "1234");
170 assertEquals(true, result.contains("0000"));
174 public void testGetAppcTimestampUTC() throws Exception {
175 String requestId = "1234";
176 DesignDBService design = DesignDBService.initialise();
177 String result = Whitebox.invokeMethod(design, "getAppcTimestampUTC",requestId);
178 assertTrue(result.endsWith("Z"));