2 * Copyright 2019 Huawei Technologies Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.vtp.scenario;
18 import com.google.gson.JsonElement;
19 import com.google.gson.JsonParser;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.onap.vtp.VTPResource;
25 import org.onap.vtp.error.VTPError;
27 import java.io.IOException;
28 import java.util.List;
30 import static org.junit.Assert.*;
31 import org.onap.vtp.scenario.model.VTPTestCase;
33 public class VTPScenarioResourceTest {
35 VTPScenarioResource vtpScenarioResource;
38 public void setUp() throws Exception {
39 vtpScenarioResource = new VTPScenarioResource();
43 public void testListTestScenariosHandler() throws Exception {
44 new MockUp<VTPResource>() {
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);
53 assertNotNull(vtpScenarioResource.listTestScenariosHandler());
57 public void testListTestSutiesHandler() throws Exception {
58 new MockUp<VTPResource>() {
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);
67 assertNotNull(vtpScenarioResource.listTestSutiesHandler("open-cli"));
71 public void testListTestcasesHandler() throws Exception {
72 new MockUp<VTPResource>() {
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);
82 VTPTestCase vtpTestCases = vtpScenarioResource.listTestcasesHandler("testsuite", "open-cli").getTestCases().get(0);
83 assertEquals("list-users", vtpTestCases.getTestCaseName());
86 public void testListTestcases() throws Exception {
87 vtpScenarioResource.listTestcases("open-cli", "testsuite");
90 @Test(expected = Exception.class)
91 public void testGetTestcase() throws Exception {
92 vtpScenarioResource.getTestcase("open-cli", "testsuit", "testcase");
96 public void testGetTestcaseHandler() throws Exception {
97 new MockUp<VTPResource>() {
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);
109 assertNotNull(vtpScenarioResource.getTestcaseHandler("open-cli", "testsuit", "testcase"));