c3f8bedb0f7d0f1f1baba94d67d1d20e0869fa48
[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                 @SuppressWarnings("unused")
44                 PolicyUtils policyUtils = new PolicyUtils();
45                 StdPDPNotification notification = new StdPDPNotification();
46                 notification.setNotificationType(NotificationType.BOTH);
47                 Collection<StdRemovedPolicy> removedPolicies = new ArrayList<StdRemovedPolicy>();
48                 Collection<StdLoadedPolicy> loadedPolicies = new ArrayList<StdLoadedPolicy>();
49                 StdRemovedPolicy removedPolicy = new StdRemovedPolicy();
50                 StdLoadedPolicy updatedPolicy = new StdLoadedPolicy();
51                 removedPolicy.setPolicyName("Test");
52                 removedPolicy.setVersionNo("1");
53                 removedPolicies.add(removedPolicy);
54                 updatedPolicy.setPolicyName("Testing");
55                 updatedPolicy.setVersionNo("1");
56                 updatedPolicy.setUpdateType(UpdateType.NEW);
57                 Map<String, String> matches = new HashMap<String, String>();
58                 matches.put("key", "value");
59                 updatedPolicy.setMatches(matches);
60                 loadedPolicies.add(updatedPolicy);
61                 notification.setRemovedPolicies(removedPolicies);
62                 notification.setLoadedPolicies(loadedPolicies);
63                 
64                 String json = PolicyUtils.objectToJsonString(notification);
65                 PDPNotification getBackObject = PolicyUtils.jsonStringToObject(json, StdPDPNotification.class);
66                 assertEquals(0,getBackObject.getNotificationType().compareTo(notification.getNotificationType()));
67                 
68         }
69 }