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.assertNotNull;
27 import static org.junit.Assert.assertTrue;
29 import org.junit.AfterClass;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.onap.policy.clamp.controlloop.common.ControlLoopConstants;
33 import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
34 import org.onap.policy.common.utils.resources.MessageConstants;
37 * Class to perform unit test of {@link Main}}.
39 public class TestMain {
42 public void testMain_Help() {
43 final String[] configParameters = {"-h"};
44 Main main = new Main(configParameters);
45 assertFalse(main.isRunning());
49 public void testMain_Version() {
50 final String[] configParameters = {"-v"};
51 Main main = new Main(configParameters);
52 assertFalse(main.isRunning());
56 public void testMain_Valid() {
57 final String[] configParameters = {"-c", "src/test/resources/parameters/TestParameters.json"};
58 Main main = new Main(configParameters);
59 assertTrue(main.isRunning());
61 assertThatCode(() -> main.shutdown()).doesNotThrowAnyException();
63 assertFalse(main.isRunning());
67 public void testMain_NoParameter() {
68 assertThatConfigParameterThrownException(new String[] {});
72 public void testMain_FilePathNotDefined() {
73 assertThatConfigParameterThrownException(new String[] {"-c"});
77 public void testMain_TooManyCommand() {
78 assertThatConfigParameterThrownException(new String[] {"-h", "d"});
82 public void testMain_WrongParameter() {
83 assertThatConfigParameterThrownException(new String[] {"-d"});
86 private void assertThatConfigParameterThrownException(final String[] configParameters) {
87 assertThatThrownBy(() -> Main.main(configParameters)).isInstanceOf(ControlLoopRuntimeException.class)
88 .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_CLAMP));
92 public void testParticipant_NoFileWithThisName() {
93 assertThatConfigFileThrownException("src/test/resources/parameters/NoFileWithThisName.json");
97 public void testParticipant_NotValidFile() {
98 assertThatConfigFileThrownException("src/test/resources/parameters");
102 public void testParticipant_FileEmpty() {
103 assertThatConfigFileThrownException("src/test/resources/parameters/EmptyParameters.json");
107 public void testParticipant_NoParameters() {
108 assertThatConfigFileThrownException("src/test/resources/parameters/NoParameters.json");
112 public void testParticipant_InvalidParameters() {
113 assertThatConfigFileThrownException("src/test/resources/parameters/InvalidParameters.json");
116 private void assertThatConfigFileThrownException(final String configFilePath) {
117 final String[] configParameters = new String[] {"-c", configFilePath};
118 assertThatThrownBy(() -> new Main(configParameters)).isInstanceOf(ControlLoopRuntimeException.class)
119 .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_CLAMP));