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=========================================================
20 package org.onap.policy.apex.auth.clieditor;
22 import static org.junit.Assert.*;
24 import java.util.List;
26 import org.junit.Before;
27 import org.junit.Test;
29 public class CommandLineCommandTest {
31 CommandLineCommand commandLineCommand = null;
34 public void initializeCommandLineCommand() {
35 commandLineCommand = new CommandLineCommand();
39 public void testCommandLine() {
40 commandLineCommand.setName("TestName");
41 commandLineCommand.setDescription("testDescription");
42 commandLineCommand.setSystemCommand(true);
43 assertTrue(commandLineCommand.isSystemCommand());
44 assertEquals("testDescription", commandLineCommand.getDescription());
45 assertEquals("TestName", commandLineCommand.getName());
46 assertEquals("CLICommand [name=TestName,keywordlist=[], argumentList=[], apiMethod=, systemCommand=true, description=testDescription]",commandLineCommand.toString());
49 @Test(expected = CommandLineException.class)
50 public void testInvalidApiClassName() {
51 commandLineCommand.getApiClassName();
55 public void testGetValidApiClassName() {
56 commandLineCommand.setApiMethod("Java.Get");
57 assertEquals("Java", commandLineCommand.getApiClassName());
60 @Test(expected = CommandLineException.class)
61 public void testInvalidApiMethodName() {
62 commandLineCommand.getApiMethodName();
65 @Test(expected = CommandLineException.class)
66 public void testInvalidApiMethod() {
67 commandLineCommand.setApiMethod("fail.");
68 assertEquals("fail.", commandLineCommand.getApiMethod());
69 commandLineCommand.getApiMethodName();
73 public void testValidApiMethodName() {
74 commandLineCommand.setApiMethod("Java.Get");
75 assertEquals("Get",commandLineCommand.getApiMethodName());
79 public void testGetHelp() {
80 List<String> keywordList = commandLineCommand.getKeywordlist();
81 List<CommandLineArgument> argumentList = commandLineCommand.getArgumentList();
82 assertEquals("{}: ",commandLineCommand.getHelp());
83 keywordList.add("TestKeyword");
84 argumentList.add(new CommandLineArgument("TestArgument"));
85 argumentList.add(null);
86 assertEquals("TestKeyword {}: \n" +
87 " TestArgument: (M) ",commandLineCommand.getHelp());
91 public void testCompareTo() {
92 assertEquals(0,commandLineCommand.compareTo(commandLineCommand));
93 CommandLineCommand otherCommand = new CommandLineCommand();
94 otherCommand.setSystemCommand(true);
95 assertEquals(6,commandLineCommand.compareTo(otherCommand));
96 otherCommand.getArgumentList().add(new CommandLineArgument("testArgument"));
97 assertEquals(-609496833, commandLineCommand.compareTo(otherCommand));
101 public void testCompareKeywordList() {
102 CommandLineCommand otherCommand = new CommandLineCommand();
103 otherCommand.getKeywordlist().add("test");
104 assertEquals(-1, commandLineCommand.compareTo(otherCommand));
105 commandLineCommand.getKeywordlist().add("test");
106 assertEquals(0, commandLineCommand.compareTo(otherCommand));
107 commandLineCommand.getKeywordlist().add("test2");
108 assertEquals(1, commandLineCommand.compareTo(otherCommand));
109 otherCommand.getKeywordlist().add("test3");
110 assertEquals(-1, commandLineCommand.compareTo(otherCommand));
114 public void testHashCode() {
115 CommandLineCommand otherCommand = new CommandLineCommand();
116 assertEquals(commandLineCommand.hashCode(), otherCommand.hashCode());
117 commandLineCommand.getKeywordlist().add("Test");
118 otherCommand.setDescription(null);
119 otherCommand.setApiMethod(null);
120 otherCommand.setName(null);
121 assertNotEquals(commandLineCommand.hashCode(), otherCommand.hashCode());
125 public void testEquals() {
126 CommandLineCommand otherCommand = new CommandLineCommand();
127 assertFalse(commandLineCommand.equals(new Object()));
128 assertTrue(commandLineCommand.equals(commandLineCommand));
129 assertFalse(commandLineCommand.equals(null));
130 assertTrue(commandLineCommand.equals(otherCommand));
131 otherCommand.getKeywordlist().add("TestKeyword");
132 assertFalse(commandLineCommand.equals(otherCommand));