@Test public void testCompositeEventRendering() throws Exception { CompositeEvent testCompositeEvent = mock(CompositeEvent.class); this.mockEvent(testCompositeEvent); when(this.scriptContextManager.getCurrentScriptContext()).thenReturn(Mockito.mock(ScriptContext.class)); SyndEntry resultEntry = this.mocker.getComponentUnderTest().renderNotification(testCompositeEvent); assertEquals("TranslatedEventTitle", resultEntry.getTitle()); assertEquals(1, resultEntry.getAuthors().size()); assertEquals("id1", resultEntry.getUri()); }
@Override public SyndEntry renderNotification(CompositeEvent eventNotification) throws NotificationException { SyndEntry entry = new SyndEntryImpl(); SyndContent entryDescription = new SyndContentImpl(); List<SyndPerson> eventAuthors = new ArrayList<SyndPerson>(); for (DocumentReference author : eventNotification.getUsers()) { SyndPerson person = new SyndPersonImpl(); person.setName(author.getName()); eventAuthors.add(person); } entry.setAuthors(eventAuthors); entry.setUri(String.join("-", eventNotification.getEventIds())); entry.setTitle(this.contextualLocalizationManager.getTranslationPlain( eventNotification.getEvents().get(0).getTitle(), eventNotification.getEvents().get(0).getDocumentTitle())); try { this.scriptContextManager.getCurrentScriptContext().setAttribute( COMPOSITE_EVENT_BUILDING_NAME, eventNotification, ScriptContext.ENGINE_SCOPE); Template template = this.templateManager.getTemplate(String.format("notification/rss/%s.vm", eventNotification.getType().replaceAll("\\/", "."))); if (template == null) { template = this.templateManager.getTemplate("notification/rss/default.vm"); } XDOM descriptionXDOM = this.templateManager.execute(template); WikiPrinter printer = new DefaultWikiPrinter(); blockRenderer.render(descriptionXDOM, printer); entryDescription.setType("text/html"); entryDescription.setValue(printer.toString()); entry.setDescription(entryDescription); } catch (Exception e) { throw new NotificationException( String.format("Unable to render the description of the event [%s].", eventNotification), e); } finally { this.scriptContextManager.getCurrentScriptContext().removeAttribute( COMPOSITE_EVENT_BUILDING_NAME, ScriptContext.ENGINE_SCOPE); } entry.setUpdatedDate(eventNotification.getDates().get(0)); return entry; }
DefaultNotificationRSSRenderer implements NotificationRSSRenderer { @Override public SyndEntry renderNotification(CompositeEvent eventNotification) throws NotificationException { SyndEntry entry = new SyndEntryImpl(); SyndContent entryDescription = new SyndContentImpl(); List<SyndPerson> eventAuthors = new ArrayList<SyndPerson>(); for (DocumentReference author : eventNotification.getUsers()) { SyndPerson person = new SyndPersonImpl(); person.setName(author.getName()); eventAuthors.add(person); } entry.setAuthors(eventAuthors); entry.setUri(String.join("-", eventNotification.getEventIds())); entry.setTitle(this.contextualLocalizationManager.getTranslationPlain( eventNotification.getEvents().get(0).getTitle(), eventNotification.getEvents().get(0).getDocumentTitle())); try { this.scriptContextManager.getCurrentScriptContext().setAttribute( COMPOSITE_EVENT_BUILDING_NAME, eventNotification, ScriptContext.ENGINE_SCOPE); Template template = this.templateManager.getTemplate(String.format("notification/rss/%s.vm", eventNotification.getType().replaceAll("\\/", "."))); if (template == null) { template = this.templateManager.getTemplate("notification/rss/default.vm"); } XDOM descriptionXDOM = this.templateManager.execute(template); WikiPrinter printer = new DefaultWikiPrinter(); blockRenderer.render(descriptionXDOM, printer); entryDescription.setType("text/html"); entryDescription.setValue(printer.toString()); entry.setDescription(entryDescription); } catch (Exception e) { throw new NotificationException( String.format("Unable to render the description of the event [%s].", eventNotification), e); } finally { this.scriptContextManager.getCurrentScriptContext().removeAttribute( COMPOSITE_EVENT_BUILDING_NAME, ScriptContext.ENGINE_SCOPE); } entry.setUpdatedDate(eventNotification.getDates().get(0)); return entry; } }
DefaultNotificationRSSRenderer implements NotificationRSSRenderer { @Override public SyndEntry renderNotification(CompositeEvent eventNotification) throws NotificationException { SyndEntry entry = new SyndEntryImpl(); SyndContent entryDescription = new SyndContentImpl(); List<SyndPerson> eventAuthors = new ArrayList<SyndPerson>(); for (DocumentReference author : eventNotification.getUsers()) { SyndPerson person = new SyndPersonImpl(); person.setName(author.getName()); eventAuthors.add(person); } entry.setAuthors(eventAuthors); entry.setUri(String.join("-", eventNotification.getEventIds())); entry.setTitle(this.contextualLocalizationManager.getTranslationPlain( eventNotification.getEvents().get(0).getTitle(), eventNotification.getEvents().get(0).getDocumentTitle())); try { this.scriptContextManager.getCurrentScriptContext().setAttribute( COMPOSITE_EVENT_BUILDING_NAME, eventNotification, ScriptContext.ENGINE_SCOPE); Template template = this.templateManager.getTemplate(String.format("notification/rss/%s.vm", eventNotification.getType().replaceAll("\\/", "."))); if (template == null) { template = this.templateManager.getTemplate("notification/rss/default.vm"); } XDOM descriptionXDOM = this.templateManager.execute(template); WikiPrinter printer = new DefaultWikiPrinter(); blockRenderer.render(descriptionXDOM, printer); entryDescription.setType("text/html"); entryDescription.setValue(printer.toString()); entry.setDescription(entryDescription); } catch (Exception e) { throw new NotificationException( String.format("Unable to render the description of the event [%s].", eventNotification), e); } finally { this.scriptContextManager.getCurrentScriptContext().removeAttribute( COMPOSITE_EVENT_BUILDING_NAME, ScriptContext.ENGINE_SCOPE); } entry.setUpdatedDate(eventNotification.getDates().get(0)); return entry; }  }
DefaultNotificationRSSRenderer implements NotificationRSSRenderer { @Override public SyndEntry renderNotification(CompositeEvent eventNotification) throws NotificationException { SyndEntry entry = new SyndEntryImpl(); SyndContent entryDescription = new SyndContentImpl(); List<SyndPerson> eventAuthors = new ArrayList<SyndPerson>(); for (DocumentReference author : eventNotification.getUsers()) { SyndPerson person = new SyndPersonImpl(); person.setName(author.getName()); eventAuthors.add(person); } entry.setAuthors(eventAuthors); entry.setUri(String.join("-", eventNotification.getEventIds())); entry.setTitle(this.contextualLocalizationManager.getTranslationPlain( eventNotification.getEvents().get(0).getTitle(), eventNotification.getEvents().get(0).getDocumentTitle())); try { this.scriptContextManager.getCurrentScriptContext().setAttribute( COMPOSITE_EVENT_BUILDING_NAME, eventNotification, ScriptContext.ENGINE_SCOPE); Template template = this.templateManager.getTemplate(String.format("notification/rss/%s.vm", eventNotification.getType().replaceAll("\\/", "."))); if (template == null) { template = this.templateManager.getTemplate("notification/rss/default.vm"); } XDOM descriptionXDOM = this.templateManager.execute(template); WikiPrinter printer = new DefaultWikiPrinter(); blockRenderer.render(descriptionXDOM, printer); entryDescription.setType("text/html"); entryDescription.setValue(printer.toString()); entry.setDescription(entryDescription); } catch (Exception e) { throw new NotificationException( String.format("Unable to render the description of the event [%s].", eventNotification), e); } finally { this.scriptContextManager.getCurrentScriptContext().removeAttribute( COMPOSITE_EVENT_BUILDING_NAME, ScriptContext.ENGINE_SCOPE); } entry.setUpdatedDate(eventNotification.getDates().get(0)); return entry; }  @Override SyndEntry renderNotification(CompositeEvent eventNotification); }
DefaultNotificationRSSRenderer implements NotificationRSSRenderer { @Override public SyndEntry renderNotification(CompositeEvent eventNotification) throws NotificationException { SyndEntry entry = new SyndEntryImpl(); SyndContent entryDescription = new SyndContentImpl(); List<SyndPerson> eventAuthors = new ArrayList<SyndPerson>(); for (DocumentReference author : eventNotification.getUsers()) { SyndPerson person = new SyndPersonImpl(); person.setName(author.getName()); eventAuthors.add(person); } entry.setAuthors(eventAuthors); entry.setUri(String.join("-", eventNotification.getEventIds())); entry.setTitle(this.contextualLocalizationManager.getTranslationPlain( eventNotification.getEvents().get(0).getTitle(), eventNotification.getEvents().get(0).getDocumentTitle())); try { this.scriptContextManager.getCurrentScriptContext().setAttribute( COMPOSITE_EVENT_BUILDING_NAME, eventNotification, ScriptContext.ENGINE_SCOPE); Template template = this.templateManager.getTemplate(String.format("notification/rss/%s.vm", eventNotification.getType().replaceAll("\\/", "."))); if (template == null) { template = this.templateManager.getTemplate("notification/rss/default.vm"); } XDOM descriptionXDOM = this.templateManager.execute(template); WikiPrinter printer = new DefaultWikiPrinter(); blockRenderer.render(descriptionXDOM, printer); entryDescription.setType("text/html"); entryDescription.setValue(printer.toString()); entry.setDescription(entryDescription); } catch (Exception e) { throw new NotificationException( String.format("Unable to render the description of the event [%s].", eventNotification), e); } finally { this.scriptContextManager.getCurrentScriptContext().removeAttribute( COMPOSITE_EVENT_BUILDING_NAME, ScriptContext.ENGINE_SCOPE); } entry.setUpdatedDate(eventNotification.getDates().get(0)); return entry; }  @Override SyndEntry renderNotification(CompositeEvent eventNotification); static final String COMPOSITE_EVENT_BUILDING_NAME; }