diff options
author | Jim Hahn <jrh3@att.com> | 2019-07-31 09:45:27 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-10-07 12:04:25 -0400 |
commit | aa148d9b5bba6ad23736e939a6d0ec917e761e1e (patch) | |
tree | 5c3f0d4e552b1cfa43b3ff0ed8b956bee3d31e68 /models-interactions/model-simulators/src/main/java | |
parent | 5af913104ec412086deab4d599359751246e4ba3 (diff) |
Flesh out DMaaP simulator
Fleshed out the dmaap simulator with additional media types.
Added more junit tests.
Added buildDmaapSim() to simulators Util.
Change-Id: I39acd3df8e8d0ded21228e56fa1ef919cafc3772
Issue-ID: POLICY-2144
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-simulators/src/main/java')
-rw-r--r-- | models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java | 40 |
1 files changed, 39 insertions, 1 deletions
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; + } } |