98615af0ca361a3bdb4d17a0d826644b04a274f3
[policy/distribution.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2022 Nordix Foundation.
4  *  Modifications Copyright (C) 2022 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.distribution.forwarding.testclasses;
23
24 import org.onap.policy.common.endpoints.http.server.RestServer;
25 import org.onap.policy.common.endpoints.parameters.RestServerParameters;
26 import org.onap.policy.common.utils.coder.CoderException;
27 import org.onap.policy.common.utils.coder.StandardCoder;
28 import org.onap.policy.common.utils.resources.ResourceUtils;
29 import org.onap.policy.distribution.forwarding.PolicyForwardingException;
30 import org.onap.policy.distribution.forwarding.lifecycle.api.LifecycleApiAutomationCompositionForwarder;
31 import org.onap.policy.distribution.main.rest.aaf.AafDistributionFilter;
32
33 /**
34  * The class for starting/stopping simulator for testing {@link LifecycleApiAutomationCompositionForwarder} .
35  *
36  * @author Sirisha Manchikanti (sirisha.manchikanti@est.tech)
37  */
38 public class LifecycleApiAutomationCompositionSimulatorMain {
39     private RestServer restServer;
40
41     /**
42      * Starts the simulator.
43      *
44      * @throws PolicyForwardingException if error occurs
45      * @throws CoderException if error occurs
46      */
47     public void startLifecycycleApiSimulator() throws PolicyForwardingException, CoderException {
48         final StandardCoder standardCoder = new StandardCoder();
49         final RestServerParameters restServerParameters = standardCoder.decode(
50                 ResourceUtils.getResourceAsString("src/test/resources/parameters/RestServerParameters.json"),
51                 RestServerParameters.class);
52         restServer = new RestServer(restServerParameters, AafDistributionFilter.class,
53                 LifecycleApiAutomationCompositionSimulatorEndpoint.class);
54         if (!restServer.start()) {
55             throw new PolicyForwardingException("Failed to start rest simulator. Check log for more details...");
56         }
57     }
58
59     /**
60      * Shut down Execution.
61      */
62     public void stopLifecycycleApiSimulator() {
63         if (restServer != null) {
64             restServer.stop();
65         }
66     }
67 }