2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Samsung. All rights reserved.
4 * Modifications Copyright (C) 2019 Nordix Foundation.
5 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.apex.plugins.event.carrier.restserver;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
30 import java.lang.reflect.Field;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.policy.common.parameters.ValidationResult;
35 public class RestServerCarrierTechnologyParametersTest {
37 RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null;
38 ValidationResult result = null;
43 * @throws Exception on test set up errors.
46 public void setUp() throws Exception {
47 restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
51 public void testRestServerCarrierTechnologyParameters() {
52 assertNotNull(restServerCarrierTechnologyParameters);
53 assertFalse(restServerCarrierTechnologyParameters.isStandalone());
57 public void testValidate() {
58 result = restServerCarrierTechnologyParameters.validate();
59 assertNotNull(result);
60 assertTrue(result.isValid());
64 public void testValidateWithNonDefaultValues() throws NoSuchFieldException, SecurityException,
65 IllegalArgumentException, IllegalAccessException {
67 Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone");
68 field.setAccessible(true);
69 field.set(restServerCarrierTechnologyParameters, true);
70 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
71 field.setAccessible(true);
72 field.set(restServerCarrierTechnologyParameters, "");
73 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
74 field.setAccessible(true);
75 field.set(restServerCarrierTechnologyParameters, 1023);
76 result = restServerCarrierTechnologyParameters.validate();
77 assertNotNull(result);
78 assertFalse(result.isValid());
80 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
81 field.setAccessible(true);
82 field.set(restServerCarrierTechnologyParameters, "");
83 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
84 field.setAccessible(true);
85 field.set(restServerCarrierTechnologyParameters, 1023);
86 result = restServerCarrierTechnologyParameters.validate();
87 assertNotNull(result);
88 assertFalse(result.isValid());
92 public void testValidateWithValidValues() throws NoSuchFieldException, SecurityException,
93 IllegalArgumentException, IllegalAccessException {
95 Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone");
96 field.setAccessible(true);
97 field.set(restServerCarrierTechnologyParameters, true);
98 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
99 field.setAccessible(true);
100 field.set(restServerCarrierTechnologyParameters, "localhost");
101 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
102 field.setAccessible(true);
103 field.set(restServerCarrierTechnologyParameters, 6969);
104 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("userName");
105 field.setAccessible(true);
106 field.set(restServerCarrierTechnologyParameters, "username");
107 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("password");
108 field.setAccessible(true);
109 field.set(restServerCarrierTechnologyParameters, "password");
110 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("https");
111 field.setAccessible(true);
112 field.set(restServerCarrierTechnologyParameters, true);
113 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("aaf");
114 field.setAccessible(true);
115 field.set(restServerCarrierTechnologyParameters, true);
116 result = restServerCarrierTechnologyParameters.validate();
117 assertNotNull(result);
118 assertTrue(result.isValid());
122 public void testValidateWithInvalidValues() throws NoSuchFieldException, SecurityException,
123 IllegalArgumentException, IllegalAccessException {
125 Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone");
126 field.setAccessible(true);
127 field.set(restServerCarrierTechnologyParameters, false);
128 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
129 field.setAccessible(true);
130 field.set(restServerCarrierTechnologyParameters, "localhost");
131 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
132 field.setAccessible(true);
133 field.set(restServerCarrierTechnologyParameters, 6969);
134 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("userName");
135 field.setAccessible(true);
136 field.set(restServerCarrierTechnologyParameters, "username");
137 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("password");
138 field.setAccessible(true);
139 field.set(restServerCarrierTechnologyParameters, "password");
140 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("https");
141 field.setAccessible(true);
142 field.set(restServerCarrierTechnologyParameters, true);
143 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("aaf");
144 field.setAccessible(true);
145 field.set(restServerCarrierTechnologyParameters, true);
146 result = restServerCarrierTechnologyParameters.validate();
147 assertNotNull(result);
148 assertFalse(result.isValid());
149 assertThat(result.getResult()).contains("host", "port", "should be specified only in standalone mode");