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;
29 import java.io.IOException;
31 import org.junit.Before;
32 import org.junit.ClassRule;
33 import org.junit.Test;
34 import org.junit.rules.TemporaryFolder;
35 import org.onap.policy.common.parameters.GroupValidationResult;
38 * Class to perform unit test of XacmlPdpParameterGroup.
41 public class TestXacmlPdpParameterGroup {
42 CommonTestData commonTestData = new CommonTestData();
43 private static File applicationPath;
46 public static final TemporaryFolder applicationFolder = new TemporaryFolder();
49 public void setupPath() throws IOException {
50 applicationPath = applicationFolder.newFolder();
54 public void testXacmlPdpParameterGroup() throws IOException {
55 final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
56 final XacmlPdpParameterGroup pdpxParameters =
57 new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME,
59 applicationPath.getAbsolutePath());
60 final GroupValidationResult validationResult = pdpxParameters.validate();
61 assertTrue(validationResult.isValid());
62 assertEquals(restServerParameters.getHost(), pdpxParameters.getRestServerParameters().getHost());
63 assertEquals(restServerParameters.getPort(), pdpxParameters.getRestServerParameters().getPort());
64 assertEquals(restServerParameters.getUserName(), pdpxParameters.getRestServerParameters().getUserName());
65 assertEquals(restServerParameters.getPassword(), pdpxParameters.getRestServerParameters().getPassword());
66 assertEquals(CommonTestData.PDPX_GROUP_NAME, pdpxParameters.getName());
67 assertFalse(pdpxParameters.getRestServerParameters().isHttps());
68 assertFalse(pdpxParameters.getRestServerParameters().isAaf());
72 public void testXacmlPdpParameterGroup_NullName() {
73 final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
74 final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(null, restServerParameters,
75 applicationPath.getAbsolutePath());
76 final GroupValidationResult validationResult = pdpxParameters.validate();
77 assertFalse(validationResult.isValid());
78 assertEquals(null, pdpxParameters.getName());
79 assertTrue(validationResult.getResult().contains(
80 "field \"name\" type \"java.lang.String\" value \"null\" INVALID, " + "must be a non-blank string"));
84 public void testXacmlPdpParameterGroup_EmptyName() {
85 final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
87 final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup("", restServerParameters,
88 applicationPath.getAbsolutePath());
89 final GroupValidationResult validationResult = pdpxParameters.validate();
90 assertFalse(validationResult.isValid());
91 assertEquals("", pdpxParameters.getName());
92 assertTrue(validationResult.getResult().contains(
93 "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
97 public void testXacmlPdpParameterGroup_EmptyRestServerParameters() {
98 final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(true);
100 final XacmlPdpParameterGroup pdpxParameters =
101 new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters,
102 applicationPath.getAbsolutePath());
103 final GroupValidationResult validationResult = pdpxParameters.validate();
104 assertFalse(validationResult.isValid());
105 assertTrue(validationResult.getResult()
106 .contains("\"org.onap.policy.pdpx.main.parameters.RestServerParameters\" INVALID, "
107 + "parameter group has status INVALID"));