2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.simulators;
24 import java.io.IOException;
26 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
27 import org.onap.policy.common.gson.GsonMessageBodyHandler;
28 import org.onap.policy.common.utils.network.NetworkUtil;
31 public static final String AAISIM_SERVER_NAME = "aaiSim";
32 public static final String SOSIM_SERVER_NAME = "soSim";
33 public static final String VFCSIM_SERVER_NAME = "vfcSim";
34 public static final String GUARDSIM_SERVER_NAME = "guardSim";
35 public static final String SDNCSIM_SERVER_NAME = "sdncSim";
37 public static final int AAISIM_SERVER_PORT = 6666;
38 public static final int SOSIM_SERVER_PORT = 6667;
39 public static final int VFCSIM_SERVER_PORT = 6668;
40 public static final int GUARDSIM_SERVER_PORT = 6669;
41 public static final int SDNCSIM_SERVER_PORT = 6670;
43 private static final String CANNOT_CONNECT = "cannot connect to port ";
44 private static final String LOCALHOST = "localhost";
47 // Prevent instantiation of thic class
51 * Build an A&AI simulator.
53 * @return the simulator
54 * @throws InterruptedException if a thread is interrupted
55 * @throws IOException if an IO errror occurs
57 public static HttpServletServer buildAaiSim() throws InterruptedException, IOException {
58 final HttpServletServer testServer =
59 HttpServletServer.factory.build(AAISIM_SERVER_NAME, LOCALHOST, AAISIM_SERVER_PORT, "/", false, true);
60 testServer.addServletClass("/*", AaiSimulatorJaxRs.class.getName());
61 testServer.waitedStart(5000);
62 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
63 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
69 * Build an SDNC simulator.
71 * @return the simulator
72 * @throws InterruptedException if a thread is interrupted
73 * @throws IOException if an IO errror occurs
75 public static HttpServletServer buildSdncSim() throws InterruptedException, IOException {
76 final HttpServletServer testServer =
77 HttpServletServer.factory.build(SDNCSIM_SERVER_NAME, LOCALHOST, SDNCSIM_SERVER_PORT, "/", false, true);
78 testServer.addServletClass("/*", SdncSimulatorJaxRs.class.getName());
79 testServer.waitedStart(5000);
80 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
81 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
88 * Build an SO simulator.
90 * @return the simulator
91 * @throws InterruptedException if a thread is interrupted
92 * @throws IOException if an IO errror occurs
94 public static HttpServletServer buildSoSim() throws InterruptedException, IOException {
95 final HttpServletServer testServer =
96 HttpServletServer.factory.build(SOSIM_SERVER_NAME, LOCALHOST, SOSIM_SERVER_PORT, "/", false, true);
97 testServer.addServletClass("/*", SoSimulatorJaxRs.class.getName());
98 testServer.waitedStart(5000);
99 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
100 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
106 * Build a VFC simulator.
108 * @return the simulator
109 * @throws InterruptedException if a thread is interrupted
110 * @throws IOException if an IO errror occurs
112 public static HttpServletServer buildVfcSim() throws InterruptedException, IOException {
113 final HttpServletServer testServer =
114 HttpServletServer.factory.build(VFCSIM_SERVER_NAME,LOCALHOST, VFCSIM_SERVER_PORT, "/", false, true);
115 testServer.addServletClass("/*", VfcSimulatorJaxRs.class.getName());
116 testServer.waitedStart(5000);
117 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
118 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
124 * Build a guard simulator.
126 * @return the simulator
127 * @throws InterruptedException if a thread is interrupted
128 * @throws IOException if an IO errror occurs
130 public static HttpServletServer buildGuardSim() throws InterruptedException, IOException {
131 HttpServletServer testServer = HttpServletServer.factory.build(GUARDSIM_SERVER_NAME, LOCALHOST,
132 GUARDSIM_SERVER_PORT, "/", false, true);
133 testServer.setSerializationProvider(GsonMessageBodyHandler.class.getName());
134 testServer.addServletClass("/*", GuardSimulatorJaxRs.class.getName());
135 testServer.waitedStart(5000);
136 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
137 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());