X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-interactions%2Fmodel-simulators%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fsimulators%2FUtil.java;h=6c1a057536a6fdecef243639eae3d48569015613;hb=aa148d9b5bba6ad23736e939a6d0ec917e761e1e;hp=a1d28ba239fe44f50e3c7eb6e1c58798bcedeeff;hpb=5af913104ec412086deab4d599359751246e4ba3;p=policy%2Fmodels.git diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java index a1d28ba23..6c1a05753 100644 --- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java @@ -22,11 +22,18 @@ package org.onap.policy.simulators; import java.io.IOException; - +import java.util.Properties; import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; +import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.onap.policy.common.gson.GsonMessageBodyHandler; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.network.NetworkUtil; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup; +import org.onap.policy.models.sim.dmaap.provider.DmaapSimProvider; +import org.onap.policy.models.sim.dmaap.rest.DmaapSimRestServer; public class Util { public static final String AAISIM_SERVER_NAME = "aaiSim"; @@ -40,6 +47,7 @@ public class Util { public static final int VFCSIM_SERVER_PORT = 6668; public static final int GUARDSIM_SERVER_PORT = 6669; public static final int SDNCSIM_SERVER_PORT = 6670; + public static final int DMAAPSIM_SERVER_PORT = 3904; private static final String CANNOT_CONNECT = "cannot connect to port "; private static final String LOCALHOST = "localhost"; @@ -139,4 +147,34 @@ public class Util { } return testServer; } + + /** + * Build a DMaaP simulator. + * + * @return the simulator + * @throws InterruptedException if a thread is interrupted + * @throws IOException if an IO errror occurs + * @throws CoderException if the server parameters cannot be loaded + */ + public static HttpServletServer buildDmaapSim() throws InterruptedException, IOException, CoderException { + String json = ResourceUtils.getResourceAsString("org/onap/policy/simulators/dmaap/DmaapParameters.json"); + DmaapSimParameterGroup params = new StandardCoder().decode(json, DmaapSimParameterGroup.class); + + DmaapSimProvider.setInstance(new DmaapSimProvider(params)); + + Properties props = DmaapSimRestServer.getServerProperties(params.getRestServerParameters()); + + final String svcpfx = PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + + params.getRestServerParameters().getName(); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, + Integer.toString(DMAAPSIM_SERVER_PORT)); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); + + HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory().build(props).get(0); + testServer.waitedStart(5000); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 50, 1000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); + } + return testServer; + } }