aboutsummaryrefslogtreecommitdiffstats
path: root/models-sim/policy-models-simulators/src
diff options
context:
space:
mode:
Diffstat (limited to 'models-sim/policy-models-simulators/src')
-rw-r--r--models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java18
-rw-r--r--models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java10
-rw-r--r--models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/MainTest.java11
-rw-r--r--models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/SimulatorParametersTest.java18
-rw-r--r--models-sim/policy-models-simulators/src/test/resources/invalidDmaapParameters.json7
-rw-r--r--models-sim/policy-models-simulators/src/test/resources/invalidGrpcParameters.json7
-rw-r--r--models-sim/policy-models-simulators/src/test/resources/invalidSimParameters.json2
-rw-r--r--models-sim/policy-models-simulators/src/test/resources/minParameters.json14
-rw-r--r--models-sim/policy-models-simulators/src/test/resources/simParameters.json5
9 files changed, 71 insertions, 21 deletions
diff --git a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java
index a0fafbc9b..f82423c11 100644
--- a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java
+++ b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java
@@ -83,18 +83,22 @@ public class Main extends ServiceManagerContainer {
}
DmaapSimParameterGroup dmaapProv = params.getDmaapProvider();
- String dmaapName = dmaapProv.getName();
- String provName = dmaapName.replace("simulator", "provider");
+ String dmaapName = (dmaapProv != null ? dmaapProv.getName() : null);
// dmaap provider
- AtomicReference<DmaapSimProvider> provRef = new AtomicReference<>();
- addAction(provName, () -> provRef.set(buildDmaapProvider(dmaapProv)), () -> provRef.get().shutdown());
+ if (dmaapProv != null) {
+ String provName = dmaapName.replace("simulator", "provider");
+ AtomicReference<DmaapSimProvider> provRef = new AtomicReference<>();
+ addAction(provName, () -> provRef.set(buildDmaapProvider(dmaapProv)), () -> provRef.get().shutdown());
+ }
CdsServerParameters cdsServer = params.getGrpcServer();
// Cds Simulator
- AtomicReference<CdsSimulator> cdsSim = new AtomicReference<>();
- addAction(cdsServer.getName(), () -> cdsSim.set(buildCdsSimulator(cdsServer)), () -> cdsSim.get().stop());
+ if (cdsServer != null) {
+ AtomicReference<CdsSimulator> cdsSim = new AtomicReference<>();
+ addAction(cdsServer.getName(), () -> cdsSim.set(buildCdsSimulator(cdsServer)), () -> cdsSim.get().stop());
+ }
// REST server simulators
// @formatter:off
@@ -276,7 +280,7 @@ public class Main extends ServiceManagerContainer {
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SWAGGER_SUFFIX, "false");
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
- if (dmaapName.equals(params.getName())) {
+ if (dmaapName != null && dmaapName.equals(params.getName())) {
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER,
String.join(",", CambriaMessageBodyHandler.class.getName(),
GsonMessageBodyHandler.class.getName(),
diff --git a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java
index 788829f36..c22527165 100644
--- a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java
+++ b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java
@@ -27,14 +27,12 @@ import lombok.Getter;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.BeanValidator;
-import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
/**
* Simulator parameters.
*/
@Getter
-@NotNull
public class SimulatorParameters {
/**
@@ -77,6 +75,14 @@ public class SimulatorParameters {
public BeanValidationResult validate(String containerName) {
BeanValidationResult result = new BeanValidator().validateTop(containerName, this);
+ if (dmaapProvider != null) {
+ result.addResult(dmaapProvider.validate());
+ }
+
+ if (grpcServer != null) {
+ result.addResult(grpcServer.validate());
+ }
+
result.validateList("restServers", restServers, params -> params.validate("restServers"));
result.validateList("topicServers", topicServers, params -> params.validate("topicServers"));
diff --git a/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/MainTest.java b/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/MainTest.java
index e9e8cbdec..abc27f428 100644
--- a/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/MainTest.java
+++ b/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/MainTest.java
@@ -109,7 +109,7 @@ public class MainTest {
@Test
public void testConstructor() throws Exception {
- assertThatIllegalArgumentException().isThrownBy(() -> new Main("invalidSimParameters.json"))
+ assertThatIllegalArgumentException().isThrownBy(() -> new Main("invalidDmaapParameters.json"))
.withMessage("invalid simulator parameters");
}
@@ -125,7 +125,7 @@ public class MainTest {
Main.main(new String[] {PARAMETER_FILE});
// don't need to wait long, because buildXxx() does the wait for us
- for (int port = 6666; port <= 6670; ++port) {
+ for (int port : new int[] {6666, 6667, 6668, 6669, 6670, 6680}) {
assertTrue("simulator on port " + port, NetworkUtil.isTcpPortOpen(HOST, port, 1, 100));
}
@@ -133,6 +133,13 @@ public class MainTest {
checkAai();
}
+ @Test
+ public void testMainMinimalParameters() {
+ Main.main(new String[] {"minParameters.json"});
+ assertNotNull(Main.getInstance());
+ assertTrue(Main.getInstance().isAlive());
+ }
+
private void checkAai() throws HttpClientConfigException {
BusTopicParams params = BusTopicParams.builder().clientName("client").hostname(HOST).port(6666).useHttps(true)
.allowSelfSignedCerts(true).basePath("aai").build();
diff --git a/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/SimulatorParametersTest.java b/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/SimulatorParametersTest.java
index 5294ca483..f8d7433d2 100644
--- a/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/SimulatorParametersTest.java
+++ b/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/SimulatorParametersTest.java
@@ -34,14 +34,24 @@ public class SimulatorParametersTest {
@Test
public void testValidate() throws CoderException {
- // some fields missing
- BeanValidationResult result = new SimulatorParameters().validate("InvalidParams");
- assertFalse(result.isValid());
- assertNotNull(result.getResult());
// everything populated
SimulatorParameters params = new StandardCoder().decode(new File("src/test/resources/simParameters.json"),
SimulatorParameters.class);
assertNull(params.validate("ValidParams").getResult());
+
+ // invalid dmaap provider
+ params = new StandardCoder().decode(new File("src/test/resources/invalidDmaapParameters.json"),
+ SimulatorParameters.class);
+ BeanValidationResult result = params.validate("InvalidDmaapParams");
+ assertFalse(result.isValid());
+ assertNotNull(result.getResult());
+
+ // invalid grpc server
+ params = new StandardCoder().decode(new File("src/test/resources/invalidGrpcParameters.json"),
+ SimulatorParameters.class);
+ result = params.validate("InvalidGrpcParams");
+ assertFalse(result.isValid());
+ assertNotNull(result.getResult());
}
}
diff --git a/models-sim/policy-models-simulators/src/test/resources/invalidDmaapParameters.json b/models-sim/policy-models-simulators/src/test/resources/invalidDmaapParameters.json
new file mode 100644
index 000000000..ff6790144
--- /dev/null
+++ b/models-sim/policy-models-simulators/src/test/resources/invalidDmaapParameters.json
@@ -0,0 +1,7 @@
+{
+ "dmaapProvider": {},
+ "restServers": [],
+ "topicSinks": [],
+ "topicSources": [],
+ "topicServers": []
+}
diff --git a/models-sim/policy-models-simulators/src/test/resources/invalidGrpcParameters.json b/models-sim/policy-models-simulators/src/test/resources/invalidGrpcParameters.json
new file mode 100644
index 000000000..86e425364
--- /dev/null
+++ b/models-sim/policy-models-simulators/src/test/resources/invalidGrpcParameters.json
@@ -0,0 +1,7 @@
+{
+ "grpcServer": {},
+ "restServers": [],
+ "topicSinks": [],
+ "topicSources": [],
+ "topicServers": []
+}
diff --git a/models-sim/policy-models-simulators/src/test/resources/invalidSimParameters.json b/models-sim/policy-models-simulators/src/test/resources/invalidSimParameters.json
deleted file mode 100644
index 2c63c0851..000000000
--- a/models-sim/policy-models-simulators/src/test/resources/invalidSimParameters.json
+++ /dev/null
@@ -1,2 +0,0 @@
-{
-}
diff --git a/models-sim/policy-models-simulators/src/test/resources/minParameters.json b/models-sim/policy-models-simulators/src/test/resources/minParameters.json
new file mode 100644
index 000000000..c7ea49874
--- /dev/null
+++ b/models-sim/policy-models-simulators/src/test/resources/minParameters.json
@@ -0,0 +1,14 @@
+{
+ "restServers": [
+ {
+ "name": "A&AI simulator",
+ "providerClass": "org.onap.policy.simulators.AaiSimulatorJaxRs",
+ "host": "localhost",
+ "port": 6766,
+ "https": true
+ }
+ ],
+ "topicSinks": [],
+ "topicSources": [],
+ "topicServers": []
+}
diff --git a/models-sim/policy-models-simulators/src/test/resources/simParameters.json b/models-sim/policy-models-simulators/src/test/resources/simParameters.json
index 1d1c0aad7..df8de6ff7 100644
--- a/models-sim/policy-models-simulators/src/test/resources/simParameters.json
+++ b/models-sim/policy-models-simulators/src/test/resources/simParameters.json
@@ -1,10 +1,7 @@
{
"dmaapProvider": {
"name": "DMaaP simulator",
- "topicSweepSec": 300,
- "restServerParameters": {
-
- }
+ "topicSweepSec": 300
},
"restServers": [
{