Changes for checkstyle 8.32
[policy/apex-pdp.git] / auth / cli-editor / src / test / java / org / onap / policy / apex / auth / clieditor / CommandLineCommandTest.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.auth.clieditor;
22
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;
27
28 import java.util.List;
29 import org.junit.Before;
30 import org.junit.Test;
31
32 public class CommandLineCommandTest {
33
34     CommandLineCommand commandLineCommand = null;
35
36     @Before
37     public void initializeCommandLineCommand() {
38         commandLineCommand = new CommandLineCommand();
39     }
40
41     @Test
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());
49         assertEquals(
50             "CLICommand [name=TestName,keywordlist=[], argumentList=[], apiMethod=, systemCommand=true,"
51             + " description=testDescription]", commandLineCommand.toString());
52     }
53
54     @Test(expected = CommandLineException.class)
55     public void testInvalidApiClassName() {
56         commandLineCommand.getApiClassName();
57     }
58
59     @Test
60     public void testGetValidApiClassName() {
61         commandLineCommand.setApiMethod("Java.Get");
62         assertEquals("Java", commandLineCommand.getApiClassName());
63     }
64
65     @Test(expected = CommandLineException.class)
66     public void testInvalidApiMethodName() {
67         commandLineCommand.getApiMethodName();
68     }
69
70     @Test(expected = CommandLineException.class)
71     public void testInvalidApiMethod() {
72         commandLineCommand.setApiMethod("fail.");
73         assertEquals("fail.", commandLineCommand.getApiMethod());
74         commandLineCommand.getApiMethodName();
75     }
76
77     @Test
78     public void testValidApiMethodName() {
79         commandLineCommand.setApiMethod("Java.Get");
80         assertEquals("Get", commandLineCommand.getApiMethodName());
81     }
82
83     @Test
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());
92     }
93
94     @Test
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));
102     }
103
104     @Test
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));
115     }
116
117     @Test
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());
126     }
127
128     @Test
129     public void testEquals() {
130         assertFalse(commandLineCommand.equals(new Object()));
131         assertTrue(commandLineCommand.equals(commandLineCommand));
132         assertFalse(commandLineCommand.equals(null));
133
134         CommandLineCommand otherCommand = new CommandLineCommand();
135         assertTrue(commandLineCommand.equals(otherCommand));
136         otherCommand.getKeywordlist().add("TestKeyword");
137         assertFalse(commandLineCommand.equals(otherCommand));
138     }
139 }