@Test void renderNotificationWhenSpecificTemplateDoesntExists() throws Exception { ScriptContext scriptContext = mock(ScriptContext.class); when(this.scriptContextManager.getScriptContext()).thenReturn(scriptContext); Event event = mock(Event.class); when(event.getType()).thenReturn("some/type"); when(this.templateManager.getTemplate("notification/some.type.vm")).thenReturn(null); when(this.templateManager.execute("notification/default.vm")).thenReturn(new XDOM(Collections.emptyList())); CompositeEvent compositeEvent = new CompositeEvent(event); Block block = this.displayer.renderNotification(compositeEvent); assertNotNull(block); }
@Override public Block renderNotification(CompositeEvent eventNotification) throws NotificationException { ScriptContext scriptContext = this.scriptContextManager.getScriptContext(); try { scriptContext.setAttribute(EVENT_BINDING_NAME, eventNotification, ScriptContext.ENGINE_SCOPE); Template template = getSpecificTemplate(eventNotification); return (template != null) ? this.templateManager.execute(template) : this.templateManager.execute("notification/default.vm"); } catch (Exception e) { throw new NotificationException(String.format("Failed to render the notification for events [%s]", StringUtils.join(eventNotification.getEventIds(), ',')), e); } finally { scriptContext.removeAttribute(EVENT_BINDING_NAME, ScriptContext.ENGINE_SCOPE); } }
DefaultNotificationDisplayer implements NotificationDisplayer { @Override public Block renderNotification(CompositeEvent eventNotification) throws NotificationException { ScriptContext scriptContext = this.scriptContextManager.getScriptContext(); try { scriptContext.setAttribute(EVENT_BINDING_NAME, eventNotification, ScriptContext.ENGINE_SCOPE); Template template = getSpecificTemplate(eventNotification); return (template != null) ? this.templateManager.execute(template) : this.templateManager.execute("notification/default.vm"); } catch (Exception e) { throw new NotificationException(String.format("Failed to render the notification for events [%s]", StringUtils.join(eventNotification.getEventIds(), ',')), e); } finally { scriptContext.removeAttribute(EVENT_BINDING_NAME, ScriptContext.ENGINE_SCOPE); } } }
DefaultNotificationDisplayer implements NotificationDisplayer { @Override public Block renderNotification(CompositeEvent eventNotification) throws NotificationException { ScriptContext scriptContext = this.scriptContextManager.getScriptContext(); try { scriptContext.setAttribute(EVENT_BINDING_NAME, eventNotification, ScriptContext.ENGINE_SCOPE); Template template = getSpecificTemplate(eventNotification); return (template != null) ? this.templateManager.execute(template) : this.templateManager.execute("notification/default.vm"); } catch (Exception e) { throw new NotificationException(String.format("Failed to render the notification for events [%s]", StringUtils.join(eventNotification.getEventIds(), ',')), e); } finally { scriptContext.removeAttribute(EVENT_BINDING_NAME, ScriptContext.ENGINE_SCOPE); } }  }
DefaultNotificationDisplayer implements NotificationDisplayer { @Override public Block renderNotification(CompositeEvent eventNotification) throws NotificationException { ScriptContext scriptContext = this.scriptContextManager.getScriptContext(); try { scriptContext.setAttribute(EVENT_BINDING_NAME, eventNotification, ScriptContext.ENGINE_SCOPE); Template template = getSpecificTemplate(eventNotification); return (template != null) ? this.templateManager.execute(template) : this.templateManager.execute("notification/default.vm"); } catch (Exception e) { throw new NotificationException(String.format("Failed to render the notification for events [%s]", StringUtils.join(eventNotification.getEventIds(), ',')), e); } finally { scriptContext.removeAttribute(EVENT_BINDING_NAME, ScriptContext.ENGINE_SCOPE); } }  @Override Block renderNotification(CompositeEvent eventNotification); @Override List<String> getSupportedEvents(); }
DefaultNotificationDisplayer implements NotificationDisplayer { @Override public Block renderNotification(CompositeEvent eventNotification) throws NotificationException { ScriptContext scriptContext = this.scriptContextManager.getScriptContext(); try { scriptContext.setAttribute(EVENT_BINDING_NAME, eventNotification, ScriptContext.ENGINE_SCOPE); Template template = getSpecificTemplate(eventNotification); return (template != null) ? this.templateManager.execute(template) : this.templateManager.execute("notification/default.vm"); } catch (Exception e) { throw new NotificationException(String.format("Failed to render the notification for events [%s]", StringUtils.join(eventNotification.getEventIds(), ',')), e); } finally { scriptContext.removeAttribute(EVENT_BINDING_NAME, ScriptContext.ENGINE_SCOPE); } }  @Override Block renderNotification(CompositeEvent eventNotification); @Override List<String> getSupportedEvents();  }