dbe20c96009c0b804a13bf67526828834aa2ed28
[policy/apex-pdp.git] /
1 /*-
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.plugins.event.carrier.restserver;
23
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27
28 import java.lang.reflect.Field;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.policy.common.parameters.GroupValidationResult;
32
33 public class RestServerCarrierTechnologyParametersTest {
34
35     RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null;
36     GroupValidationResult result = null;
37
38     /**
39      * Set up testing.
40      *
41      * @throws Exception on test set up errors.
42      */
43     @Before
44     public void setUp() throws Exception {
45         restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
46     }
47
48     @Test
49     public void testRestServerCarrierTechnologyParameters() {
50         assertNotNull(restServerCarrierTechnologyParameters);
51         assertFalse(restServerCarrierTechnologyParameters.isStandalone());
52     }
53
54     @Test
55     public void testValidate() {
56         result = restServerCarrierTechnologyParameters.validate();
57         assertNotNull(result);
58         assertTrue(result.isValid());
59     }
60
61     @Test
62     public void testValidateWithNonDefaultValues() throws NoSuchFieldException, SecurityException,
63             IllegalArgumentException, IllegalAccessException {
64
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());
77
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());
87     }
88
89 }