2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 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
9 * http://www.apache.org/licenses/LICENSE-2.0
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 * ============LICENSE_END=========================================================
19 package org.onap.policy.common.endpoints.parameters;
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertNull;
23 import static org.junit.jupiter.api.Assertions.assertTrue;
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27 import org.onap.policy.common.parameters.BeanValidationResult;
28 import org.onap.policy.common.parameters.ValidationStatus;
30 class RestClientParametersTest {
32 private RestClientParameters params;
36 params = new RestClientParameters();
40 void testValidate_ValidParameters() {
41 params.setHostname("localhost");
42 params.setClientName("testClient");
45 BeanValidationResult result = params.validate();
47 assertEquals(ValidationStatus.CLEAN, result.getStatus(), "Expected the parameters to be valid");
48 assertNull(result.getResult(), "Expected no validation errors");
52 void testValidate_InvalidHostname() {
53 params.setHostname("");
54 params.setClientName("testClient");
57 BeanValidationResult result = params.validate();
59 assertEquals(ValidationStatus.INVALID, result.getStatus(), "Expected the parameters to be invalid");
60 assertTrue(result.getResult().contains("hostname") && result.getResult().contains("is blank"),
61 "Expected invalid hostname error message");
65 void testValidate_InvalidClientName() {
66 params.setHostname("localhost");
67 params.setClientName("");
70 BeanValidationResult result = params.validate();
72 assertEquals(ValidationStatus.INVALID, result.getStatus(), "Expected the parameters to be invalid");
73 assertTrue(result.getResult().contains("clientName") && result.getResult().contains("is blank"),
74 "Expected invalid clientName error message");
78 void testValidate_InvalidPort() {
79 params.setHostname("localhost");
80 params.setClientName("testClient");
83 BeanValidationResult result = params.validate();
85 assertEquals(ValidationStatus.INVALID, result.getStatus(), "Expected the parameters to be invalid");
86 assertTrue(result.getResult().contains("port") && result.getResult().contains("is not valid"),
87 "Expected invalid port error message");
91 void testValidate_MultipleInvalidParameters() {
92 params.setHostname("");
93 params.setClientName("");
96 BeanValidationResult result = params.validate();
98 assertEquals(ValidationStatus.INVALID, result.getStatus(), "Expected the parameters to be invalid");
100 assertTrue(result.getResult().contains("hostname") && result.getResult().contains("is blank"),
101 "Expected invalid hostname error message");
103 assertTrue(result.getResult().contains("clientName") && result.getResult().contains("is blank"),
104 "Expected invalid clientName error message");
106 assertTrue(result.getResult().contains("port") && result.getResult().contains("is not valid"),
107 "Expected invalid port error message");
111 void testGetAndSetName() {
112 String name = "testClient";
113 params.setName(name);
114 assertEquals(name, params.getName(), "Expected the client name to be set and retrieved correctly");