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;
29 import java.io.IOException;
30 import java.util.Arrays;
31 import org.junit.Test;
33 public class ExtraCommandLineArgumentTest {
35 private static final String EMPTY_STRING = "";
36 private static final String RESOURCE_NAME = "RESOURCE_NAME";
39 public void test_ExtraCommandLineArgument_ShowValidArgs() throws IOException {
40 final PrintableImpl printable = new PrintableImpl();
42 final ExtraCommandLineArgument objUnderTest =
43 ExtraCommandLineArgument.getExtraCommandLineArgument(SHOW.getValue());
45 assertTrue(objUnderTest.isValid(Arrays.asList(SHOW.getValue()), printable));
46 assertTrue(printable.getResult().isEmpty());
50 public void test_ExtraCommandLineArgument_SetAdminStateValidArgs() throws IOException {
51 final PrintableImpl printable = new PrintableImpl();
53 final ExtraCommandLineArgument objUnderTest =
54 ExtraCommandLineArgument.getExtraCommandLineArgument(SET_ADMIN_STATE.getValue());
56 assertTrue(objUnderTest.isValid(Arrays.asList(SET_ADMIN_STATE.getValue(), RESOURCE_NAME), printable, true));
57 assertTrue(printable.getResult().isEmpty());
61 public void test_ExtraCommandLineArgument_LockStateValidArgs() throws IOException {
62 final PrintableImpl printable = new PrintableImpl();
64 final ExtraCommandLineArgument objUnderTest =
65 ExtraCommandLineArgument.getExtraCommandLineArgument(LOCK.getValue());
67 assertTrue(objUnderTest.isValid(Arrays.asList(LOCK.getValue()), printable, true));
68 assertTrue(printable.getResult().isEmpty());
72 public void test_ExtraCommandLineArgument_InValidArgs() throws IOException {
73 final PrintableImpl printable = new PrintableImpl();
75 final ExtraCommandLineArgument objUnderTest =
76 ExtraCommandLineArgument.getExtraCommandLineArgument(EMPTY_STRING);
78 assertTrue(objUnderTest.equals(ExtraCommandLineArgument.INVALID));
79 assertFalse(objUnderTest.isValid(Arrays.asList(EMPTY_STRING), printable, false));
80 assertFalse(printable.getResult().isEmpty());
81 assertEquals(Arrays.asList(ErrorMessages.UNKNOWN_COMMAND), printable.getResult());