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.AfterClass;
31 import org.junit.Before;
32 import org.junit.BeforeClass;
33 import org.junit.Ignore;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.Mock;
37 import org.mockito.Mockito;
38 import static org.mockito.Mockito.when;
39 import org.mockito.runners.MockitoJUnitRunner;
40 import org.onap.appc.design.dbervices.DbService;
41 import org.onap.appc.design.dbervices.DesignDBService;
42 import org.onap.appc.design.dbervices.DesignDBService.ArtifactHandlerFactory;
43 import org.onap.appc.design.services.util.ArtifactHandlerClient;
44 import org.powermock.api.mockito.PowerMockito;
45 import org.powermock.core.classloader.annotations.PrepareForTest;
46 import org.powermock.modules.junit4.PowerMockRunner;
47 import org.powermock.reflect.Whitebox;
49 @RunWith(PowerMockRunner.class)
50 public class TestDesignDBServices {
52 private DesignDBService designDbService;
54 private DesignDBService spyDesign;
57 private DbService dbservice;
63 private ArtifactHandlerClient artifactHandlerClient;
65 private static ArtifactHandlerFactory saveFactory;
67 private static ArtifactHandlerFactory factory;
70 public static void setUpBeforeClass() {
71 saveFactory = Whitebox.getInternalState(DesignDBService.class, "artifactHandlerFactory");
75 public static void tearDownAfterClass() {
76 Whitebox.setInternalState(DesignDBService.class, "artifactHandlerFactory", saveFactory);
81 public void setUp() throws Exception {
82 factory = Mockito.mock(ArtifactHandlerFactory.class);
83 Whitebox.setInternalState(DesignDBService.class, "artifactHandlerFactory", factory);
84 Map<String, String> outputMessage = new HashMap<>();
85 designDbService = DesignDBService.initialise();
86 Whitebox.setInternalState(designDbService, "dbservice", dbservice);
87 //Whitebox.setInternalState(designDbService, "ac",artifactHandlerClient);
88 //Mockito.doReturn(outputMessage).when(artifactHandlerClient).execute(Mockito.anyString(), Mockito.anyString());
89 when(factory.ahi()).thenReturn(artifactHandlerClient);
90 when(dbservice.getDBData(Mockito.anyString(), Mockito.anyList())).thenReturn(rs);
91 when(rs.next()).thenReturn(true, true, false);
92 Mockito.doReturn(true).when(dbservice).updateDBData(Mockito.anyString(), Mockito.anyList());
94 spyDesign = PowerMockito.spy(designDbService);
98 public void testSetStatus() throws Exception {
99 String payload = "{\"userID\": \"1234\", \"vnf-type\" : \"DesigTest-VNF\",\"artifact_status\":\"TestArtifactStatus\",\"action_status\":\"TestAction\",\"vnfc-type\":\"TestVnfc\" }";
100 String json = Whitebox.invokeMethod(spyDesign, "setStatus", payload, "1234");
101 assertEquals(true, json.contains("1234"));
105 public void testGetDesigns() throws Exception {
106 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"artifact_status\":\"TestArtifactStatus\",\"action_status\":\"TestAction\" }";
107 String result = Whitebox.invokeMethod(spyDesign, "getDesigns", payload, "1234");
108 assertEquals(true, result.contains("0000"));
112 public void testGetDesignsWithFilter() throws Exception {
113 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"filter\":\"TestFilter\" }";
114 String result = Whitebox.invokeMethod(spyDesign, "getDesigns", payload, "1234");
115 assertEquals(true, result.contains("0000"));
119 public void testSetInCartr() throws Exception {
120 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"inCart\":\"TestInCart\",\"vnfc-type\":\"TestVnfc\"}";
121 String result = Whitebox.invokeMethod(spyDesign, "setInCart", payload, "1234");
122 assertEquals(true, result.contains("success"));
126 public void testSetProtocolReference() throws Exception {
127 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"action\":\"TestAction\",\"action-level\":\"TestLevel\",\"protocol\":\"TestProtocol\",\"vnfc-type\":\"TestVnfc\",\"template\":\"TestTemplate\"}";
128 String result = Whitebox.invokeMethod(spyDesign, "setProtocolReference", payload, "1234");
129 assertEquals(true, result.contains("success"));
134 public void TestUploadArtifact() throws Exception {
135 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\"} ";
136 String result = Whitebox.invokeMethod(spyDesign, "uploadArtifact", payload, "1234");
137 assertEquals(true, result.contains("success"));
141 public void testLinkstatusRelationShip() throws Exception {
142 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"action\":\"TestAction\",\"action-level\":\"TestLevel\",\"protocol\":\"TestProtocol\",\"vnfc-type\":\"TestVnfc\",\"template\":\"TestTemplate\"}";
143 String result = Whitebox.invokeMethod(spyDesign, "linkstatusRelationShip", 0, 0, payload);
144 assertEquals(null, result);
148 public void testGetSDCReferenceID() throws Exception {
149 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\"}";
150 int result = Whitebox.invokeMethod(spyDesign, "getSDCReferenceID", payload);
151 assertEquals(0, result);
155 public void testgetDataFromActionStatus() throws Exception {
156 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\"}";
157 String result = Whitebox.invokeMethod(spyDesign, "getDataFromActionStatus", payload, "Data");
158 assertEquals(null, result);
162 public void testsetActionStatus() throws Exception {
163 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"action\":\"TestAction\",\"action-level\":\"TestLevel\",\"protocol\":\"TestProtocol\",\"vnfc-type\":\"TestVnfc\",\"template\":\"TestTemplate\"}";
164 String result = Whitebox.invokeMethod(spyDesign, "setActionStatus", payload, "Status");
165 assertEquals(null, result);
169 public void testcreateArtifactTrackingRecord() throws Exception {
170 String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\",\"action\":\"TestAction\",\"technology\":\"TestTech\",\"action-level\":\"TestLevel\",\"protocol\":\"TestProtocol\",\"vnfc-type\":\"TestVnfc\",\"template\":\"TestTemplate\"}";
171 String result = Whitebox.invokeMethod(spyDesign, "createArtifactTrackingRecord", payload, "1234", 0, 0);
172 assertEquals(null, result);
176 public void testgetSDCArtifactIDbyRequestID() throws Exception {
177 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\"}";
178 int result = Whitebox.invokeMethod(spyDesign, "getSDCArtifactIDbyRequestID", payload);
179 assertEquals(0, result);
182 @Test(expected = Exception.class)
183 public void testgetArtifact() throws Exception {
184 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\"}";
185 String result = Whitebox.invokeMethod(spyDesign, "getArtifact", payload, "1234");
189 public void testgetStatus() throws Exception {
190 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\"}";
191 String result = Whitebox.invokeMethod(spyDesign, "getStatus", payload, "1234");
192 assertEquals(true, result.contains("0000"));
196 public void testGetAppcTimestampUTC() throws Exception {
197 String requestId = "1234";
198 DesignDBService design = DesignDBService.initialise();
199 String result = Whitebox.invokeMethod(design, "getAppcTimestampUTC",requestId);
200 assertTrue(result.endsWith("Z"));