Fixed the Policy API issues and Bugfixes
[policy/engine.git] / PolicyEngineUtils / src / test / java / org / openecomp / policy / test / PolicyUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * PolicyEngineUtils
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.policy.test;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.HashMap;
28 import java.util.Map;
29
30 import org.junit.Test;
31 import org.openecomp.policy.api.NotificationType;
32 import org.openecomp.policy.api.PDPNotification;
33 import org.openecomp.policy.api.UpdateType;
34 import org.openecomp.policy.std.StdLoadedPolicy;
35 import org.openecomp.policy.std.StdPDPNotification;
36 import org.openecomp.policy.std.StdRemovedPolicy;
37 import org.openecomp.policy.utils.PolicyUtils;
38
39 public class PolicyUtilsTest {
40         
41         @Test
42         public void testJsonConversions() throws Exception{
43                 StdPDPNotification notification = new StdPDPNotification();
44                 notification.setNotificationType(NotificationType.BOTH);
45                 Collection<StdRemovedPolicy> removedPolicies = new ArrayList<>();
46                 Collection<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
47                 StdRemovedPolicy removedPolicy = new StdRemovedPolicy();
48                 StdLoadedPolicy updatedPolicy = new StdLoadedPolicy();
49                 removedPolicy.setPolicyName("Test");
50                 removedPolicy.setVersionNo("1");
51                 removedPolicies.add(removedPolicy);
52                 updatedPolicy.setPolicyName("Testing");
53                 updatedPolicy.setVersionNo("1");
54                 updatedPolicy.setUpdateType(UpdateType.NEW);
55                 Map<String, String> matches = new HashMap<>();
56                 matches.put("key", "value");
57                 updatedPolicy.setMatches(matches);
58                 loadedPolicies.add(updatedPolicy);
59                 notification.setRemovedPolicies(removedPolicies);
60                 notification.setLoadedPolicies(loadedPolicies);
61                 
62                 String json = PolicyUtils.objectToJsonString(notification);
63                 PDPNotification getBackObject = PolicyUtils.jsonStringToObject(json, StdPDPNotification.class);
64                 assertEquals(0,getBackObject.getNotificationType().compareTo(notification.getNotificationType()));
65                 
66         }
67 }