Code Improvements-Vnfsdk-refrepo sonar issue fixes
[vnfsdk/refrepo.git] / vnfmarket-be / vnf-sdk-marketplace / src / test / java / org / onap / vtp / scenario / VTPScenarioResourceTest.java
1 /**
2  * Copyright 2019 Huawei Technologies Co., Ltd.
3  * <p>
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * <p>
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * <p>
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.vtp.scenario;
17
18 import com.google.gson.JsonElement;
19 import com.google.gson.JsonParser;
20 import mockit.Mock;
21 import mockit.MockUp;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.onap.vtp.VTPResource;
25 import org.onap.vtp.error.VTPError;
26
27 import java.io.IOException;
28 import java.util.List;
29
30 import static org.junit.Assert.*;
31 import org.onap.vtp.scenario.model.VTPTestCase;
32
33 public class VTPScenarioResourceTest {
34
35     VTPScenarioResource vtpScenarioResource;
36
37     @Before
38     public void setUp() throws Exception {
39         vtpScenarioResource = new VTPScenarioResource();
40     }
41
42     @Test
43     public void testListTestScenariosHandler() throws Exception {
44         new MockUp<VTPResource>() {
45             @Mock
46             protected JsonElement makeRpcAndGetJson(List<String> args, int timeout) throws VTPError.VTPException, IOException {
47                 JsonParser jsonParser = new JsonParser();
48                 String jsonvalue = "[{\"product\":\"onap-dublin\",\"description\":\"its 4th release\"}]";
49                 JsonElement jsonNode = jsonParser.parse(jsonvalue);
50                 return jsonNode;
51             }
52         };
53         assertNotNull(vtpScenarioResource.listTestScenariosHandler());
54     }
55
56     @Test
57     public void testListTestSutiesHandler() throws Exception {
58         new MockUp<VTPResource>() {
59             @Mock
60             protected JsonElement makeRpcAndGetJson(List<String> args, int timeout) throws VTPError.VTPException, IOException {
61                 JsonParser jsonParser = new JsonParser();
62                 String jsonvalue = "[{\"product\":\"onap-dublin\",\"service\":\"test\",\"description\":\"its 4th release\"}]";
63                 JsonElement jsonNode = jsonParser.parse(jsonvalue);
64                 return jsonNode;
65             }
66         };
67         assertNotNull(vtpScenarioResource.listTestSutiesHandler("open-cli"));
68     }
69
70     @Test
71     public void testListTestcasesHandler() throws Exception {
72         new MockUp<VTPResource>() {
73             @Mock
74             protected JsonElement makeRpcAndGetJson(List<String> args, int timeout) throws VTPError.VTPException, IOException {
75                 JsonParser jsonParser = new JsonParser();
76                 String jsonvalue = "[{\"command\":\"list-users\",\"service\":\"ut\"}]";
77                 JsonElement jsonNode = jsonParser.parse(jsonvalue);
78                 return jsonNode;
79             }
80         };
81
82         VTPTestCase vtpTestCases = vtpScenarioResource.listTestcasesHandler("testsuite", "open-cli").getTestCases().get(0);
83         assertEquals("list-users", vtpTestCases.getTestCaseName());
84     }
85
86     public void testListTestcases() throws Exception {
87         vtpScenarioResource.listTestcases("open-cli", "testsuite");
88     }
89
90     @Test(expected = Exception.class)
91     public void testGetTestcase() throws Exception {
92         vtpScenarioResource.getTestcase("open-cli", "testsuit", "testcase");
93     }
94
95     @Test
96     public void testGetTestcaseHandler() throws Exception {
97         new MockUp<VTPResource>() {
98             @Mock
99             protected JsonElement makeRpcAndGetJson(List<String> args, int timeout) throws VTPError.VTPException, IOException {
100                 JsonParser jsonParser = new JsonParser();
101                 String jsonvalue = "{\"schema\":{\"name\":\"cli\",\"product\":\"onap-dublin\",\"description\":\"its 4th release\"," +
102                         "\"service\":\"test\",\"author\":\"jitendra\",\"inputs\":[{\"name\":\"abc\",\"description\":\"abc\"," +
103                         "\"type\":\"abc\",\"is_optional\":\"yes\",\"default_value\":\"abc\",\"metadata\":\"abc\"}]," +
104                         "\"outputs\":[{\"name\":\"abc\",\"description\":\"abc\",\"type\":\"abc\"}]}}";
105                 JsonElement jsonNode = jsonParser.parse(jsonvalue);
106                 return jsonNode;
107             }
108         };
109         assertNotNull(vtpScenarioResource.getTestcaseHandler("open-cli", "testsuit", "testcase"));
110     }
111 }