2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Ericsson. 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.common.sitemanager.utils;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26 import static org.onap.policy.common.sitemanager.utils.ExtraCommandLineArgument.LOCK;
27 import static org.onap.policy.common.sitemanager.utils.ExtraCommandLineArgument.SET_ADMIN_STATE;
28 import static org.onap.policy.common.sitemanager.utils.ExtraCommandLineArgument.SHOW;
30 import java.io.IOException;
31 import java.util.Arrays;
33 import org.junit.Test;
35 public class ExtraCommandLineArgumentTest {
37 private static final String EMPTY_STRING = "";
38 private static final String RESOURCE_NAME = "RESOURCE_NAME";
41 public void test_ExtraCommandLineArgument_ShowValidArgs() throws IOException {
42 final PrintableImpl printable = new PrintableImpl();
44 final ExtraCommandLineArgument objUnderTest =
45 ExtraCommandLineArgument.getExtraCommandLineArgument(SHOW.getValue());
47 assertTrue(objUnderTest.isValid(Arrays.asList(SHOW.getValue()), printable));
48 assertTrue(printable.getResult().isEmpty());
52 public void test_ExtraCommandLineArgument_SetAdminStateValidArgs() throws IOException {
53 final PrintableImpl printable = new PrintableImpl();
55 final ExtraCommandLineArgument objUnderTest =
56 ExtraCommandLineArgument.getExtraCommandLineArgument(SET_ADMIN_STATE.getValue());
58 assertTrue(objUnderTest.isValid(Arrays.asList(SET_ADMIN_STATE.getValue(), RESOURCE_NAME), printable, true));
59 assertTrue(printable.getResult().isEmpty());
63 public void test_ExtraCommandLineArgument_LockStateValidArgs() throws IOException {
64 final PrintableImpl printable = new PrintableImpl();
66 final ExtraCommandLineArgument objUnderTest =
67 ExtraCommandLineArgument.getExtraCommandLineArgument(LOCK.getValue());
69 assertTrue(objUnderTest.isValid(Arrays.asList(LOCK.getValue()), printable, true));
70 assertTrue(printable.getResult().isEmpty());
74 public void test_ExtraCommandLineArgument_InValidArgs() throws IOException {
75 final PrintableImpl printable = new PrintableImpl();
77 final ExtraCommandLineArgument objUnderTest =
78 ExtraCommandLineArgument.getExtraCommandLineArgument(EMPTY_STRING);
80 assertTrue(objUnderTest.equals(ExtraCommandLineArgument.INVALID));
81 assertFalse(objUnderTest.isValid(Arrays.asList(EMPTY_STRING), printable, false));
82 assertFalse(printable.getResult().isEmpty());
83 assertEquals(Arrays.asList(ErrorMessages.UNKNOWN_COMMAND), printable.getResult());