2 * Copyright 2017 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.
17 package org.onap.cli.fw.defaultParameter;
19 import org.junit.Test;
20 import org.onap.cli.fw.OnapCommand;
21 import org.onap.cli.fw.error.OnapCommandException;
22 import org.onap.cli.fw.error.OnapCommandInvalidDefaultParameter;
23 import org.onap.cli.fw.error.OnapCommandInvalidSchema;
24 import org.onap.cli.fw.input.OnapCommandParameter;
25 import org.onap.cli.fw.utils.OnapCommandUtils;
27 import java.util.List;
28 import java.util.stream.Collectors;
30 import static org.junit.Assert.assertFalse;
31 import static org.junit.Assert.assertTrue;
34 public class TestDefaultParameterSection {
36 public void checkOnlyInclude() throws OnapCommandException {
37 OnapCommand cmd = new OnapCommand() {
39 protected void run() throws OnapCommandException {}
42 OnapCommandUtils.loadSchema(cmd, "sample-test-include-param.yaml", true, false);
43 List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
44 assertTrue(parameters.contains("host-username"));
45 assertTrue(parameters.contains("host-password"));
46 assertTrue(parameters.contains("host-url"));
50 public void checkOnlyExclude() throws OnapCommandException {
51 OnapCommand cmd = new OnapCommand() {
53 protected void run() throws OnapCommandException {}
56 OnapCommandUtils.loadSchema(cmd, "sample-test-exclude-param.yaml", true, false);
57 List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
58 assertTrue(parameters.contains("host-username"));
59 assertTrue(parameters.contains("host-password"));
60 assertTrue(parameters.contains("host-url"));
61 assertFalse(parameters.contains("long"));
62 assertFalse(parameters.contains("format"));
63 assertTrue(parameters.contains("debug"));
67 public void checkBothIncludeAndExclude() throws OnapCommandException {
68 OnapCommand cmd = new OnapCommand() {
70 protected void run() throws OnapCommandException {}
73 OnapCommandUtils.loadSchema(cmd, "sample-test-include-exclude.yaml", true, false);
74 List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
76 assertTrue(parameters.contains("host-username"));
77 assertTrue(parameters.contains("host-password"));
78 assertTrue(parameters.contains("host-url"));
82 public void checkDefaultSectionAbsent() throws OnapCommandException {
83 OnapCommand cmd = new OnapCommand() {
85 protected void run() throws OnapCommandException {}
88 OnapCommandUtils.loadSchema(cmd, "onap-test-schema.yaml", true, false);
89 List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
91 assertFalse(parameters.contains("host-username"));
92 assertFalse(parameters.contains("host-password"));
93 assertTrue(parameters.contains("host-url"));
94 assertTrue(parameters.contains("debug"));
95 assertTrue(parameters.contains("long"));
96 assertTrue(parameters.contains("format"));
99 @Test(expected = OnapCommandInvalidDefaultParameter.class)
100 public void checkInvalidDefaultArgument() throws OnapCommandException {
101 OnapCommand cmd = new OnapCommand() {
103 protected void run() throws OnapCommandException {}
106 OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-default-parameter.yaml", true, false);
109 @Test(expected = OnapCommandInvalidDefaultParameter.class)
110 public void checkInvalidDefaultArgumentNotExist() throws OnapCommandException {
111 OnapCommand cmd = new OnapCommand() {
113 protected void run() throws OnapCommandException {}
116 OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-default-params-not-exist.yaml", true, false);
119 @Test(expected = OnapCommandInvalidSchema.class)
120 public void checkDefaltwithNoExcludeAndInclude() throws OnapCommandException {
121 OnapCommand cmd = new OnapCommand() {
123 protected void run() throws OnapCommandException {}
126 OnapCommandUtils.loadSchema(cmd, "sample-test-import-def-param-false.yaml", true, false);
129 @Test(expected = OnapCommandInvalidDefaultParameter.class)
130 public void checkInvalidIncludeNoAuth() throws OnapCommandException {
131 OnapCommand cmd = new OnapCommand() {
133 protected void run() throws OnapCommandException {}
136 OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-include-noauth.yaml", true, false);
139 @Test(expected = OnapCommandInvalidDefaultParameter.class)
140 public void checkInvalidExcludeNoAuth() throws OnapCommandException {
141 OnapCommand cmd = new OnapCommand() {
143 protected void run() throws OnapCommandException {}
146 OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-exclude-noauth.yaml", true, false);