2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2024 Nordix Foundation.
4 * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.common.endpoints.parameters;
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.assertFalse;
27 import static org.junit.jupiter.api.Assertions.assertNull;
28 import static org.junit.jupiter.api.Assertions.assertTrue;
30 import org.junit.jupiter.api.Test;
31 import org.onap.policy.common.parameters.ValidationResult;
32 import org.onap.policy.common.utils.coder.Coder;
33 import org.onap.policy.common.utils.coder.StandardCoder;
36 * Class to perform unit test of {@link RestServerParameters}.
38 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
40 class RestServerParametersTest {
42 private static CommonTestData testData = new CommonTestData();
43 private static final Coder coder = new StandardCoder();
47 final RestServerParameters restServerParameters =
48 testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
49 final ValidationResult 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());
61 final RestServerParameters restServerParameters =
62 testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
63 final ValidationResult result = restServerParameters.validate();
64 assertNull(result.getResult());
65 assertTrue(result.isValid());
69 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 ValidationResult result = restServerParameters.validate();
74 assertNull(result.getResult());
75 assertTrue(result.isValid());
79 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 ValidationResult result = restServerParameters.validate();
84 assertFalse(result.isValid());
85 assertThat(result.getResult()).contains("item has status INVALID");