2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
22 package org.onap.policy.pdpx.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;
32 * Class to perform unit test of XacmlPdpParameterGroup.
35 public class TestXacmlPdpParameterGroup {
36 CommonTestData commonTestData = new CommonTestData();
39 public void testXacmlPdpParameterGroup() {
40 final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
41 final XacmlPdpParameterGroup pdpxParameters =
42 new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters);
43 final GroupValidationResult validationResult = pdpxParameters.validate();
44 assertTrue(validationResult.isValid());
45 assertEquals(restServerParameters.getHost(), pdpxParameters.getRestServerParameters().getHost());
46 assertEquals(restServerParameters.getPort(), pdpxParameters.getRestServerParameters().getPort());
47 assertEquals(restServerParameters.getUserName(), pdpxParameters.getRestServerParameters().getUserName());
48 assertEquals(restServerParameters.getPassword(), pdpxParameters.getRestServerParameters().getPassword());
49 assertEquals(CommonTestData.PDPX_GROUP_NAME, pdpxParameters.getName());
50 assertFalse(pdpxParameters.getRestServerParameters().isHttps());
51 assertFalse(pdpxParameters.getRestServerParameters().isAaf());
55 public void testXacmlPdpParameterGroup_NullName() {
56 final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
57 final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(null, restServerParameters);
58 final GroupValidationResult validationResult = pdpxParameters.validate();
59 assertFalse(validationResult.isValid());
60 assertEquals(null, pdpxParameters.getName());
61 assertTrue(validationResult.getResult().contains(
62 "field \"name\" type \"java.lang.String\" value \"null\" INVALID, " + "must be a non-blank string"));
66 public void testXacmlPdpParameterGroup_EmptyName() {
67 final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
69 final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup("", restServerParameters);
70 final GroupValidationResult validationResult = pdpxParameters.validate();
71 assertFalse(validationResult.isValid());
72 assertEquals("", pdpxParameters.getName());
73 assertTrue(validationResult.getResult().contains(
74 "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
78 public void testXacmlPdpParameterGroup_EmptyRestServerParameters() {
79 final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(true);
81 final XacmlPdpParameterGroup pdpxParameters =
82 new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters);
83 final GroupValidationResult validationResult = pdpxParameters.validate();
84 assertFalse(validationResult.isValid());
85 assertTrue(validationResult.getResult()
86 .contains("\"org.onap.policy.pdpx.main.parameters.RestServerParameters\" INVALID, "
87 + "parameter group has status INVALID"));