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
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.controlloop.participant.simulator.main.startstop;
23 import static org.assertj.core.api.Assertions.assertThatCode;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
28 import org.junit.Test;
29 import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
30 import org.onap.policy.common.utils.resources.MessageConstants;
33 * Class to perform unit test of {@link Main}}.
35 public class TestMain {
38 public void testMain_Help() {
39 final String[] configParameters = {"-h"};
40 Main main = new Main(configParameters);
41 assertFalse(main.isRunning());
45 public void testMain_Version() {
46 final String[] configParameters = {"-v"};
47 Main main = new Main(configParameters);
48 assertFalse(main.isRunning());
52 public void testMain_Valid() {
53 final String[] configParameters = {"-c", "src/test/resources/parameters/TestParameters.json"};
54 Main main = new Main(configParameters);
55 assertTrue(main.isRunning());
57 assertThatCode(() -> main.shutdown()).doesNotThrowAnyException();
59 assertFalse(main.isRunning());
63 public void testMain_NoParameter() {
64 assertThatConfigParameterThrownException(new String[] {});
68 public void testMain_FilePathNotDefined() {
69 assertThatConfigParameterThrownException(new String[] {"-c"});
73 public void testMain_TooManyCommand() {
74 assertThatConfigParameterThrownException(new String[] {"-h", "d"});
78 public void testMain_WrongParameter() {
79 assertThatConfigParameterThrownException(new String[] {"-d"});
82 private void assertThatConfigParameterThrownException(final String[] configParameters) {
83 assertThatThrownBy(() -> Main.main(configParameters)).isInstanceOf(ControlLoopRuntimeException.class)
84 .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_CLAMP));
88 public void testParticipant_NoFileWithThisName() {
89 assertThatConfigFileThrownException("src/test/resources/parameters/NoFileWithThisName.json");
93 public void testParticipant_NotValidFile() {
94 assertThatConfigFileThrownException("src/test/resources/parameters");
98 public void testParticipant_FileEmpty() {
99 assertThatConfigFileThrownException("src/test/resources/parameters/EmptyParameters.json");
103 public void testParticipant_NoParameters() {
104 assertThatConfigFileThrownException("src/test/resources/parameters/NoParameters.json");
108 public void testParticipant_InvalidParameters() {
109 assertThatConfigFileThrownException("src/test/resources/parameters/InvalidParameters.json");
112 private void assertThatConfigFileThrownException(final String configFilePath) {
113 final String[] configParameters = new String[] {"-c", configFilePath};
114 assertThatThrownBy(() -> new Main(configParameters)).isInstanceOf(ControlLoopRuntimeException.class)
115 .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_CLAMP));