2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4 * Modifications Copyright (C) 2019 Nordix Foundation.
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=========================================================
23 package org.onap.policy.pdpx.main.parameters;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertTrue;
30 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.endpoints.parameters.RestServerParameters;
36 import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
37 import org.onap.policy.common.parameters.GroupValidationResult;
40 * Class to perform unit test of XacmlPdpParameterGroup.
43 public class TestXacmlPdpParameterGroup {
44 CommonTestData commonTestData = new CommonTestData();
45 private static File applicationPath;
46 private static CommonTestData testData = new CommonTestData();
49 public static final TemporaryFolder applicationFolder = new TemporaryFolder();
52 public void setupPath() throws IOException {
53 applicationPath = applicationFolder.newFolder();
57 public void testXacmlPdpParameterGroup() throws IOException {
58 final RestServerParameters restServerParameters =
59 testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
60 final TopicParameterGroup topicParameterGroup =
61 testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
62 final XacmlPdpParameterGroup pdpxParameters =
63 new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME,
64 restServerParameters, topicParameterGroup, applicationPath.getAbsolutePath());
65 final GroupValidationResult validationResult = pdpxParameters.validate();
66 assertTrue(validationResult.isValid());
67 assertEquals(restServerParameters.getHost(), pdpxParameters.getRestServerParameters().getHost());
68 assertEquals(restServerParameters.getPort(), pdpxParameters.getRestServerParameters().getPort());
69 assertEquals(restServerParameters.getUserName(), pdpxParameters.getRestServerParameters().getUserName());
70 assertEquals(restServerParameters.getPassword(), pdpxParameters.getRestServerParameters().getPassword());
71 assertEquals(CommonTestData.PDPX_GROUP_NAME, pdpxParameters.getName());
72 assertFalse(pdpxParameters.getRestServerParameters().isHttps());
73 assertFalse(pdpxParameters.getRestServerParameters().isAaf());
77 public void testXacmlPdpParameterGroup_NullName() {
78 final RestServerParameters restServerParameters =
79 testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
80 final TopicParameterGroup topicParameterGroup =
81 testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
82 final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(null, restServerParameters,
83 topicParameterGroup, applicationPath.getAbsolutePath());
84 final GroupValidationResult validationResult = pdpxParameters.validate();
85 assertFalse(validationResult.isValid());
86 assertEquals(null, pdpxParameters.getName());
87 assertTrue(validationResult.getResult().contains(
88 "field \"name\" type \"java.lang.String\" value \"null\" INVALID, " + "must be a non-blank string"));
92 public void testXacmlPdpParameterGroup_EmptyName() {
93 final RestServerParameters restServerParameters =
94 testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
95 final TopicParameterGroup topicParameterGroup =
96 testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
97 final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup("", restServerParameters,
98 topicParameterGroup, applicationPath.getAbsolutePath());
99 final GroupValidationResult validationResult = pdpxParameters.validate();
100 assertFalse(validationResult.isValid());
101 assertEquals("", pdpxParameters.getName());
102 assertTrue(validationResult.getResult().contains(
103 "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
107 public void testXacmlPdpParameterGroup_EmptyRestServerParameters() {
108 final RestServerParameters restServerParameters =
109 testData.toObject(testData.getRestServerParametersMap(true), RestServerParameters.class);
110 final TopicParameterGroup topicParameterGroup =
111 testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
112 final XacmlPdpParameterGroup pdpxParameters =
113 new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters,
114 topicParameterGroup, applicationPath.getAbsolutePath());
115 final GroupValidationResult validationResult = pdpxParameters.validate();
116 assertFalse(validationResult.isValid());
117 assertTrue(validationResult.getResult()
118 .contains("\"org.onap.policy.common.endpoints.parameters.RestServerParameters\" INVALID, "
119 + "parameter group has status INVALID"));
123 public void testXacmlPdpParameterGroup_EmptyTopicParameterGroup() {
124 final RestServerParameters restServerParameters =
125 testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
126 final TopicParameterGroup topicParameterGroup =
127 testData.toObject(testData.getTopicParametersMap(true), TopicParameterGroup.class);
128 final XacmlPdpParameterGroup pdpxParameters =
129 new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters,
130 topicParameterGroup, applicationPath.getAbsolutePath());
131 final GroupValidationResult validationResult = pdpxParameters.validate();
132 assertFalse(validationResult.isValid());
133 assertTrue(validationResult.getResult()
134 .contains("\"org.onap.policy.common.endpoints.parameters.TopicParameterGroup\" INVALID, "
135 + "parameter group has status INVALID"));