Adding unit tests for Policy API.
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / parameters / RestServerParameters.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  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * SPDX-License-Identifier: Apache-2.0
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.policy.api.main.parameters;
25
26 import org.onap.policy.common.parameters.GroupValidationResult;
27 import org.onap.policy.common.parameters.ParameterGroup;
28 import org.onap.policy.common.parameters.ValidationStatus;
29 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
30
31 /**
32  * Class to hold all parameters needed for api rest server.
33  *
34  */
35 public class RestServerParameters implements ParameterGroup {
36     private String name;
37     private String host;
38     private int port;
39     private String userName;
40     private String password;
41     private boolean https; 
42     private boolean aaf;
43     
44     /**
45      * Constructor for instantiating RestServerParameters.
46      *
47      * @param host the host name
48      * @param port the port
49      * @param userName the user name
50      * @param password the password
51      */
52     public RestServerParameters(final String host, final int port, final String userName, final String password) {
53         super();
54         this.host = host;
55         this.port = port;
56         this.userName = userName;
57         this.password = password;
58         this.https = false;
59         this.aaf = false;
60     }
61     
62     /**
63      * Constructor for instantiating RestServerParameters.
64      *
65      * @param host the host name
66      * @param port the port
67      * @param userName the user name
68      * @param password the password
69      * @param https the https
70      * @param aaf the aaf
71      */
72     public RestServerParameters(final String host, final int port, final String userName, final String password, 
73                                 final boolean https, final boolean aaf) {
74         super();
75         this.host = host;
76         this.port = port;
77         this.userName = userName;
78         this.password = password;
79         this.https = https;
80         this.aaf = aaf;
81     }
82
83     /**
84      * Return the name of this RestServerParameters instance.
85      *
86      * @return name the name of this RestServerParameters
87      */
88     @Override
89     public String getName() {
90         return name;
91     }
92
93     /**
94      * Return the host of this RestServerParameters instance.
95      *
96      * @return the host
97      */
98     public String getHost() {
99         return host;
100     }
101
102     /**
103      * Return the port of this RestServerParameters instance.
104      *
105      * @return the port
106      */
107     public int getPort() {
108         return port;
109     }
110
111     /**
112      * Return the user name of this RestServerParameters instance.
113      *
114      * @return the userName
115      */
116     public String getUserName() {
117         return userName;
118     }
119
120     /**
121      * Return the password of this RestServerParameters instance.
122      *
123      * @return the password
124      */
125     public String getPassword() {
126         return password;
127     }
128     
129     /**
130      * Return the https flag of this RestServerParameters instance.
131      * @return the https
132      */
133     public boolean isHttps() {
134         return https;
135     }
136     
137     /**
138      * Return the aaf flag of this RestServerParameters instance.
139      * @return the aaf
140      */
141     public boolean isAaf() {
142         return aaf;
143     } 
144
145     /**
146      * Set the name of this RestServerParameters instance.
147      *
148      * @param name the name to set
149      */
150     public void setName(final String name) {
151         this.name = name;
152     }
153
154     /**
155      * Validate the rest server parameters.
156      *
157      * @return the result of the validation
158      */
159     @Override
160     public GroupValidationResult validate() {
161         final GroupValidationResult validationResult = new GroupValidationResult(this);
162         if (!ParameterValidationUtils.validateStringParameter(host)) {
163             validationResult.setResult("host", ValidationStatus.INVALID,
164                     "must be a non-blank string containing hostname/ipaddress of the api rest server");
165         }
166         if (!ParameterValidationUtils.validateStringParameter(userName)) {
167             validationResult.setResult("userName", ValidationStatus.INVALID,
168                     "must be a non-blank string containing userName for api rest server credentials");
169         }
170         if (!ParameterValidationUtils.validateStringParameter(password)) {
171             validationResult.setResult("password", ValidationStatus.INVALID,
172                     "must be a non-blank string containing password for api rest server credentials");
173         }
174         if (!ParameterValidationUtils.validateIntParameter(port)) {
175             validationResult.setResult("port", ValidationStatus.INVALID,
176                     "must be a positive integer containing port of the api rest server");
177         }
178         return validationResult;
179     }
180 }