2bf6fd8194e0a2a3843a2800655f0296af880ef1
[policy/xacml-pdp.git] / main / src / test / java / org / onap / policy / pdpx / main / parameters / TestXacmlPdpParameterGroup.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21
22 package org.onap.policy.pdpx.main.parameters;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
27
28 import java.io.File;
29 import java.io.IOException;
30
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;
36
37 /**
38  * Class to perform unit test of XacmlPdpParameterGroup.
39  *
40  */
41 public class TestXacmlPdpParameterGroup {
42     CommonTestData commonTestData = new CommonTestData();
43     private static File applicationPath;
44
45     @ClassRule
46     public static final TemporaryFolder applicationFolder = new TemporaryFolder();
47
48     @Before
49     public void setupPath() throws IOException {
50         applicationPath = applicationFolder.newFolder();
51     }
52
53     @Test
54     public void testXacmlPdpParameterGroup() throws IOException {
55         final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
56         final XacmlPdpParameterGroup pdpxParameters =
57                 new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME,
58                         restServerParameters,
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());
69     }
70
71     @Test
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"));
81     }
82
83     @Test
84     public void testXacmlPdpParameterGroup_EmptyName() {
85         final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
86
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"));
94     }
95
96     @Test
97     public void testXacmlPdpParameterGroup_EmptyRestServerParameters() {
98         final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(true);
99
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"));
108     }
109 }