2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Samsung. All rights reserved.
4 * Modifications Copyright (C) 2019 Nordix Foundation.
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.apex.plugins.event.carrier.restserver;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
28 import java.lang.reflect.Field;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.policy.common.parameters.GroupValidationResult;
33 public class RestServerCarrierTechnologyParametersTest {
35 RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null;
36 GroupValidationResult result = null;
41 * @throws Exception on test set up errors.
44 public void setUp() throws Exception {
45 restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
49 public void testRestServerCarrierTechnologyParameters() {
50 assertNotNull(restServerCarrierTechnologyParameters);
51 assertFalse(restServerCarrierTechnologyParameters.isStandalone());
55 public void testValidate() {
56 result = restServerCarrierTechnologyParameters.validate();
57 assertNotNull(result);
58 assertTrue(result.isValid());
62 public void testValidateWithNonDefaultValues() throws NoSuchFieldException, SecurityException,
63 IllegalArgumentException, IllegalAccessException {
65 Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone");
66 field.setAccessible(true);
67 field.set(restServerCarrierTechnologyParameters, true);
68 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
69 field.setAccessible(true);
70 field.set(restServerCarrierTechnologyParameters, "");
71 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
72 field.setAccessible(true);
73 field.set(restServerCarrierTechnologyParameters, 1023);
74 result = restServerCarrierTechnologyParameters.validate();
75 assertNotNull(result);
76 assertFalse(result.isValid());
78 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
79 field.setAccessible(true);
80 field.set(restServerCarrierTechnologyParameters, "");
81 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
82 field.setAccessible(true);
83 field.set(restServerCarrierTechnologyParameters, 1023);
84 result = restServerCarrierTechnologyParameters.validate();
85 assertNotNull(result);
86 assertFalse(result.isValid());
90 public void testValidateWithValidValues() throws NoSuchFieldException, SecurityException,
91 IllegalArgumentException, IllegalAccessException {
93 Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone");
94 field.setAccessible(true);
95 field.set(restServerCarrierTechnologyParameters, true);
96 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
97 field.setAccessible(true);
98 field.set(restServerCarrierTechnologyParameters, "localhost");
99 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
100 field.setAccessible(true);
101 field.set(restServerCarrierTechnologyParameters, 6969);
102 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("userName");
103 field.setAccessible(true);
104 field.set(restServerCarrierTechnologyParameters, "username");
105 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("password");
106 field.setAccessible(true);
107 field.set(restServerCarrierTechnologyParameters, "password");
108 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("https");
109 field.setAccessible(true);
110 field.set(restServerCarrierTechnologyParameters, true);
111 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("aaf");
112 field.setAccessible(true);
113 field.set(restServerCarrierTechnologyParameters, true);
114 result = restServerCarrierTechnologyParameters.validate();
115 assertNotNull(result);
116 assertTrue(result.isValid());
120 public void testValidateWithInvalidValues() throws NoSuchFieldException, SecurityException,
121 IllegalArgumentException, IllegalAccessException {
123 Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone");
124 field.setAccessible(true);
125 field.set(restServerCarrierTechnologyParameters, false);
126 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
127 field.setAccessible(true);
128 field.set(restServerCarrierTechnologyParameters, "localhost");
129 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
130 field.setAccessible(true);
131 field.set(restServerCarrierTechnologyParameters, 6969);
132 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("userName");
133 field.setAccessible(true);
134 field.set(restServerCarrierTechnologyParameters, "username");
135 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("password");
136 field.setAccessible(true);
137 field.set(restServerCarrierTechnologyParameters, "password");
138 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("https");
139 field.setAccessible(true);
140 field.set(restServerCarrierTechnologyParameters, true);
141 field = RestServerCarrierTechnologyParameters.class.getDeclaredField("aaf");
142 field.setAccessible(true);
143 field.set(restServerCarrierTechnologyParameters, true);
144 result = restServerCarrierTechnologyParameters.validate();
145 assertNotNull(result);
146 assertFalse(result.isValid());
147 assertTrue(result.getResult().contains("host is specified only in standalone mode"));
148 assertTrue(result.getResult().contains("port is specified only in standalone mode"));