8f053d219d9cae0d529dd740802c070d12345b25
[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  * ================================================================================
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  * ============LICENSE_END=========================================================
17  */
18
19 package org.onap.policy.sim.dmaap.parameters;
20
21 import static org.assertj.core.api.Assertions.assertThatThrownBy;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.onap.policy.models.sim.dmaap.DmaapSimException;
28 import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
29 import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterHandler;
30 import org.onap.policy.models.sim.dmaap.startstop.DmaapSimCommandLineArguments;
31
32 public class DmaapSimParameterHandlerTest {
33
34     private static final String RESOURCE_DIR = "src/test/resources/parameters/";
35
36     private DmaapSimParameterHandler handler;
37
38     @Before
39     public void setUp() {
40         handler = new DmaapSimParameterHandler();
41     }
42
43     @Test
44     public void testGetParameters() throws DmaapSimException {
45         final DmaapSimCommandLineArguments args = new DmaapSimCommandLineArguments();
46
47         args.parse(new String[] {"-c", RESOURCE_DIR + "NormalParameters.json"});
48         DmaapSimParameterGroup params = handler.getParameters(args);
49         assertNotNull(params);
50         assertEquals("DMaapSim", params.getName());
51         assertEquals(300L, params.getTopicSweepSec());
52         assertEquals(6845, params.getRestServerParameters().getPort());
53
54
55         args.parse(new String[] {"-c", "FileNotFound.json"});
56         assertThatThrownBy(() -> handler.getParameters(args)).isInstanceOf(DmaapSimException.class)
57                         .hasMessageStartingWith("error reading parameters");
58
59
60         args.parse(new String[] {"-c", RESOURCE_DIR + "EmptyParameterFile.json"});
61         assertThatThrownBy(() -> handler.getParameters(args)).isInstanceOf(DmaapSimException.class)
62                         .hasMessageStartingWith("no parameters found");
63
64
65         args.parse(new String[] {"-c", RESOURCE_DIR + "Parameters_InvalidName.json"});
66         assertThatThrownBy(() -> handler.getParameters(args)).isInstanceOf(DmaapSimException.class)
67                         .hasMessageContaining("validation error");
68     }
69
70 }