19800538681e3436e5f0c6d7f1b40061f6000a5f
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Samsung. All rights reserved.
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.policy.apex.plugins.event.carrier.restserver;
21
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25 import java.lang.reflect.Field;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.policy.common.parameters.GroupValidationResult;
29
30 public class RestServerCarrierTechnologyParametersTest {
31
32     RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null;
33     GroupValidationResult result = null;
34
35     /**
36      * Set up testing.
37      *
38      * @throws Exception on test set up errors.
39      */
40     @Before
41     public void setUp() throws Exception {
42         restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
43     }
44
45     @Test
46     public void testRestServerCarrierTechnologyParameters() {
47         assertNotNull(restServerCarrierTechnologyParameters);
48         assertFalse(restServerCarrierTechnologyParameters.isStandalone());
49     }
50
51     @Test
52     public void testValidate() {
53         result = restServerCarrierTechnologyParameters.validate();
54         assertNotNull(result);
55         assertTrue(result.isValid());
56     }
57
58     @Test
59     public void testValidateWithNonDefaultValues() throws NoSuchFieldException, SecurityException,
60             IllegalArgumentException, IllegalAccessException {
61
62         Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone");
63         field.setAccessible(true);
64         field.set(restServerCarrierTechnologyParameters, true);
65         field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
66         field.setAccessible(true);
67         field.set(restServerCarrierTechnologyParameters, "");
68         field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
69         field.setAccessible(true);
70         field.set(restServerCarrierTechnologyParameters, 1023);
71         result = restServerCarrierTechnologyParameters.validate();
72         assertNotNull(result);
73         assertFalse(result.isValid());
74
75         field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
76         field.setAccessible(true);
77         field.set(restServerCarrierTechnologyParameters, "");
78         field = RestServerCarrierTechnologyParameters.class.getDeclaredField("port");
79         field.setAccessible(true);
80         field.set(restServerCarrierTechnologyParameters, 1023);
81         result = restServerCarrierTechnologyParameters.validate();
82         assertNotNull(result);
83         assertFalse(result.isValid());
84     }
85
86 }