2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 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=========================================================
21 package org.onap.policy.distribution.main.startstop;
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.junit.Assert.assertThrows;
26 import org.junit.Test;
27 import org.onap.policy.distribution.main.PolicyDistributionException;
28 import org.onap.policy.distribution.main.PolicyDistributionRuntimeException;
31 * Class to perform unit test of DistributionCommandLineArguments.
33 * @author Adheli Tavares (adheli.tavares@est.tech)
36 public class TestDistributionCommandLineArguments {
39 public void testDistributionCommandLineArgumentsException() {
40 String[] wrongParams = {"arg1", "nothing", "{\"someJson\":1}"};
41 assertThrows(PolicyDistributionRuntimeException.class, () -> new DistributionCommandLineArguments(wrongParams));
45 public void testValidateFileNameEmpty() {
46 String[] argsOnlyKeyNoValue = {"-c", ""};
47 assertValidate(argsOnlyKeyNoValue, "policy distribution configuration file was not specified as an argument");
51 public void testValidateFileNameDoesNotExist() {
52 String[] fileNameNotExistentArgs = {"-c", "someFileName.json"};
53 assertValidate(fileNameNotExistentArgs,
54 "policy distribution configuration file \"someFileName.json\" does not exist");
58 public void testValidateFileNameIsNotFile() {
59 String[] folderAsFileNameArgs = {"-c", "src/test/resources/parameters"};
60 assertValidate(folderAsFileNameArgs,
61 "policy distribution configuration file \"src/test/resources/parameters\" is not a normal file");
64 protected void assertValidate(String[] testArgs, String expectedErrorMsg) {
65 DistributionCommandLineArguments sutArgs = new DistributionCommandLineArguments(testArgs);
67 assertThatThrownBy(() -> sutArgs.validate())
68 .isInstanceOf(PolicyDistributionException.class)
69 .hasMessage(expectedErrorMsg);