Catalog alignment
[sdc.git] / asdctool / src / test / java / org / openecomp / sdc / asdctool / cli / CLIToolTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP SDC
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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  * ===================================================================
20  */
21
22 package org.openecomp.sdc.asdctool.cli;
23
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;
29
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;
34
35 public class CLIToolTest {
36
37     private static final String OPT = "t";
38     private static final String DESC = "top";
39     private static final String ARG = "blue";
40
41     private CLIToolImplTest impl = new CLIToolImplTest();
42
43     @Test
44     public void testInit() {
45         // when
46         final CLIToolData data = impl.init(new String[]{"-t", ARG});
47
48         // then
49         final CommandLine commandLine = data.getCommandLine();
50         final Option option = commandLine.iterator().next();
51
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());
57     }
58
59     private class CLIToolImplTest extends CLITool {
60         @Override
61         protected Options buildCmdLineOptions() {
62             OptionGroup group = new OptionGroup();
63             group.setRequired(true);
64
65             Option option = new Option(OPT, DESC);
66             group.addOption(option);
67
68             Options options = new Options();
69             options.addOptionGroup(group);
70
71             return options;
72         }
73
74         @Override
75         protected String commandName() {
76             return "cmd";
77         }
78     }
79 }