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.assertThatIllegalStateException;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
28 import org.junit.AfterClass;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.CommonTestData;
32 import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.ParticipantSimulatorParameterHandler;
33 import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.ParticipantSimulatorParameters;
36 * Class to perform unit test of {@link ParticipantActivator}}.
38 public class TestParticipantSimulatorActivator {
40 private static ParticipantSimulatorActivator activator;
43 * Initializes an activator.
45 * @throws Exception if an error occurs
48 public static void setUp() throws Exception {
49 final String[] participantConfigParameters = { "-c", "src/test/resources/parameters/TestParameters.json"};
50 final ParticipantSimulatorCommandLineArguments arguments =
51 new ParticipantSimulatorCommandLineArguments(participantConfigParameters);
52 final ParticipantSimulatorParameters parGroup =
53 new ParticipantSimulatorParameterHandler().getParameters(arguments);
54 activator = new ParticipantSimulatorActivator(parGroup);
58 * Method for cleanup after each test.
60 * @throws Exception if an error occurs
63 public static void teardown() throws Exception {
64 // shut down activator
65 if (activator != null && activator.isAlive()) {
71 public void testParticipantActivator() {
73 assertTrue(activator.isAlive());
74 assertTrue(activator.getParameters().isValid());
75 assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, activator.getParameters().getName());
77 // repeat - should throw an exception
78 assertThatIllegalStateException().isThrownBy(() -> activator.start());
79 assertTrue(activator.isAlive());
80 assertTrue(activator.getParameters().isValid());
83 assertFalse(activator.isAlive());
85 // repeat - should throw an exception
86 assertThatIllegalStateException().isThrownBy(() -> activator.shutdown());
87 assertFalse(activator.isAlive());