2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
28 import org.junit.Test;
29 import org.onap.policy.common.parameters.GroupValidationResult;
30 import org.onap.policy.common.utils.coder.Coder;
31 import org.onap.policy.common.utils.coder.StandardCoder;
33 public class TestPdpRequestParameters {
34 private static final Coder coder = new StandardCoder();
37 public void test() throws Exception {
38 PdpRequestParameters params = makeParams(10, 20);
39 assertEquals(10, params.getMaxRetryCount());
40 assertEquals(20, params.getMaxWaitMs());
44 public void testValidate() throws Exception {
46 PdpRequestParameters params = makeParams(0, 0);
47 GroupValidationResult result = params.validate();
48 assertNull(result.getResult());
49 assertTrue(result.isValid());
52 params = makeParams(100, 110);
53 result = params.validate();
54 assertNull(result.getResult());
55 assertTrue(result.isValid());
57 // invalid retry count
58 params = makeParams(-1, 120);
59 result = params.validate();
60 assertFalse(result.isValid());
61 assertTrue(result.getResult().contains(
62 "field 'maxRetryCount' type 'int' value '-1' INVALID, must be >= 0".replace('\'', '"')));
65 params = makeParams(130, -1);
66 result = params.validate();
67 assertFalse(result.isValid());
68 assertTrue(result.getResult()
69 .contains("field 'maxWaitMs' type 'long' value '-1' INVALID, must be >= 0".replace('\'', '"')));
72 private PdpRequestParameters makeParams(int maxRetry, long maxWait) throws Exception {
73 String json = "{'name':'abc', 'maxRetryCount':" + maxRetry + ", 'maxWaitMs':" + maxWait + "}";
74 return coder.decode(json.replace('\'', '"'), PdpRequestParameters.class);