2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019 AT&T Intellectual Property.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.pap.main.parameters;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
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;
34 * Class to perform unit test of {@link PapParameterGroup}.
36 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
38 public class TestPapParameterGroup {
39 private static final Coder coder = new StandardCoder();
41 CommonTestData commonTestData = new CommonTestData();
44 public void testPapParameterGroup_Named() {
45 final PapParameterGroup papParameters = new PapParameterGroup("my-name");
46 assertEquals("my-name", papParameters.getName());
50 public void testPapParameterGroup() {
51 final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(1);
52 final RestServerParameters restServerParameters = papParameters.getRestServerParameters();
53 final GroupValidationResult validationResult = papParameters.validate();
54 assertTrue(validationResult.isValid());
55 assertEquals(CommonTestData.PAP_GROUP_NAME, papParameters.getName());
56 assertEquals(restServerParameters.getHost(), papParameters.getRestServerParameters().getHost());
57 assertEquals(restServerParameters.getPort(), papParameters.getRestServerParameters().getPort());
58 assertEquals(restServerParameters.getUserName(), papParameters.getRestServerParameters().getUserName());
59 assertEquals(restServerParameters.getPassword(), papParameters.getRestServerParameters().getPassword());
60 assertTrue(papParameters.getRestServerParameters().isHttps());
61 assertFalse(papParameters.getRestServerParameters().isAaf());
65 public void testPapParameterGroup_NullName() throws Exception {
66 String json = commonTestData.getPapParameterGroupAsString(1).replace("\"PapGroup\"", "null");
67 final PapParameterGroup papParameters = coder.decode(json, PapParameterGroup.class);
68 final GroupValidationResult validationResult = papParameters.validate();
69 assertFalse(validationResult.isValid());
70 assertEquals(null, papParameters.getName());
71 assertTrue(validationResult.getResult().contains("is null"));
75 public void testPapParameterGroup_EmptyName() throws Exception {
76 String json = commonTestData.getPapParameterGroupAsString(1).replace(CommonTestData.PAP_GROUP_NAME, "");
77 final PapParameterGroup papParameters = coder.decode(json, PapParameterGroup.class);
78 final GroupValidationResult validationResult = papParameters.validate();
79 assertFalse(validationResult.isValid());
80 assertEquals("", papParameters.getName());
81 assertTrue(validationResult.getResult().contains(
82 "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
86 public void testPapParameterGroup_SetName() {
87 final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(1);
88 papParameters.setName("PapNewGroup");
89 final GroupValidationResult validationResult = papParameters.validate();
90 assertTrue(validationResult.isValid());
91 assertEquals("PapNewGroup", papParameters.getName());
95 public void testApiParameterGroup_EmptyRestServerParameters() throws Exception {
96 String json = commonTestData.getPapParameterGroupAsString(1);
97 json = commonTestData.nullifyField(json, "restServerParameters");
98 final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(0);
99 final GroupValidationResult validationResult = papParameters.validate();
100 assertFalse(validationResult.isValid());
101 assertTrue(validationResult.getResult()
102 .contains("\"org.onap.policy.pap.main.parameters.RestServerParameters\" INVALID, "
103 + "parameter group has status INVALID"));