2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.utils.test;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.List;
31 import org.junit.Test;
32 import org.onap.policy.api.NotificationType;
33 import org.onap.policy.api.UpdateType;
34 import org.onap.policy.std.NotificationStore;
35 import org.onap.policy.std.StdLoadedPolicy;
36 import org.onap.policy.std.StdPDPNotification;
37 import org.onap.policy.std.StdRemovedPolicy;
39 public class NotificationStoreTest {
42 public void notificationTest(){
43 StdPDPNotification notification = new StdPDPNotification();
44 notification.setNotificationType(NotificationType.UPDATE);
45 List<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
46 StdLoadedPolicy loadedPolicy = new StdLoadedPolicy();
47 loadedPolicy.setPolicyName("com.testing");
48 loadedPolicy.setUpdateType(UpdateType.NEW);
49 loadedPolicy.setVersionNo("1");
50 Map<String, String> matches = new HashMap<>();
51 matches.put("test", "test");
52 loadedPolicy.setMatches(matches);
53 loadedPolicies.add(loadedPolicy);
54 notification.setLoadedPolicies(loadedPolicies);
55 NotificationStore.recordNotification(notification);
56 assertEquals(notification, NotificationStore.getNotificationRecord());
57 // Add new Notifications.
58 notification = new StdPDPNotification();
59 notification.setNotificationType(NotificationType.BOTH);
60 loadedPolicies = new ArrayList<>();
61 loadedPolicy = new StdLoadedPolicy();
62 loadedPolicy.setPolicyName("com.testing");
63 loadedPolicy.setUpdateType(UpdateType.UPDATE);
64 loadedPolicy.setVersionNo("2");
65 matches = new HashMap<>();
66 matches.put("test", "test");
67 loadedPolicy.setMatches(matches);
68 loadedPolicies.add(loadedPolicy);
69 notification.setLoadedPolicies(loadedPolicies);
70 List<StdRemovedPolicy> removedPolicies = new ArrayList<>();
71 StdRemovedPolicy removedPolicy = new StdRemovedPolicy();
72 removedPolicy.setPolicyName("com.testing");
73 removedPolicy.setVersionNo("1");
74 notification.setRemovedPolicies(removedPolicies);
75 NotificationStore.recordNotification(notification);
76 assertNotNull(NotificationStore.getNotificationRecord());
77 // Add new Notifications.
78 notification = new StdPDPNotification();
79 notification.setNotificationType(NotificationType.BOTH);
80 loadedPolicies = new ArrayList<>();
81 loadedPolicy = new StdLoadedPolicy();
82 loadedPolicy.setPolicyName("com.test.xml");
83 loadedPolicy.setUpdateType(UpdateType.NEW);
84 loadedPolicy.setVersionNo("2");
85 matches = new HashMap<>();
86 matches.put("test", "test");
87 loadedPolicy.setMatches(matches);
88 loadedPolicies.add(loadedPolicy);
89 notification.setLoadedPolicies(loadedPolicies);
90 removedPolicies = new ArrayList<>();
91 removedPolicy = new StdRemovedPolicy();
92 removedPolicy.setPolicyName("com.testing.xml");
93 removedPolicy.setVersionNo("2");
94 notification.setRemovedPolicies(removedPolicies);
95 NotificationStore.recordNotification(notification);
96 assertNotNull(NotificationStore.getNotificationRecord());