/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.onap.policy.common.parameters.ParameterGroupImpl;
import org.onap.policy.common.parameters.annotations.Min;
import org.onap.policy.common.parameters.annotations.NotBlank;
-import org.onap.policy.common.parameters.annotations.NotNull;
/**
* Class to hold all parameters needed for the DMaaP simulator component.
*/
-@NotNull
@NotBlank
@Getter
public class DmaapSimParameterGroup extends ParameterGroupImpl {
}
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
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(),
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 {
/**
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"));
@Test
public void testConstructor() throws Exception {
- assertThatIllegalArgumentException().isThrownBy(() -> new Main("invalidSimParameters.json"))
+ assertThatIllegalArgumentException().isThrownBy(() -> new Main("invalidDmaapParameters.json"))
.withMessage("invalid simulator parameters");
}
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));
}
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();
@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());
}
}
--- /dev/null
+{
+ "dmaapProvider": {},
+ "restServers": [],
+ "topicSinks": [],
+ "topicSources": [],
+ "topicServers": []
+}
--- /dev/null
+{
+ "grpcServer": {},
+ "restServers": [],
+ "topicSinks": [],
+ "topicSources": [],
+ "topicServers": []
+}
--- /dev/null
+{
+ "restServers": [
+ {
+ "name": "A&AI simulator",
+ "providerClass": "org.onap.policy.simulators.AaiSimulatorJaxRs",
+ "host": "localhost",
+ "port": 6766,
+ "https": true
+ }
+ ],
+ "topicSinks": [],
+ "topicSources": [],
+ "topicServers": []
+}
{
"dmaapProvider": {
"name": "DMaaP simulator",
- "topicSweepSec": 300,
- "restServerParameters": {
-
- }
+ "topicSweepSec": 300
},
"restServers": [
{