aboutsummaryrefslogtreecommitdiffstats
path: root/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/NotificationStoreTest.java
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-10-17 10:26:58 -0400
committerPamela Dragosh <pdragosh@research.att.com>2019-10-17 17:12:11 -0400
commite9b8aa0223e6f042c0533176ae8222fb061852de (patch)
treece5ac86f12a3430a688af34e5838c8be79504d12 /PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/NotificationStoreTest.java
parent3c95fa7249cccc3d0eb3c9e89ba708a3167d41ba (diff)
Re-format source code
No longer need the onap-java-formatter.xml in the repo - just use command line to set path to it as this process is done manually anyway. Fixed missing javadoc, curly braces and variables names. One minor fix to remove redundant jump and then unnecessary lambda expression. Distance from usage - moved code. Fixed compilation error in PeCryptoUtils due to policy/common change. Fixed some test sources with consecutive capital letter in names. Updated licenses. Added some trivial code coverage. Issue-ID: POLICY-2145 Change-Id: I6c36650554e4fe31a3e71538d898535bc77e7e74 Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/NotificationStoreTest.java')
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/NotificationStoreTest.java74
1 files changed, 47 insertions, 27 deletions
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/NotificationStoreTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/NotificationStoreTest.java
index 774bf8a7e..a7e3a9478 100644
--- a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/NotificationStoreTest.java
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/NotificationStoreTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineUtils
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -38,16 +38,16 @@ import org.onap.policy.std.StdRemovedPolicy;
import org.onap.policy.utils.PolicyUtils;
public class NotificationStoreTest {
-
+
@Test
- public void notificationTest() throws IOException{
- // Notification Delta test first.
+ public void notificationTest() throws IOException {
+ // Notification Delta test first.
NotificationStore.recordNotification(new StdPDPNotification());
- assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}", PolicyUtils.objectToJsonString(NotificationStore.getDeltaNotification(new StdPDPNotification())));
- // Initialize test
+ assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}",
+ PolicyUtils.objectToJsonString(NotificationStore.getDeltaNotification(new StdPDPNotification())));
+ // Initialize test
StdPDPNotification notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.BOTH);
- List<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
StdLoadedPolicy loadedPolicy = new StdLoadedPolicy();
loadedPolicy.setPolicyName("com.testing");
loadedPolicy.setUpdateType(UpdateType.UPDATE);
@@ -55,6 +55,7 @@ public class NotificationStoreTest {
Map<String, String> matches = new HashMap<>();
matches.put("test", "test");
loadedPolicy.setMatches(matches);
+ List<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
loadedPolicies.add(loadedPolicy);
notification.setLoadedPolicies(loadedPolicies);
List<StdRemovedPolicy> removedPolicies = new ArrayList<>();
@@ -64,8 +65,10 @@ public class NotificationStoreTest {
removedPolicies.add(removedPolicy);
notification.setRemovedPolicies(removedPolicies);
NotificationStore.recordNotification(notification);
- assertEquals("{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"}],\"loadedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"2\",\"matches\":{\"test\":\"test\"},\"updateType\":\"UPDATE\"}],\"notificationType\":\"BOTH\"}", PolicyUtils.objectToJsonString(NotificationStore.getNotificationRecord()));
- // Add new Notifications.
+ assertEquals(
+ "{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"}],\"loadedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"2\",\"matches\":{\"test\":\"test\"},\"updateType\":\"UPDATE\"}],\"notificationType\":\"BOTH\"}",
+ PolicyUtils.objectToJsonString(NotificationStore.getNotificationRecord()));
+ // Add new Notifications.
notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.BOTH);
loadedPolicies = new ArrayList<>();
@@ -85,9 +88,12 @@ public class NotificationStoreTest {
removedPolicies.add(removedPolicy);
notification.setRemovedPolicies(removedPolicies);
NotificationStore.recordNotification(notification);
- StdPDPNotification check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject("{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}", StdPDPNotification.class));
- assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}", PolicyUtils.objectToJsonString(check));
- // Remove Notifications.
+ StdPDPNotification check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject(
+ "{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}",
+ StdPDPNotification.class));
+ assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}",
+ PolicyUtils.objectToJsonString(check));
+ // Remove Notifications.
notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.REMOVE);
removedPolicies = new ArrayList<>();
@@ -97,9 +103,12 @@ public class NotificationStoreTest {
removedPolicies.add(removedPolicy);
notification.setRemovedPolicies(removedPolicies);
NotificationStore.recordNotification(notification);
- check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject("{\"removedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\"},{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[],\"notificationType\":\"REMOVE\"}", StdPDPNotification.class));
- assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}", PolicyUtils.objectToJsonString(check));
- // Remove on remove duplicate Notifications.
+ check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject(
+ "{\"removedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\"},{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[],\"notificationType\":\"REMOVE\"}",
+ StdPDPNotification.class));
+ assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}",
+ PolicyUtils.objectToJsonString(check));
+ // Remove on remove duplicate Notifications.
notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.REMOVE);
removedPolicies = new ArrayList<>();
@@ -109,9 +118,12 @@ public class NotificationStoreTest {
removedPolicies.add(removedPolicy);
notification.setRemovedPolicies(removedPolicies);
NotificationStore.recordNotification(notification);
- check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject("{\"removedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\"},{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[],\"notificationType\":\"REMOVE\"}", StdPDPNotification.class));
- assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}", PolicyUtils.objectToJsonString(check));
- // Update Notification
+ check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject(
+ "{\"removedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\"},{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[],\"notificationType\":\"REMOVE\"}",
+ StdPDPNotification.class));
+ assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}",
+ PolicyUtils.objectToJsonString(check));
+ // Update Notification
notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.UPDATE);
loadedPolicies = new ArrayList<>();
@@ -125,9 +137,12 @@ public class NotificationStoreTest {
loadedPolicies.add(loadedPolicy);
notification.setLoadedPolicies(loadedPolicies);
NotificationStore.recordNotification(notification);
- check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject("{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}", StdPDPNotification.class));
- assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}", PolicyUtils.objectToJsonString(check));
- // Update on update duplicate Notification
+ check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject(
+ "{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}",
+ StdPDPNotification.class));
+ assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}",
+ PolicyUtils.objectToJsonString(check));
+ // Update on update duplicate Notification
notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.UPDATE);
loadedPolicies = new ArrayList<>();
@@ -141,9 +156,12 @@ public class NotificationStoreTest {
loadedPolicies.add(loadedPolicy);
notification.setLoadedPolicies(loadedPolicies);
NotificationStore.recordNotification(notification);
- check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject("{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}", StdPDPNotification.class));
- assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}", PolicyUtils.objectToJsonString(check));
- //
+ check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject(
+ "{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}",
+ StdPDPNotification.class));
+ assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}",
+ PolicyUtils.objectToJsonString(check));
+ //
// Notification Delta Tests
//
notification = new StdPDPNotification();
@@ -165,7 +183,9 @@ public class NotificationStoreTest {
removedPolicies.add(removedPolicy);
notification.setRemovedPolicies(removedPolicies);
check = NotificationStore.getDeltaNotification(notification);
- assertEquals("{\"removedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\"}],\"loadedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}", PolicyUtils.objectToJsonString(check));
+ assertEquals(
+ "{\"removedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\"}],\"loadedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}",
+ PolicyUtils.objectToJsonString(check));
}
}