@Test public void createCacheKey() { DocumentReference userReference = new DocumentReference("xwiki", "XWiki", "Foobar"); when(this.entityReferenceSerializer.serialize(userReference)).thenReturn("xwiki:XWiki.Foobar"); DocumentReference userReference2 = new DocumentReference("xwiki", "XWiki", "Another"); when(this.entityReferenceSerializer.serialize(userReference2)).thenReturn("xwiki:XWiki.another"); NotificationParameters notificationParameters = new NotificationParameters(); notificationParameters.format = NotificationFormat.ALERT; notificationParameters.endDate = new Date(42); notificationParameters.blackList = Collections.singletonList("foo"); notificationParameters.fromDate = new Date(); notificationParameters.filters = Collections.singletonList(mock(NotificationFilter.class)); notificationParameters.user = userReference; notificationParameters.expectedCount = 22; notificationParameters.onlyUnread = true; int hashCode = notificationParameters.hashCode(); assertEquals("5ALERT/18xwiki:XWiki.Foobar/42/true/22/true/" + hashCode, this.defaultNotificationCacheManager.createCacheKey(notificationParameters)); NotificationParameters notificationParameters2 = new NotificationParameters(); notificationParameters2.format = NotificationFormat.ALERT; notificationParameters2.endDate = new Date(42); notificationParameters2.user = userReference; notificationParameters2.expectedCount = 22; notificationParameters2.onlyUnread = true; hashCode = notificationParameters2.hashCode(); assertEquals("5ALERT/18xwiki:XWiki.Foobar/42/true/22/true/" + hashCode, this.defaultNotificationCacheManager.createCacheKey(notificationParameters2)); assertNotEquals(notificationParameters, notificationParameters2); assertNotEquals(this.defaultNotificationCacheManager.createCacheKey(notificationParameters), this.defaultNotificationCacheManager.createCacheKey(notificationParameters2)); notificationParameters = new NotificationParameters(); notificationParameters.format = NotificationFormat.EMAIL; notificationParameters.endDate = new Date(84); notificationParameters.user = userReference2; notificationParameters.expectedCount = 444; notificationParameters.onlyUnread = false; hashCode = notificationParameters.hashCode(); assertEquals("5EMAIL/19xwiki:XWiki.another/84/true/444/false/" + hashCode, this.defaultNotificationCacheManager.createCacheKey(notificationParameters)); notificationParameters = new NotificationParameters(); notificationParameters.format = NotificationFormat.EMAIL; notificationParameters.endDate = new Date(84); notificationParameters.endDateIncluded = false; notificationParameters.user = userReference2; notificationParameters.expectedCount = 444; notificationParameters.onlyUnread = false; hashCode = notificationParameters.hashCode(); assertEquals("5EMAIL/19xwiki:XWiki.another/84/false/444/false/" + hashCode, this.defaultNotificationCacheManager.createCacheKey(notificationParameters)); notificationParameters = new NotificationParameters(); notificationParameters.format = NotificationFormat.EMAIL; notificationParameters.user = userReference2; notificationParameters.expectedCount = 444; notificationParameters.onlyUnread = false; hashCode = notificationParameters.hashCode(); assertEquals("5EMAIL/19xwiki:XWiki.another/444/false/" + hashCode, this.defaultNotificationCacheManager.createCacheKey(notificationParameters)); notificationParameters = new NotificationParameters(); notificationParameters.format = NotificationFormat.EMAIL; notificationParameters.user = userReference2; hashCode = notificationParameters.hashCode(); assertEquals("5EMAIL/19xwiki:XWiki.another/0/null/" + hashCode, this.defaultNotificationCacheManager.createCacheKey(notificationParameters)); }
public String createCacheKey(NotificationParameters notificationParameters) { StringBuilder cacheKeyBuilder = new StringBuilder(); addCacheKeyElement(cacheKeyBuilder, notificationParameters.format.name()); cacheKeyBuilder.append(CACHE_KEY_SEPARATOR); addCacheKeyElement(cacheKeyBuilder, this.entityReferenceSerializer.serialize(notificationParameters.user)); cacheKeyBuilder.append(CACHE_KEY_SEPARATOR); if (notificationParameters.endDate != null) { cacheKeyBuilder.append(notificationParameters.endDate.getTime()) .append(CACHE_KEY_SEPARATOR); cacheKeyBuilder.append(notificationParameters.endDateIncluded) .append(CACHE_KEY_SEPARATOR); } cacheKeyBuilder .append(notificationParameters.expectedCount) .append(CACHE_KEY_SEPARATOR) .append(notificationParameters.onlyUnread) .append(CACHE_KEY_SEPARATOR) .append(notificationParameters.hashCode()); return cacheKeyBuilder.toString(); }
DefaultNotificationCacheManager implements Initializable, Disposable { public String createCacheKey(NotificationParameters notificationParameters) { StringBuilder cacheKeyBuilder = new StringBuilder(); addCacheKeyElement(cacheKeyBuilder, notificationParameters.format.name()); cacheKeyBuilder.append(CACHE_KEY_SEPARATOR); addCacheKeyElement(cacheKeyBuilder, this.entityReferenceSerializer.serialize(notificationParameters.user)); cacheKeyBuilder.append(CACHE_KEY_SEPARATOR); if (notificationParameters.endDate != null) { cacheKeyBuilder.append(notificationParameters.endDate.getTime()) .append(CACHE_KEY_SEPARATOR); cacheKeyBuilder.append(notificationParameters.endDateIncluded) .append(CACHE_KEY_SEPARATOR); } cacheKeyBuilder .append(notificationParameters.expectedCount) .append(CACHE_KEY_SEPARATOR) .append(notificationParameters.onlyUnread) .append(CACHE_KEY_SEPARATOR) .append(notificationParameters.hashCode()); return cacheKeyBuilder.toString(); } }
DefaultNotificationCacheManager implements Initializable, Disposable { public String createCacheKey(NotificationParameters notificationParameters) { StringBuilder cacheKeyBuilder = new StringBuilder(); addCacheKeyElement(cacheKeyBuilder, notificationParameters.format.name()); cacheKeyBuilder.append(CACHE_KEY_SEPARATOR); addCacheKeyElement(cacheKeyBuilder, this.entityReferenceSerializer.serialize(notificationParameters.user)); cacheKeyBuilder.append(CACHE_KEY_SEPARATOR); if (notificationParameters.endDate != null) { cacheKeyBuilder.append(notificationParameters.endDate.getTime()) .append(CACHE_KEY_SEPARATOR); cacheKeyBuilder.append(notificationParameters.endDateIncluded) .append(CACHE_KEY_SEPARATOR); } cacheKeyBuilder .append(notificationParameters.expectedCount) .append(CACHE_KEY_SEPARATOR) .append(notificationParameters.onlyUnread) .append(CACHE_KEY_SEPARATOR) .append(notificationParameters.hashCode()); return cacheKeyBuilder.toString(); }  }
DefaultNotificationCacheManager implements Initializable, Disposable { public String createCacheKey(NotificationParameters notificationParameters) { StringBuilder cacheKeyBuilder = new StringBuilder(); addCacheKeyElement(cacheKeyBuilder, notificationParameters.format.name()); cacheKeyBuilder.append(CACHE_KEY_SEPARATOR); addCacheKeyElement(cacheKeyBuilder, this.entityReferenceSerializer.serialize(notificationParameters.user)); cacheKeyBuilder.append(CACHE_KEY_SEPARATOR); if (notificationParameters.endDate != null) { cacheKeyBuilder.append(notificationParameters.endDate.getTime()) .append(CACHE_KEY_SEPARATOR); cacheKeyBuilder.append(notificationParameters.endDateIncluded) .append(CACHE_KEY_SEPARATOR); } cacheKeyBuilder .append(notificationParameters.expectedCount) .append(CACHE_KEY_SEPARATOR) .append(notificationParameters.onlyUnread) .append(CACHE_KEY_SEPARATOR) .append(notificationParameters.hashCode()); return cacheKeyBuilder.toString(); }  @Override void initialize(); String createCacheKey(NotificationParameters notificationParameters); Object getFromCache(String cacheKey, boolean count); void setInCache(String cacheKey, List<CompositeEvent> events, boolean count); void flushLongCache(); @Override void dispose(); }
DefaultNotificationCacheManager implements Initializable, Disposable { public String createCacheKey(NotificationParameters notificationParameters) { StringBuilder cacheKeyBuilder = new StringBuilder(); addCacheKeyElement(cacheKeyBuilder, notificationParameters.format.name()); cacheKeyBuilder.append(CACHE_KEY_SEPARATOR); addCacheKeyElement(cacheKeyBuilder, this.entityReferenceSerializer.serialize(notificationParameters.user)); cacheKeyBuilder.append(CACHE_KEY_SEPARATOR); if (notificationParameters.endDate != null) { cacheKeyBuilder.append(notificationParameters.endDate.getTime()) .append(CACHE_KEY_SEPARATOR); cacheKeyBuilder.append(notificationParameters.endDateIncluded) .append(CACHE_KEY_SEPARATOR); } cacheKeyBuilder .append(notificationParameters.expectedCount) .append(CACHE_KEY_SEPARATOR) .append(notificationParameters.onlyUnread) .append(CACHE_KEY_SEPARATOR) .append(notificationParameters.hashCode()); return cacheKeyBuilder.toString(); }  @Override void initialize(); String createCacheKey(NotificationParameters notificationParameters); Object getFromCache(String cacheKey, boolean count); void setInCache(String cacheKey, List<CompositeEvent> events, boolean count); void flushLongCache(); @Override void dispose();  }