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.runtime.main.startstop;
23 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
24 import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertTrue;
29 import org.junit.Test;
30 import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
31 import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
32 import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterHandler;
33 import org.onap.policy.common.utils.services.Registry;
36 * Class to perform unit test of {@link ClRuntimeActivator}}.
39 public class ClRuntimeActivatorTest {
42 public void testStartAndStop() throws Exception {
43 Registry.newRegistry();
44 final String[] configParameters = {"-c", "src/test/resources/parameters/TestParameters.json"};
45 final ClRuntimeCommandLineArguments arguments = new ClRuntimeCommandLineArguments();
46 arguments.parse(configParameters);
47 ClRuntimeParameterGroup parameterGroup = new ClRuntimeParameterHandler().getParameters(arguments);
48 ClRuntimeActivator activator = new ClRuntimeActivator(parameterGroup);
51 assertFalse(activator.isAlive());
53 assertTrue(activator.isAlive());
54 assertTrue(activator.getParameterGroup().isValid());
55 assertEquals(activator.getParameterGroup().getName(),
56 activator.getParameterGroup().getRestServerParameters().getName());
58 // repeat start - should throw an exception
59 assertThatIllegalStateException().isThrownBy(() -> activator.start());
60 assertTrue(activator.isAlive());
61 assertTrue(activator.getParameterGroup().isValid());
64 assertFalse(activator.isAlive());
66 // repeat stop - should throw an exception
67 assertThatIllegalStateException().isThrownBy(() -> activator.stop());
68 assertFalse(activator.isAlive());
72 public void testNull() {
73 assertThatExceptionOfType(ControlLoopRuntimeException.class).isThrownBy(() -> new ClRuntimeActivator(null));
77 public void testNotValid() {
78 ClRuntimeParameterGroup parameterGroup = new ClRuntimeParameterGroup("name");
79 assertThatExceptionOfType(ControlLoopRuntimeException.class)
80 .isThrownBy(() -> new ClRuntimeActivator(parameterGroup));