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
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.
16 * ============LICENSE_END=========================================================
19 package org.onap.policy.sim.dmaap.parameters;
21 import static org.assertj.core.api.Assertions.assertThatThrownBy;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
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;
32 public class DmaapSimParameterHandlerTest {
34 private static final String RESOURCE_DIR = "src/test/resources/parameters/";
36 private DmaapSimParameterHandler handler;
40 handler = new DmaapSimParameterHandler();
44 public void testGetParameters() throws DmaapSimException {
45 final DmaapSimCommandLineArguments args = new DmaapSimCommandLineArguments();
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());
55 args.parse(new String[] {"-c", "FileNotFound.json"});
56 assertThatThrownBy(() -> handler.getParameters(args)).isInstanceOf(DmaapSimException.class)
57 .hasMessageStartingWith("error reading parameters");
60 args.parse(new String[] {"-c", RESOURCE_DIR + "EmptyParameterFile.json"});
61 assertThatThrownBy(() -> handler.getParameters(args)).isInstanceOf(DmaapSimException.class)
62 .hasMessageStartingWith("no parameters found");
65 args.parse(new String[] {"-c", RESOURCE_DIR + "Parameters_InvalidName.json"});
66 assertThatThrownBy(() -> handler.getParameters(args)).isInstanceOf(DmaapSimException.class)
67 .hasMessageContaining("validation error");