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
10 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.policy.sim.dmaap.parameters;
22 import static org.assertj.core.api.Assertions.assertThatThrownBy;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
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;
34 public class DmaapSimParameterHandlerTest {
36 private static final String RESOURCE_DIR = "src/test/resources/parameters/";
38 private DmaapSimParameterHandler handler;
42 handler = new DmaapSimParameterHandler();
46 public void testGetParameters() throws DmaapSimException, CommandLineException {
47 final DmaapSimCommandLineArguments args = new DmaapSimCommandLineArguments();
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());
57 args.parse(new String[] {"-c", "FileNotFound.json"});
58 assertThatThrownBy(() -> handler.getParameters(args)).isInstanceOf(DmaapSimException.class)
59 .hasMessageStartingWith("error reading parameters");
62 args.parse(new String[] {"-c", RESOURCE_DIR + "EmptyParameterFile.json"});
63 assertThatThrownBy(() -> handler.getParameters(args)).isInstanceOf(DmaapSimException.class)
64 .hasMessageStartingWith("no parameters found");
67 args.parse(new String[] {"-c", RESOURCE_DIR + "Parameters_InvalidName.json"});
68 assertThatThrownBy(() -> handler.getParameters(args)).isInstanceOf(DmaapSimException.class)
69 .hasMessageContaining("validation error");