ca2b3c4c2e2e1de535a26051b71401f4d2b51958
[policy/common.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
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.common.endpoints.parameters;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
27
28 import org.junit.Test;
29 import org.onap.policy.common.parameters.GroupValidationResult;
30 import org.onap.policy.common.utils.coder.Coder;
31 import org.onap.policy.common.utils.coder.StandardCoder;
32
33 /**
34  * Class to perform unit test of {@link RestServerParameters}.
35  *
36  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
37  */
38 public class RestServerParametersTest {
39
40     private static CommonTestData testData = new CommonTestData();
41     private static final Coder coder = new StandardCoder();
42
43     @Test
44     public void test() throws Exception {
45         final RestServerParameters restServerParameters =
46                 testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
47         final GroupValidationResult validationResult = restServerParameters.validate();
48         assertTrue(validationResult.isValid());
49         assertEquals(CommonTestData.REST_SERVER_HOST, restServerParameters.getHost());
50         assertEquals(CommonTestData.REST_SERVER_PORT, restServerParameters.getPort());
51         assertEquals(CommonTestData.REST_SERVER_USER, restServerParameters.getUserName());
52         assertEquals(CommonTestData.REST_SERVER_PASSWORD, restServerParameters.getPassword());
53         assertEquals(CommonTestData.REST_SERVER_HTTPS, restServerParameters.isHttps());
54         assertEquals(CommonTestData.REST_SERVER_AAF, restServerParameters.isAaf());
55     }
56
57     @Test
58     public void testValidate() throws Exception {
59         final RestServerParameters restServerParameters =
60             testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
61         final GroupValidationResult result = restServerParameters.validate();
62         assertNull(result.getResult());
63         assertTrue(result.isValid());
64     }
65
66     @Test
67     public void test_valid() throws Exception {
68         String json = testData.getParameterGroupAsString(
69             "src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_valid.json");
70         RestServerParameters restServerParameters = coder.decode(json, RestServerParameters.class);
71         final GroupValidationResult result = restServerParameters.validate();
72         assertNull(result.getResult());
73         assertTrue(result.isValid());
74     }
75
76     @Test
77     public void test_invalid() throws Exception {
78         String json = testData.getParameterGroupAsString(
79             "src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_invalid.json");
80         RestServerParameters restServerParameters = coder.decode(json, RestServerParameters.class);
81         final GroupValidationResult result = restServerParameters.validate();
82         assertFalse(result.isValid());
83         assertTrue(result.getResult().contains("parameter group has status INVALID"));
84     }
85 }