added test cases to TestApiParameterGroup.java
[policy/api.git] / main / src / test / java / org / onap / policy / api / main / parameters / TestApiParameterGroup.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy API 
4  * ================================================================================ 
5  * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
6  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
7  * Modifications Copyright (C) 2019 IBM.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0 
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * SPDX-License-Identifier: Apache-2.0
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.policy.api.main.parameters;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertTrue;
30
31 import org.junit.Test;
32 import org.onap.policy.common.parameters.GroupValidationResult;
33
34 /**
35  * Class to perform unit test of ApiParameterGroup.
36  *
37  */
38 public class TestApiParameterGroup {
39     CommonTestData commonTestData = new CommonTestData();
40
41     @Test
42     public void testApiParameterGroup() {
43         final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
44         final ApiParameterGroup apiParameters = new ApiParameterGroup(CommonTestData.API_GROUP_NAME,
45                 restServerParameters);
46         final GroupValidationResult validationResult = apiParameters.validate();
47         assertTrue(validationResult.isValid());
48         assertEquals(restServerParameters.getHost(), apiParameters.getRestServerParameters().getHost());
49         assertEquals(restServerParameters.getPort(), apiParameters.getRestServerParameters().getPort());
50         assertEquals(restServerParameters.getUserName(), apiParameters.getRestServerParameters().getUserName());
51         assertEquals(restServerParameters.getPassword(), apiParameters.getRestServerParameters().getPassword());
52         assertEquals(restServerParameters.isHttps(), apiParameters.getRestServerParameters().isHttps());
53         assertEquals(restServerParameters.isAaf(), apiParameters.getRestServerParameters().isAaf());
54         assertEquals(CommonTestData.API_GROUP_NAME, apiParameters.getName());
55     }
56
57     @Test
58     public void testApiParameterGroup_NullName() {
59         final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
60         final ApiParameterGroup apiParameters = new ApiParameterGroup(null, restServerParameters);
61         final GroupValidationResult validationResult = apiParameters.validate();
62         assertFalse(validationResult.isValid());
63         assertEquals(null, apiParameters.getName());
64         assertTrue(validationResult.getResult().contains(
65                 "field \"name\" type \"java.lang.String\" value \"null\" INVALID, " + "must be a non-blank string"));
66     }
67
68     @Test
69     public void testApiParameterGroup_EmptyName() {
70         final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
71
72         final ApiParameterGroup apiParameters = new ApiParameterGroup("", restServerParameters);
73         final GroupValidationResult validationResult = apiParameters.validate();
74         assertFalse(validationResult.isValid());
75         assertEquals("", apiParameters.getName());
76         assertTrue(validationResult.getResult().contains(
77                 "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
78     }
79
80     @Test
81     public void testApiParameterGroup_EmptyRestServerParameters() {
82         final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(true);
83
84         final ApiParameterGroup apiParameters = new ApiParameterGroup(CommonTestData.API_GROUP_NAME,
85                 restServerParameters);
86         final GroupValidationResult validationResult = apiParameters.validate();
87         assertFalse(validationResult.isValid());
88         assertTrue(validationResult.getResult()
89                 .contains("\"org.onap.policy.api.main.parameters.RestServerParameters\" INVALID, "
90                         + "parameter group has status INVALID"));
91     }
92
93     @Test
94     public void testName() {
95         final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
96
97         final ApiParameterGroup apiParameters = new ApiParameterGroup("", restServerParameters);
98         apiParameters.setName("name");
99         assertEquals("name", apiParameters.getName());
100     }
101
102     @Test
103     public void testVaildateForNullRestServiceParameters() {
104         final ApiParameterGroup apiParameters = new ApiParameterGroup(CommonTestData.API_GROUP_NAME, null);
105         final GroupValidationResult validationResult = apiParameters.validate();
106         assertTrue(validationResult.getResult().contains("parameter group has status INVALID"));
107     }
108 }