2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019, 2021 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.pap.main.parameters;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
29 import org.junit.Test;
30 import org.onap.policy.common.parameters.ValidationResult;
31 import org.onap.policy.common.utils.coder.Coder;
32 import org.onap.policy.common.utils.coder.StandardCoder;
34 public class TestPdpRequestParameters {
35 private static final Coder coder = new StandardCoder();
38 public void test() throws Exception {
39 PdpRequestParameters params = makeParams(10, 20);
40 assertEquals(10, params.getMaxRetryCount());
41 assertEquals(20, params.getMaxWaitMs());
45 public void testValidate() throws Exception {
47 PdpRequestParameters params = makeParams(0, 0);
48 ValidationResult result = params.validate();
49 assertNull(result.getResult());
50 assertTrue(result.isValid());
53 params = makeParams(100, 110);
54 result = params.validate();
55 assertNull(result.getResult());
56 assertTrue(result.isValid());
58 // invalid retry count
59 params = makeParams(-1, 120);
60 result = params.validate();
61 assertFalse(result.isValid());
62 assertThat(result.getResult()).contains(
63 "'maxRetryCount' value '-1' INVALID, is below the minimum value: 0".replace('\'', '"'));
66 params = makeParams(130, -1);
67 result = params.validate();
68 assertFalse(result.isValid());
69 assertThat(result.getResult()).contains(
70 "'maxWaitMs' value '-1' INVALID, is below the minimum value: 0".replace('\'', '"'));
73 private PdpRequestParameters makeParams(int maxRetry, long maxWait) throws Exception {
74 String json = "{'name':'abc', 'maxRetryCount':" + maxRetry + ", 'maxWaitMs':" + maxWait + "}";
75 return coder.decode(json.replace('\'', '"'), PdpRequestParameters.class);