765bb70a9713502c30c95651453ab19d80282fc7
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
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.services.onappf.parameters;
23
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
29
30 import java.util.Map;
31 import org.junit.Test;
32 import org.onap.policy.common.parameters.ValidationResult;
33
34 /**
35  * Class to perform unit test of {@link PdpStatusParameters}.
36  *
37  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
38  */
39 public class TestPdpStatusParameters {
40     private static CommonTestData testData = new CommonTestData();
41
42     @Test
43     public void test() throws Exception {
44         final PdpStatusParameters pdpStatusParameters =
45                 testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
46         final ValidationResult validationResult = pdpStatusParameters.validate();
47         assertTrue(validationResult.isValid());
48         assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeIntervalMs());
49         assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
50         assertEquals(CommonTestData.DESCRIPTION, pdpStatusParameters.getDescription());
51         assertEquals(CommonTestData.SUPPORTED_POLICY_TYPES, pdpStatusParameters.getSupportedPolicyTypes());
52         assertEquals(CommonTestData.PDP_GROUP, pdpStatusParameters.getPdpGroup());
53     }
54
55     @Test
56     public void testValidate() throws Exception {
57         final PdpStatusParameters pdpStatusParameters =
58                 testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
59         final ValidationResult result = pdpStatusParameters.validate();
60         assertNull(result.getResult());
61         assertTrue(result.isValid());
62     }
63
64     @Test
65     public void testPdpStatusParameters_nullPdpGroup() throws Exception {
66         Map<String, Object> pdpStatusParametersMap = testData.getPdpStatusParametersMap(false);
67         pdpStatusParametersMap.remove("pdpGroup");
68         final PdpStatusParameters pdpStatusParameters =
69                 testData.toObject(pdpStatusParametersMap, PdpStatusParameters.class);
70         final ValidationResult validationResult = pdpStatusParameters.validate();
71         assertFalse(validationResult.isValid());
72         assertThat(validationResult.getResult()).contains("\"pdpGroup\" value \"null\" INVALID");
73     }
74
75     @Test
76     public void testPdpStatusParameters_emptyPdpGroup() throws Exception {
77         Map<String, Object> pdpStatusParametersMap = testData.getPdpStatusParametersMap(false);
78         pdpStatusParametersMap.put("pdpGroup", "");
79         final PdpStatusParameters pdpStatusParameters =
80                 testData.toObject(pdpStatusParametersMap, PdpStatusParameters.class);
81         final ValidationResult validationResult = pdpStatusParameters.validate();
82         assertFalse(validationResult.isValid());
83         assertThat(validationResult.getResult()).contains("\"pdpGroup\" value \"\" INVALID");
84     }
85 }