2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.simulators;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
29 import org.junit.Test;
30 import org.onap.policy.common.parameters.BeanValidationResult;
31 import org.onap.policy.common.utils.coder.CoderException;
32 import org.onap.policy.common.utils.coder.StandardCoder;
34 public class SimulatorParametersTest {
37 public void testValidate() throws CoderException {
38 SimulatorParameters params = new StandardCoder().decode(new File("src/test/resources/simParameters.json"),
39 SimulatorParameters.class);
40 assertNull(params.validate("ValidParams").getResult());
44 public void testValidateEmptyRestServer() throws CoderException {
45 SimulatorParameters params = new StandardCoder()
46 .decode(new File("src/test/resources/emptyRestServer.json"), SimulatorParameters.class);
47 assertNull(params.validate("ValidParams").getResult());
51 public void testValidateInvalidDmaapProvider() throws CoderException {
52 SimulatorParameters params = new StandardCoder()
53 .decode(new File("src/test/resources/invalidDmaapProvider.json"), SimulatorParameters.class);
54 BeanValidationResult result = params.validate("InvalidDmaapParams");
55 assertFalse(result.isValid());
56 assertNotNull(result.getResult());
60 public void testValidateInvalidDmaapName() throws CoderException {
61 SimulatorParameters params = new StandardCoder().decode(
62 new File("src/test/resources/invalidDmaapName.json"), SimulatorParameters.class);
63 BeanValidationResult result = params.validate("InvalidDmaapParams");
64 assertFalse(result.isValid());
65 assertThat(result.getResult()).contains("item \"name\" value \"null\"");
69 public void testValidateInvalidTopicSweep() throws CoderException {
70 SimulatorParameters params = new StandardCoder().decode(
71 new File("src/test/resources/invalidTopicSweep.json"), SimulatorParameters.class);
72 BeanValidationResult result = params.validate("InvalidDmaapParams");
73 assertFalse(result.isValid());
74 assertThat(result.getResult()).contains("topicSweepSec");
78 public void testValidateInvalidGrpcServer() throws CoderException {
79 SimulatorParameters params = new StandardCoder()
80 .decode(new File("src/test/resources/invalidGrpcServer.json"), SimulatorParameters.class);
81 BeanValidationResult result = params.validate("InvalidGrpcParams");
82 assertFalse(result.isValid());
83 assertNotNull(result.getResult());