@Test public void render() throws Exception { List<CompositeEvent> compositeEventList = Arrays.asList( mock(CompositeEvent.class), mock(CompositeEvent.class) ); when(this.notificationManager.getEvents(notificationParameters)).thenReturn(compositeEventList); List<CompositeEventStatus> compositeEventStatusList = Arrays.asList( mock(CompositeEventStatus.class), mock(CompositeEventStatus.class) ); when(this.compositeEventStatusManager.getCompositeEventStatuses(compositeEventList, USER_SERIALIZED_REFERENCE)) .thenReturn(compositeEventStatusList); notificationParameters.expectedCount = 2; when(this.htmlNotificationRenderer.render(compositeEventList, compositeEventStatusList, true)) .thenReturn("Expected result!"); this.asyncNotificationRenderer.initialize( new NotificationAsyncRendererConfiguration(notificationParameters, false)); assertEquals(new AsyncRendererResult("Expected result!"), this.asyncNotificationRenderer.render(false, false)); verify(this.notificationCacheManager).getFromCache(CACHE_KEY, false); verify(this.notificationCacheManager).setInCache(CACHE_KEY, compositeEventList, false); when(this.htmlNotificationRenderer.render(2)).thenReturn("Expected count result!"); this.asyncNotificationRenderer.initialize( new NotificationAsyncRendererConfiguration(notificationParameters, true)); assertEquals(new AsyncRendererResult("Expected count result!"), this.asyncNotificationRenderer.render(true, true)); verify(this.notificationCacheManager).getFromCache(CACHE_KEY, true); verify(this.notificationCacheManager).setInCache(CACHE_KEY, compositeEventList, true); compositeEventList = Arrays.asList( mock(CompositeEvent.class) ); compositeEventStatusList = Arrays.asList( mock(CompositeEventStatus.class) ); when(this.compositeEventStatusManager.getCompositeEventStatuses(compositeEventList, USER_SERIALIZED_REFERENCE)) .thenReturn(compositeEventStatusList); when(this.notificationCacheManager.getFromCache(CACHE_KEY, false)).thenReturn(compositeEventList); when(this.htmlNotificationRenderer.render(compositeEventList, compositeEventStatusList, false)) .thenReturn("Expected cache result!"); this.asyncNotificationRenderer.initialize( new NotificationAsyncRendererConfiguration(notificationParameters, false)); assertEquals(new AsyncRendererResult("Expected cache result!"), this.asyncNotificationRenderer.render(true, false)); verify(this.notificationCacheManager, never()).setInCache(CACHE_KEY, compositeEventList, false); when(this.notificationCacheManager.getFromCache(CACHE_KEY, true)).thenReturn(1); when(this.htmlNotificationRenderer.render(1)) .thenReturn("Expected count cache result!"); this.asyncNotificationRenderer.initialize( new NotificationAsyncRendererConfiguration(notificationParameters, true)); assertEquals(new AsyncRendererResult("Expected count cache result!"), this.asyncNotificationRenderer.render(false, true)); verify(this.notificationCacheManager, never()).setInCache(CACHE_KEY, compositeEventList, false); }
@Override public AsyncRendererResult render(boolean async, boolean cached) throws RenderingException { Object fromCache = this.notificationCacheManager.getFromCache(this.cacheKey, this.configuration.isCount()); NotificationParameters notificationParameters = this.configuration.getNotificationParameters(); List<CompositeEvent> events = null; Integer count = null; if (fromCache == null) { try { events = this.notificationManager.getEvents(notificationParameters); count = events.size(); this.notificationCacheManager.setInCache(this.cacheKey, events, this.configuration.isCount()); } catch (NotificationException e) { throw new RenderingException("Error while retrieving the notification", e); } } else { if (this.configuration.isCount()) { count = (Integer) fromCache; } else { events = (List<CompositeEvent>) fromCache; } } String stringResult; if (this.configuration.isCount()) { stringResult = this.htmlNotificationRenderer.render(count); } else { try { boolean loadMore = events.size() == notificationParameters.expectedCount; List<CompositeEventStatus> compositeEventStatuses = null; if (notificationParameters.user != null) { compositeEventStatuses = this.compositeEventStatusManager.getCompositeEventStatuses(events, documentReferenceSerializer.serialize(notificationParameters.user)); } stringResult = this.htmlNotificationRenderer.render(events, compositeEventStatuses, loadMore); } catch (Exception e) { throw new RenderingException("Error while retrieving the event status", e); } } return new AsyncRendererResult(stringResult); }
DefaultAsyncNotificationRenderer implements AsyncRenderer { @Override public AsyncRendererResult render(boolean async, boolean cached) throws RenderingException { Object fromCache = this.notificationCacheManager.getFromCache(this.cacheKey, this.configuration.isCount()); NotificationParameters notificationParameters = this.configuration.getNotificationParameters(); List<CompositeEvent> events = null; Integer count = null; if (fromCache == null) { try { events = this.notificationManager.getEvents(notificationParameters); count = events.size(); this.notificationCacheManager.setInCache(this.cacheKey, events, this.configuration.isCount()); } catch (NotificationException e) { throw new RenderingException("Error while retrieving the notification", e); } } else { if (this.configuration.isCount()) { count = (Integer) fromCache; } else { events = (List<CompositeEvent>) fromCache; } } String stringResult; if (this.configuration.isCount()) { stringResult = this.htmlNotificationRenderer.render(count); } else { try { boolean loadMore = events.size() == notificationParameters.expectedCount; List<CompositeEventStatus> compositeEventStatuses = null; if (notificationParameters.user != null) { compositeEventStatuses = this.compositeEventStatusManager.getCompositeEventStatuses(events, documentReferenceSerializer.serialize(notificationParameters.user)); } stringResult = this.htmlNotificationRenderer.render(events, compositeEventStatuses, loadMore); } catch (Exception e) { throw new RenderingException("Error while retrieving the event status", e); } } return new AsyncRendererResult(stringResult); } }
DefaultAsyncNotificationRenderer implements AsyncRenderer { @Override public AsyncRendererResult render(boolean async, boolean cached) throws RenderingException { Object fromCache = this.notificationCacheManager.getFromCache(this.cacheKey, this.configuration.isCount()); NotificationParameters notificationParameters = this.configuration.getNotificationParameters(); List<CompositeEvent> events = null; Integer count = null; if (fromCache == null) { try { events = this.notificationManager.getEvents(notificationParameters); count = events.size(); this.notificationCacheManager.setInCache(this.cacheKey, events, this.configuration.isCount()); } catch (NotificationException e) { throw new RenderingException("Error while retrieving the notification", e); } } else { if (this.configuration.isCount()) { count = (Integer) fromCache; } else { events = (List<CompositeEvent>) fromCache; } } String stringResult; if (this.configuration.isCount()) { stringResult = this.htmlNotificationRenderer.render(count); } else { try { boolean loadMore = events.size() == notificationParameters.expectedCount; List<CompositeEventStatus> compositeEventStatuses = null; if (notificationParameters.user != null) { compositeEventStatuses = this.compositeEventStatusManager.getCompositeEventStatuses(events, documentReferenceSerializer.serialize(notificationParameters.user)); } stringResult = this.htmlNotificationRenderer.render(events, compositeEventStatuses, loadMore); } catch (Exception e) { throw new RenderingException("Error while retrieving the event status", e); } } return new AsyncRendererResult(stringResult); }  }
DefaultAsyncNotificationRenderer implements AsyncRenderer { @Override public AsyncRendererResult render(boolean async, boolean cached) throws RenderingException { Object fromCache = this.notificationCacheManager.getFromCache(this.cacheKey, this.configuration.isCount()); NotificationParameters notificationParameters = this.configuration.getNotificationParameters(); List<CompositeEvent> events = null; Integer count = null; if (fromCache == null) { try { events = this.notificationManager.getEvents(notificationParameters); count = events.size(); this.notificationCacheManager.setInCache(this.cacheKey, events, this.configuration.isCount()); } catch (NotificationException e) { throw new RenderingException("Error while retrieving the notification", e); } } else { if (this.configuration.isCount()) { count = (Integer) fromCache; } else { events = (List<CompositeEvent>) fromCache; } } String stringResult; if (this.configuration.isCount()) { stringResult = this.htmlNotificationRenderer.render(count); } else { try { boolean loadMore = events.size() == notificationParameters.expectedCount; List<CompositeEventStatus> compositeEventStatuses = null; if (notificationParameters.user != null) { compositeEventStatuses = this.compositeEventStatusManager.getCompositeEventStatuses(events, documentReferenceSerializer.serialize(notificationParameters.user)); } stringResult = this.htmlNotificationRenderer.render(events, compositeEventStatuses, loadMore); } catch (Exception e) { throw new RenderingException("Error while retrieving the event status", e); } } return new AsyncRendererResult(stringResult); }  void initialize(NotificationAsyncRendererConfiguration configuration); @Override List<String> getId(); @Override AsyncRendererResult render(boolean async, boolean cached); @Override boolean isAsyncAllowed(); @Override boolean isCacheAllowed(); @Override JobGroupPath getJobGroupPath(); }
DefaultAsyncNotificationRenderer implements AsyncRenderer { @Override public AsyncRendererResult render(boolean async, boolean cached) throws RenderingException { Object fromCache = this.notificationCacheManager.getFromCache(this.cacheKey, this.configuration.isCount()); NotificationParameters notificationParameters = this.configuration.getNotificationParameters(); List<CompositeEvent> events = null; Integer count = null; if (fromCache == null) { try { events = this.notificationManager.getEvents(notificationParameters); count = events.size(); this.notificationCacheManager.setInCache(this.cacheKey, events, this.configuration.isCount()); } catch (NotificationException e) { throw new RenderingException("Error while retrieving the notification", e); } } else { if (this.configuration.isCount()) { count = (Integer) fromCache; } else { events = (List<CompositeEvent>) fromCache; } } String stringResult; if (this.configuration.isCount()) { stringResult = this.htmlNotificationRenderer.render(count); } else { try { boolean loadMore = events.size() == notificationParameters.expectedCount; List<CompositeEventStatus> compositeEventStatuses = null; if (notificationParameters.user != null) { compositeEventStatuses = this.compositeEventStatusManager.getCompositeEventStatuses(events, documentReferenceSerializer.serialize(notificationParameters.user)); } stringResult = this.htmlNotificationRenderer.render(events, compositeEventStatuses, loadMore); } catch (Exception e) { throw new RenderingException("Error while retrieving the event status", e); } } return new AsyncRendererResult(stringResult); }  void initialize(NotificationAsyncRendererConfiguration configuration); @Override List<String> getId(); @Override AsyncRendererResult render(boolean async, boolean cached); @Override boolean isAsyncAllowed(); @Override boolean isCacheAllowed(); @Override JobGroupPath getJobGroupPath();  }