58bf98b3f106e7f5d9e2c38979d0e5427d1c0bd5
[policy/common.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.common.endpoints.parameters;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
29
30 import org.junit.Test;
31 import org.onap.policy.common.parameters.GroupValidationResult;
32 import org.onap.policy.common.utils.coder.Coder;
33 import org.onap.policy.common.utils.coder.StandardCoder;
34
35 /**
36  * Class to perform unit test of {@link RestServerParameters}.
37  *
38  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
39  */
40 public class RestServerParametersTest {
41
42     private static CommonTestData testData = new CommonTestData();
43     private static final Coder coder = new StandardCoder();
44
45     @Test
46     public void test() {
47         final RestServerParameters restServerParameters =
48                 testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
49         final GroupValidationResult validationResult = restServerParameters.validate();
50         assertTrue(validationResult.isValid());
51         assertEquals(CommonTestData.REST_SERVER_HOST, restServerParameters.getHost());
52         assertEquals(CommonTestData.REST_SERVER_PORT, restServerParameters.getPort());
53         assertEquals(CommonTestData.REST_SERVER_USER, restServerParameters.getUserName());
54         assertEquals(CommonTestData.REST_SERVER_PASS, restServerParameters.getPassword());
55         assertEquals(CommonTestData.REST_SERVER_HTTPS, restServerParameters.isHttps());
56         assertEquals(CommonTestData.REST_SERVER_AAF, restServerParameters.isAaf());
57     }
58
59     @Test
60     public void testValidate() {
61         final RestServerParameters restServerParameters =
62             testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
63         final GroupValidationResult result = restServerParameters.validate();
64         assertNull(result.getResult());
65         assertTrue(result.isValid());
66     }
67
68     @Test
69     public void test_valid() throws Exception {
70         String json = testData.getParameterGroupAsString(
71             "src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_valid.json");
72         RestServerParameters restServerParameters = coder.decode(json, RestServerParameters.class);
73         final GroupValidationResult result = restServerParameters.validate();
74         assertNull(result.getResult());
75         assertTrue(result.isValid());
76     }
77
78     @Test
79     public void test_invalid() throws Exception {
80         String json = testData.getParameterGroupAsString(
81             "src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_invalid.json");
82         RestServerParameters restServerParameters = coder.decode(json, RestServerParameters.class);
83         final GroupValidationResult result = restServerParameters.validate();
84         assertFalse(result.isValid());
85         assertTrue(result.getResult().contains("parameter group has status INVALID"));
86     }
87 }