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.policy.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.policy.main.parameters.CommonTestData;
32 import org.onap.policy.clamp.controlloop.participant.policy.main.parameters.ParticipantPolicyParameterHandler;
33 import org.onap.policy.clamp.controlloop.participant.policy.main.parameters.ParticipantPolicyParameters;
34 import org.onap.policy.common.utils.services.Registry;
36 public class TestParticipantPolicyActivator {
38 private static ParticipantPolicyActivator activator;
41 * Initializes an activator.
43 * @throws Exception if an error occurs
46 public static void setUp() throws Exception {
47 Registry.newRegistry();
48 final String[] participantConfigParameters = { "-c", "src/test/resources/parameters/TestParameters.json"};
49 final ParticipantPolicyCommandLineArguments arguments =
50 new ParticipantPolicyCommandLineArguments(participantConfigParameters);
51 final ParticipantPolicyParameters parGroup =
52 new ParticipantPolicyParameterHandler().getParameters(arguments);
53 activator = new ParticipantPolicyActivator(parGroup);
57 * Method for cleanup after each test.
59 * @throws Exception if an error occurs
62 public static void teardown() throws Exception {
63 // shut down activator
64 if (activator != null && activator.isAlive()) {
70 public void testParticipantActivator() {
72 assertTrue(activator.isAlive());
73 assertTrue(activator.getParameters().isValid());
74 assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, activator.getParameters().getName());
76 // repeat - should throw an exception
77 assertThatIllegalStateException().isThrownBy(() -> activator.start());
78 assertTrue(activator.isAlive());
79 assertTrue(activator.getParameters().isValid());
82 assertFalse(activator.isAlive());
84 // repeat - should throw an exception
85 assertThatIllegalStateException().isThrownBy(() -> activator.shutdown());
86 assertFalse(activator.isAlive());