From ea317372413753320db681efb9a1e469c3776f42 Mon Sep 17 00:00:00 2001 From: RossC Date: Thu, 7 May 2020 13:25:34 +0100 Subject: Unit tests for various classes Issue-ID: POLICY-1916 Change-Id: Ie7cafa16ce12ca542a4e76307caddb36b7753990 Signed-off-by: RossC --- .../auth/clieditor/CommandLineCommandTest.java | 134 +++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java (limited to 'auth/cli-editor/src') diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java new file mode 100644 index 000000000..020e272dd --- /dev/null +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java @@ -0,0 +1,134 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (c) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.policy.apex.auth.clieditor; + +import static org.junit.Assert.*; + +import java.util.List; + +import org.junit.Before; +import org.junit.Test; + +public class CommandLineCommandTest { + + CommandLineCommand commandLineCommand = null; + + @Before + public void initializeCommandLineCommand() { + commandLineCommand = new CommandLineCommand(); + } + + @Test + public void testCommandLine() { + commandLineCommand.setName("TestName"); + commandLineCommand.setDescription("testDescription"); + commandLineCommand.setSystemCommand(true); + assertTrue(commandLineCommand.isSystemCommand()); + assertEquals("testDescription", commandLineCommand.getDescription()); + assertEquals("TestName", commandLineCommand.getName()); + assertEquals("CLICommand [name=TestName,keywordlist=[], argumentList=[], apiMethod=, systemCommand=true, description=testDescription]",commandLineCommand.toString()); + } + + @Test(expected = CommandLineException.class) + public void testInvalidApiClassName() { + commandLineCommand.getApiClassName(); + } + + @Test + public void testGetValidApiClassName() { + commandLineCommand.setApiMethod("Java.Get"); + assertEquals("Java", commandLineCommand.getApiClassName()); + } + + @Test(expected = CommandLineException.class) + public void testInvalidApiMethodName() { + commandLineCommand.getApiMethodName(); + } + + @Test(expected = CommandLineException.class) + public void testInvalidApiMethod() { + commandLineCommand.setApiMethod("fail."); + assertEquals("fail.", commandLineCommand.getApiMethod()); + commandLineCommand.getApiMethodName(); + } + + @Test + public void testValidApiMethodName() { + commandLineCommand.setApiMethod("Java.Get"); + assertEquals("Get",commandLineCommand.getApiMethodName()); + } + + @Test + public void testGetHelp() { + List keywordList = commandLineCommand.getKeywordlist(); + List argumentList = commandLineCommand.getArgumentList(); + assertEquals("{}: ",commandLineCommand.getHelp()); + keywordList.add("TestKeyword"); + argumentList.add(new CommandLineArgument("TestArgument")); + argumentList.add(null); + assertEquals("TestKeyword {}: \n" + + " TestArgument: (M) ",commandLineCommand.getHelp()); + } + + @Test + public void testCompareTo() { + assertEquals(0,commandLineCommand.compareTo(commandLineCommand)); + CommandLineCommand otherCommand = new CommandLineCommand(); + otherCommand.setSystemCommand(true); + assertEquals(6,commandLineCommand.compareTo(otherCommand)); + otherCommand.getArgumentList().add(new CommandLineArgument("testArgument")); + assertEquals(-609496833, commandLineCommand.compareTo(otherCommand)); + } + + @Test + public void testCompareKeywordList() { + CommandLineCommand otherCommand = new CommandLineCommand(); + otherCommand.getKeywordlist().add("test"); + assertEquals(-1, commandLineCommand.compareTo(otherCommand)); + commandLineCommand.getKeywordlist().add("test"); + assertEquals(0, commandLineCommand.compareTo(otherCommand)); + commandLineCommand.getKeywordlist().add("test2"); + assertEquals(1, commandLineCommand.compareTo(otherCommand)); + otherCommand.getKeywordlist().add("test3"); + assertEquals(-1, commandLineCommand.compareTo(otherCommand)); + } + + @Test + public void testHashCode() { + CommandLineCommand otherCommand = new CommandLineCommand(); + assertEquals(commandLineCommand.hashCode(), otherCommand.hashCode()); + commandLineCommand.getKeywordlist().add("Test"); + otherCommand.setDescription(null); + otherCommand.setApiMethod(null); + otherCommand.setName(null); + assertNotEquals(commandLineCommand.hashCode(), otherCommand.hashCode()); + } + + @Test + public void testEquals() { + CommandLineCommand otherCommand = new CommandLineCommand(); + assertFalse(commandLineCommand.equals(new Object())); + assertTrue(commandLineCommand.equals(commandLineCommand)); + assertFalse(commandLineCommand.equals(null)); + assertTrue(commandLineCommand.equals(otherCommand)); + otherCommand.getKeywordlist().add("TestKeyword"); + assertFalse(commandLineCommand.equals(otherCommand)); + } +} -- cgit 1.2.3-korg