2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Samsung. All rights reserved.
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.
18 * ============LICENSE_END============================================
19 * ===================================================================
22 package org.openecomp.sdc.asdctool.cli;
24 import org.apache.commons.cli.CommandLine;
25 import org.apache.commons.cli.Option;
26 import org.apache.commons.cli.OptionGroup;
27 import org.apache.commons.cli.Options;
28 import org.junit.Test;
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertFalse;
32 import static org.junit.Assert.assertNull;
33 import static org.junit.Assert.assertTrue;
35 public class CLIToolTest {
37 private static final String OPT = "t";
38 private static final String DESC = "top";
39 private static final String ARG = "blue";
41 private CLIToolImplTest impl = new CLIToolImplTest();
44 public void testInit() {
46 final CLIToolData data = impl.init(new String[]{"-t", ARG});
49 final CommandLine commandLine = data.getCommandLine();
50 final Option option = commandLine.iterator().next();
52 assertNull(commandLine.getOptionValue(OPT));
53 assertEquals(ARG, commandLine.getArgs()[0]);
54 assertTrue(commandLine.hasOption(OPT));
55 assertFalse(option.hasArg());
56 assertEquals(DESC, option.getDescription());
59 private class CLIToolImplTest extends CLITool {
61 protected Options buildCmdLineOptions() {
62 OptionGroup group = new OptionGroup();
63 group.setRequired(true);
65 Option option = new Option(OPT, DESC);
66 group.addOption(option);
68 Options options = new Options();
69 options.addOptionGroup(group);
75 protected String commandName() {