0a0e5fa08206dfc0d359f0fd967daae8393821a1
[policy/distribution.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.distribution.main.startstop;
22
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;
26
27 import org.junit.Test;
28 import org.onap.policy.distribution.main.PolicyDistributionRuntimeException;
29
30 /**
31  * Class to perform unit test of DistributionCommandLineArguments.
32  *
33  * @author Adheli Tavares (adheli.tavares@est.tech)
34  *
35  */
36 public class TestDistributionCommandLineArguments {
37
38     @Test
39     public void testDistributionOnlyFileName() {
40         String[] testArgs = {"src/test/resources/parameters/DistributionConfigParameters.json"};
41         assertThrows(PolicyDistributionRuntimeException.class, () -> new DistributionCommandLineArguments(testArgs));
42     }
43
44     @Test
45     public void testDistributionCommandLineArgumentsException() {
46         String[] wrongParams = {"arg1", "nothing", "{\"someJson\":1}"};
47         assertThrows(PolicyDistributionRuntimeException.class, () -> new DistributionCommandLineArguments(wrongParams));
48     }
49
50     @Test
51     public void testValidateFileNameEmpty() {
52         String[] argsOnlyKeyNoValue = {"-c", ""};
53         assertValidate(argsOnlyKeyNoValue, "policy-distribution configuration file was not specified as an argument");
54     }
55
56     @Test
57     public void testValidateFileNameDoesNotExist() {
58         String[] fileNameNotExistentArgs = {"-c", "someFileName.json"};
59         assertValidate(fileNameNotExistentArgs,
60                 "policy-distribution configuration file \"someFileName.json\" does not exist");
61     }
62
63     @Test
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");
68     }
69
70     @Test
71     public void testDistributionVersion() {
72         String[] testArgs = {"-v"};
73         DistributionCommandLineArguments sutArgs = new DistributionCommandLineArguments(testArgs);
74         assertThat(sutArgs.version()).startsWith("ONAP Policy Framework Distribution Service");
75     }
76
77     private void assertValidate(String[] testArgs, String expectedErrorMsg) {
78         DistributionCommandLineArguments sutArgs = new DistributionCommandLineArguments(testArgs);
79         assertThatThrownBy(() -> sutArgs.validate()).hasMessage(expectedErrorMsg);
80     }
81 }