Clean up checkstyle declaration
[policy/api.git] / main / src / test / java / org / onap / policy / api / main / parameters / TestApiParameterGroup.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Samsung Electronics Co., Ltd. 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 package org.onap.policy.api.main.parameters;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26
27 import org.junit.Test;
28 import org.onap.policy.common.parameters.GroupValidationResult;
29
30 /**
31  * Class to perform unit test of ApiParameterGroup.
32  *
33  */
34 public class TestApiParameterGroup {
35     CommonTestData commonTestData = new CommonTestData();
36
37     @Test
38     public void testApiParameterGroup() {
39         final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
40         final ApiParameterGroup apiParameters = new ApiParameterGroup(
41                 CommonTestData.API_GROUP_NAME, restServerParameters);
42         final GroupValidationResult validationResult = apiParameters.validate();
43         assertTrue(validationResult.isValid());
44         assertEquals(restServerParameters.getHost(), apiParameters.getRestServerParameters().getHost());
45         assertEquals(restServerParameters.getPort(), apiParameters.getRestServerParameters().getPort());
46         assertEquals(restServerParameters.getUserName(),
47                 apiParameters.getRestServerParameters().getUserName());
48         assertEquals(restServerParameters.getPassword(),
49                 apiParameters.getRestServerParameters().getPassword());
50         assertEquals(CommonTestData.API_GROUP_NAME, apiParameters.getName());
51     }
52
53     @Test
54     public void testApiParameterGroup_NullName() {
55         final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
56         final ApiParameterGroup apiParameters = new ApiParameterGroup(null,
57                         restServerParameters);
58         final GroupValidationResult validationResult = apiParameters.validate();
59         assertFalse(validationResult.isValid());
60         assertEquals(null, apiParameters.getName());
61         assertTrue(validationResult.getResult()
62                         .contains("field \"name\" type \"java.lang.String\" value \"null\" INVALID, "
63                                         + "must be a non-blank string"));
64     }
65
66     @Test
67     public void testApiParameterGroup_EmptyName() {
68         final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
69
70         final ApiParameterGroup apiParameters = new ApiParameterGroup("",
71                         restServerParameters);
72         final GroupValidationResult validationResult = apiParameters.validate();
73         assertFalse(validationResult.isValid());
74         assertEquals("", apiParameters.getName());
75         assertTrue(validationResult.getResult().contains("field \"name\" type \"java.lang.String\" value \"\" INVALID, "
76                         + "must be a non-blank string"));
77     }
78
79     @Test
80     public void testApiParameterGroup_EmptyRestServerParameters() {
81         final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(true);
82
83         final ApiParameterGroup apiParameters = new ApiParameterGroup(
84                         CommonTestData.API_GROUP_NAME, restServerParameters);
85         final GroupValidationResult validationResult = apiParameters.validate();
86         assertFalse(validationResult.isValid());
87         assertTrue(validationResult.getResult()
88                         .contains("\"org.onap.policy.api.main.parameters.RestServerParameters\" INVALID, "
89                                         + "parameter group has status INVALID"));
90     }
91 }