Refactor CommandLineArguments classes
[policy/models.git] / models-sim / models-sim-dmaap / src / test / java / org / onap / policy / sim / dmaap / parameters / DmaapSimParameterHandlerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4  * Modifications Copyright (C) 2021 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END=========================================================
18  */
19
20 package org.onap.policy.sim.dmaap.parameters;
21
22 import static org.assertj.core.api.Assertions.assertThatThrownBy;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.policy.common.utils.cmd.CommandLineException;
29 import org.onap.policy.models.sim.dmaap.DmaapSimException;
30 import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
31 import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterHandler;
32 import org.onap.policy.models.sim.dmaap.startstop.DmaapSimCommandLineArguments;
33
34 public class DmaapSimParameterHandlerTest {
35
36     private static final String RESOURCE_DIR = "src/test/resources/parameters/";
37
38     private DmaapSimParameterHandler handler;
39
40     @Before
41     public void setUp() {
42         handler = new DmaapSimParameterHandler();
43     }
44
45     @Test
46     public void testGetParameters() throws DmaapSimException, CommandLineException {
47         final DmaapSimCommandLineArguments args = new DmaapSimCommandLineArguments();
48
49         args.parse(new String[] {"-c", RESOURCE_DIR + "NormalParameters.json"});
50         DmaapSimParameterGroup params = handler.getParameters(args);
51         assertNotNull(params);
52         assertEquals("DMaapSim", params.getName());
53         assertEquals(300L, params.getTopicSweepSec());
54         assertEquals(6845, params.getRestServerParameters().getPort());
55
56
57         args.parse(new String[] {"-c", "FileNotFound.json"});
58         assertThatThrownBy(() -> handler.getParameters(args)).isInstanceOf(DmaapSimException.class)
59                         .hasMessageStartingWith("error reading parameters");
60
61
62         args.parse(new String[] {"-c", RESOURCE_DIR + "EmptyParameterFile.json"});
63         assertThatThrownBy(() -> handler.getParameters(args)).isInstanceOf(DmaapSimException.class)
64                         .hasMessageStartingWith("no parameters found");
65
66
67         args.parse(new String[] {"-c", RESOURCE_DIR + "Parameters_InvalidName.json"});
68         assertThatThrownBy(() -> handler.getParameters(args)).isInstanceOf(DmaapSimException.class)
69                         .hasMessageContaining("validation error");
70     }
71 }