2 * ============LICENSE_START=======================================================
3 * Copyright (c) 2020 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.auth.clieditor;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertTrue;
28 import java.util.List;
29 import org.junit.Before;
30 import org.junit.Test;
32 public class CommandLineCommandTest {
34 CommandLineCommand commandLineCommand = null;
37 public void initializeCommandLineCommand() {
38 commandLineCommand = new CommandLineCommand();
42 public void testCommandLine() {
43 commandLineCommand.setName("TestName");
44 commandLineCommand.setDescription("testDescription");
45 commandLineCommand.setSystemCommand(true);
46 assertTrue(commandLineCommand.isSystemCommand());
47 assertEquals("testDescription", commandLineCommand.getDescription());
48 assertEquals("TestName", commandLineCommand.getName());
50 "CLICommand [name=TestName,keywordlist=[], argumentList=[], apiMethod=, systemCommand=true,"
51 + " description=testDescription]", commandLineCommand.toString());
54 @Test(expected = CommandLineException.class)
55 public void testInvalidApiClassName() {
56 commandLineCommand.getApiClassName();
60 public void testGetValidApiClassName() {
61 commandLineCommand.setApiMethod("Java.Get");
62 assertEquals("Java", commandLineCommand.getApiClassName());
65 @Test(expected = CommandLineException.class)
66 public void testInvalidApiMethodName() {
67 commandLineCommand.getApiMethodName();
70 @Test(expected = CommandLineException.class)
71 public void testInvalidApiMethod() {
72 commandLineCommand.setApiMethod("fail.");
73 assertEquals("fail.", commandLineCommand.getApiMethod());
74 commandLineCommand.getApiMethodName();
78 public void testValidApiMethodName() {
79 commandLineCommand.setApiMethod("Java.Get");
80 assertEquals("Get", commandLineCommand.getApiMethodName());
84 public void testGetHelp() {
85 List<String> keywordList = commandLineCommand.getKeywordlist();
86 List<CommandLineArgument> argumentList = commandLineCommand.getArgumentList();
87 assertEquals("{}: ", commandLineCommand.getHelp());
88 keywordList.add("TestKeyword");
89 argumentList.add(new CommandLineArgument("TestArgument"));
90 argumentList.add(null);
91 assertEquals("TestKeyword {}: \n" + "\tTestArgument: (M) ", commandLineCommand.getHelp());
95 public void testCompareTo() {
96 assertEquals(0, commandLineCommand.compareTo(commandLineCommand));
97 CommandLineCommand otherCommand = new CommandLineCommand();
98 otherCommand.setSystemCommand(true);
99 assertEquals(6, commandLineCommand.compareTo(otherCommand));
100 otherCommand.getArgumentList().add(new CommandLineArgument("testArgument"));
101 assertEquals(-609496833, commandLineCommand.compareTo(otherCommand));
105 public void testCompareKeywordList() {
106 CommandLineCommand otherCommand = new CommandLineCommand();
107 otherCommand.getKeywordlist().add("test");
108 assertEquals(-1, commandLineCommand.compareTo(otherCommand));
109 commandLineCommand.getKeywordlist().add("test");
110 assertEquals(0, commandLineCommand.compareTo(otherCommand));
111 commandLineCommand.getKeywordlist().add("test2");
112 assertEquals(1, commandLineCommand.compareTo(otherCommand));
113 otherCommand.getKeywordlist().add("test3");
114 assertEquals(-1, commandLineCommand.compareTo(otherCommand));
118 public void testHashCode() {
119 CommandLineCommand otherCommand = new CommandLineCommand();
120 assertEquals(commandLineCommand.hashCode(), otherCommand.hashCode());
121 commandLineCommand.getKeywordlist().add("Test");
122 otherCommand.setDescription(null);
123 otherCommand.setApiMethod(null);
124 otherCommand.setName(null);
125 assertNotEquals(commandLineCommand.hashCode(), otherCommand.hashCode());
129 public void testEquals() {
130 assertFalse(commandLineCommand.equals(new Object()));
131 assertTrue(commandLineCommand.equals(commandLineCommand));
132 assertFalse(commandLineCommand.equals(null));
134 CommandLineCommand otherCommand = new CommandLineCommand();
135 assertTrue(commandLineCommand.equals(otherCommand));
136 otherCommand.getKeywordlist().add("TestKeyword");
137 assertFalse(commandLineCommand.equals(otherCommand));