Remove annotations from dmaap common test class
[policy/models.git] / models-sim / models-sim-dmaap / src / test / java / org / onap / policy / sim / dmaap / startstop / DmaapSimActivatorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2020 AT&T Intellectual Property.
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.sim.dmaap.startstop;
22
23 import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
31 import org.onap.policy.common.utils.services.Registry;
32 import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
33 import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterHandler;
34 import org.onap.policy.models.sim.dmaap.rest.CommonRestServer;
35 import org.onap.policy.models.sim.dmaap.startstop.DmaapSimActivator;
36 import org.onap.policy.models.sim.dmaap.startstop.DmaapSimCommandLineArguments;
37
38
39 /**
40  * Class to perform unit test of {@link DmaapSimActivator}}.
41  */
42 public class DmaapSimActivatorTest extends CommonRestServer {
43
44     private DmaapSimActivator activator;
45
46     /**
47      * Initializes an activator.
48      *
49      * @throws Exception if an error occurs
50      */
51     @Before
52     public void setUp() throws Exception {
53         Registry.newRegistry();
54         HttpServletServerFactoryInstance.getServerFactory().destroy();
55
56         CommonRestServer.reconfigure();
57
58         final String[] papConfigParameters = {"-c", CONFIG_FILE};
59         final DmaapSimCommandLineArguments arguments = new DmaapSimCommandLineArguments(papConfigParameters);
60         final DmaapSimParameterGroup parGroup = new DmaapSimParameterHandler().getParameters(arguments);
61
62         activator = new DmaapSimActivator(parGroup);
63     }
64
65     /**
66      * Method for cleanup after each test.
67      *
68      * @throws Exception if an error occurs
69      */
70     @After
71     public void teardown() throws Exception {
72         if (activator != null && activator.isAlive()) {
73             activator.stop();
74         }
75     }
76
77     @Test
78     public void testDmaapSimActivator() {
79         assertFalse(activator.isAlive());
80         activator.start();
81         assertTrue(activator.isAlive());
82
83         // repeat - should throw an exception
84         assertThatIllegalStateException().isThrownBy(() -> activator.start());
85         assertTrue(activator.isAlive());
86     }
87
88     @Test
89     public void testTerminate() {
90         activator.start();
91         activator.stop();
92         assertFalse(activator.isAlive());
93
94         // repeat - should throw an exception
95         assertThatIllegalStateException().isThrownBy(() -> activator.stop());
96         assertFalse(activator.isAlive());
97     }
98 }