Adding pdp simulator for testing purposes
[policy/models.git] / models-sim / policy-models-sim-pdp / src / test / java / org / onap / policy / models / sim / pdp / parameters / TestPdpSimulatorParameterGroup.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 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
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
21 package org.onap.policy.models.sim.pdp.parameters;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26
27 import java.util.Map;
28
29 import org.junit.Test;
30 import org.onap.policy.common.parameters.GroupValidationResult;
31
32 /**
33  * Class to perform unit test of {@link PdpSimulatorParameterGroup}.
34  *
35  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
36  */
37 public class TestPdpSimulatorParameterGroup {
38     CommonTestData commonTestData = new CommonTestData();
39
40     @Test
41     public void testPdpSimulatorParameterGroup_Named() {
42         final PdpSimulatorParameterGroup pdpSimulatorParameters = new PdpSimulatorParameterGroup("my-name");
43         assertEquals("my-name", pdpSimulatorParameters.getName());
44     }
45
46     @Test
47     public void testPdpSimulatorParameterGroup() {
48         final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData.toObject(
49                 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME),
50                 PdpSimulatorParameterGroup.class);
51         final PdpStatusParameters pdpStatusParameters = pdpSimulatorParameters.getPdpStatusParameters();
52         final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
53         assertTrue(validationResult.isValid());
54         assertEquals(CommonTestData.PDP_SIMULATOR_GROUP_NAME, pdpSimulatorParameters.getName());
55         assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeIntervalMs());
56         assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
57         assertEquals(CommonTestData.DESCRIPTION, pdpStatusParameters.getDescription());
58         assertEquals(CommonTestData.SUPPORTED_POLICY_TYPES, pdpStatusParameters.getSupportedPolicyTypes());
59     }
60
61     @Test
62     public void testPdpSimulatorParameterGroup_NullName() {
63         final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData
64                 .toObject(commonTestData.getPdpSimulatorParameterGroupMap(null), PdpSimulatorParameterGroup.class);
65         final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
66         assertFalse(validationResult.isValid());
67         assertEquals(null, pdpSimulatorParameters.getName());
68         assertTrue(validationResult.getResult().contains("is null"));
69     }
70
71     @Test
72     public void testPdpSimulatorParameterGroup_EmptyName() {
73         final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData
74                 .toObject(commonTestData.getPdpSimulatorParameterGroupMap(""), PdpSimulatorParameterGroup.class);
75         final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
76         assertFalse(validationResult.isValid());
77         assertEquals("", pdpSimulatorParameters.getName());
78         assertTrue(validationResult.getResult().contains(
79                 "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
80     }
81
82     @Test
83     public void testPdpSimulatorParameterGroup_SetName() {
84         final PdpSimulatorParameterGroup pdpSimulatorParameters = commonTestData.toObject(
85                 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME),
86                 PdpSimulatorParameterGroup.class);
87         pdpSimulatorParameters.setName("PdpSimulatorNewGroup");
88         final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
89         assertTrue(validationResult.isValid());
90         assertEquals("PdpSimulatorNewGroup", pdpSimulatorParameters.getName());
91     }
92
93     @Test
94     public void testPdpSimulatorParameterGroup_EmptyPdpStatusParameters() {
95         final Map<String, Object> map =
96                 commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME);
97         map.put("pdpStatusParameters", commonTestData.getPdpStatusParametersMap(true));
98         final PdpSimulatorParameterGroup pdpSimulatorParameters =
99                 commonTestData.toObject(map, PdpSimulatorParameterGroup.class);
100         final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
101         assertFalse(validationResult.isValid());
102         assertTrue(validationResult.getResult()
103                 .contains("\"org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterGroup\" INVALID, "
104                         + "parameter group has status INVALID"));
105     }
106
107 }