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.assertThat;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertThrows;
27 import org.junit.Test;
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 testDistributionOnlyFileName() {
40 String[] testArgs = {"src/test/resources/parameters/DistributionConfigParameters.json"};
41 assertThrows(PolicyDistributionRuntimeException.class, () -> new DistributionCommandLineArguments(testArgs));
45 public void testDistributionCommandLineArgumentsException() {
46 String[] wrongParams = {"arg1", "nothing", "{\"someJson\":1}"};
47 assertThrows(PolicyDistributionRuntimeException.class, () -> new DistributionCommandLineArguments(wrongParams));
51 public void testValidateFileNameEmpty() {
52 String[] argsOnlyKeyNoValue = {"-c", ""};
53 assertValidate(argsOnlyKeyNoValue, "policy-distribution configuration file was not specified as an argument");
57 public void testValidateFileNameDoesNotExist() {
58 String[] fileNameNotExistentArgs = {"-c", "someFileName.json"};
59 assertValidate(fileNameNotExistentArgs,
60 "policy-distribution configuration file \"someFileName.json\" does not exist");
64 public void testValidateFileNameIsNotFile() {
65 String[] folderAsFileNameArgs = {"-c", "src/test/resources/parameters"};
66 assertValidate(folderAsFileNameArgs,
67 "policy-distribution configuration file \"src/test/resources/parameters\" is not a normal file");
71 public void testDistributionVersion() {
72 String[] testArgs = {"-v"};
73 DistributionCommandLineArguments sutArgs = new DistributionCommandLineArguments(testArgs);
74 assertThat(sutArgs.version()).startsWith("ONAP Policy Framework Distribution Service");
77 private void assertValidate(String[] testArgs, String expectedErrorMsg) {
78 DistributionCommandLineArguments sutArgs = new DistributionCommandLineArguments(testArgs);
79 assertThatThrownBy(() -> sutArgs.validate()).hasMessage(expectedErrorMsg);