@Test public void execute() throws Exception { RssMacroParameters rssMacroParameters = new RssMacroParameters(); rssMacroParameters.setContent(true); rssMacroParameters.setCount(4); rssMacroParameters.setImage(true); rssMacroParameters.setWidth("100"); rssMacroParameters.setEncoding("UTF-8"); rssMacroParameters.setDecoration(true); rssMacroParameters.setFeed("http: MacroTransformationContext macroTransformationContext = mock(MacroTransformationContext.class); File feedFile = new File("src/test/resources/feed1.xml"); SyndFeed syndFeed = new SyndFeedInput().build(new XmlReader(new FileInputStream(feedFile), true, rssMacroParameters.getEncoding())); when(romeFeedFactory.createFeed(rssMacroParameters)).thenReturn(syndFeed); when(context.getProperty("RssMacro.feed")).thenReturn(syndFeed); this.macro.setFeedFactory(romeFeedFactory); List<Block> expectedBlockList = Collections.singletonList( new GroupBlock(Collections.singletonList(new WordBlock("foo"))) ); when(plainTextParser.parse(any())).thenReturn(new XDOM(expectedBlockList)); when(contentParser.parse("Some content", macroTransformationContext, false, false)) .thenReturn(new XDOM(expectedBlockList)); List<Block> obtainedContent = this.macro.execute(rssMacroParameters, "Some content", macroTransformationContext); assertEquals(1, obtainedContent.size()); GroupBlock groupBlock = (GroupBlock) obtainedContent.get(0); assertEquals("box rssfeed", groupBlock.getParameter("class")); assertEquals("width:100", groupBlock.getParameter("style")); List<Block> children = groupBlock.getChildren(); assertEquals(12, children.size()); assertTrue(children.get(0) instanceof ImageBlock); ImageBlock imageBlock = (ImageBlock) children.get(0); assertEquals("http: assertTrue(children.get(1) instanceof NewLineBlock); assertTrue(children.get(2) instanceof ParagraphBlock); ParagraphBlock paragraphBlock = (ParagraphBlock) children.get(2); assertEquals("rsschanneltitle", paragraphBlock.getParameter("class")); assertEquals(2, paragraphBlock.getChildren().size()); assertTrue(paragraphBlock.getChildren().get(0) instanceof LinkBlock); LinkBlock firstLink = (LinkBlock) paragraphBlock.getChildren().get(0); assertEquals("http: assertEquals(ResourceType.URL, firstLink.getReference().getType()); assertEquals(1, firstLink.getChildren().size()); assertEquals(new WordBlock("foo"), firstLink.getChildren().get(0)); assertTrue(paragraphBlock.getChildren().get(1) instanceof LinkBlock); LinkBlock secondLink = (LinkBlock) paragraphBlock.getChildren().get(1); assertEquals("http: assertEquals(ResourceType.URL, secondLink.getReference().getType()); assertEquals(1, secondLink.getChildren().size()); assertTrue(secondLink.getChildren().get(0) instanceof ImageBlock); assertEquals(expectedBlockList.get(0), children.get(3)); assertTrue(children.get(4) instanceof ParagraphBlock); paragraphBlock = (ParagraphBlock) children.get(4); assertEquals("rssitemtitle", paragraphBlock.getParameter("class")); assertEquals(1, paragraphBlock.getChildren().size()); assertTrue(paragraphBlock.getChildren().get(0) instanceof LinkBlock); firstLink = (LinkBlock) paragraphBlock.getChildren().get(0); assertEquals("http: firstLink.getReference().getReference()); assertEquals(ResourceType.URL, firstLink.getReference().getType()); assertEquals(1, firstLink.getChildren().size()); assertEquals(new WordBlock("foo"), firstLink.getChildren().get(0)); assertTrue(children.get(5) instanceof GroupBlock); groupBlock = (GroupBlock) children.get(5); assertEquals("rssitemdescription", groupBlock.getParameter("class")); assertEquals(1, groupBlock.getChildren().size()); assertEquals( new RawBlock("How do Americans get ready to work with Russians aboard the International Space Station?", Syntax.XHTML_1_0), groupBlock.getChildren().get(0)); }
@Override public List<Block> execute(RssMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { List<Block> result; SyndFeed feed = this.romeFeedFactory.createFeed(parameters); this.setFeed(feed); if (parameters.isDecoration()) { result = super.execute(parameters, content == null ? StringUtils.EMPTY : content, context); } else { result = Arrays.<Block>asList(new GroupBlock(Collections.singletonMap(CLASS_ATTRIBUTE, FEED_CLASS_VALUE))); } generateEntries(result.get(0), feed, parameters); this.removeContextFeed(); return result; }
RssMacro extends AbstractBoxMacro<RssMacroParameters> { @Override public List<Block> execute(RssMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { List<Block> result; SyndFeed feed = this.romeFeedFactory.createFeed(parameters); this.setFeed(feed); if (parameters.isDecoration()) { result = super.execute(parameters, content == null ? StringUtils.EMPTY : content, context); } else { result = Arrays.<Block>asList(new GroupBlock(Collections.singletonMap(CLASS_ATTRIBUTE, FEED_CLASS_VALUE))); } generateEntries(result.get(0), feed, parameters); this.removeContextFeed(); return result; } }
RssMacro extends AbstractBoxMacro<RssMacroParameters> { @Override public List<Block> execute(RssMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { List<Block> result; SyndFeed feed = this.romeFeedFactory.createFeed(parameters); this.setFeed(feed); if (parameters.isDecoration()) { result = super.execute(parameters, content == null ? StringUtils.EMPTY : content, context); } else { result = Arrays.<Block>asList(new GroupBlock(Collections.singletonMap(CLASS_ATTRIBUTE, FEED_CLASS_VALUE))); } generateEntries(result.get(0), feed, parameters); this.removeContextFeed(); return result; } RssMacro(); }
RssMacro extends AbstractBoxMacro<RssMacroParameters> { @Override public List<Block> execute(RssMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { List<Block> result; SyndFeed feed = this.romeFeedFactory.createFeed(parameters); this.setFeed(feed); if (parameters.isDecoration()) { result = super.execute(parameters, content == null ? StringUtils.EMPTY : content, context); } else { result = Arrays.<Block>asList(new GroupBlock(Collections.singletonMap(CLASS_ATTRIBUTE, FEED_CLASS_VALUE))); } generateEntries(result.get(0), feed, parameters); this.removeContextFeed(); return result; } RssMacro(); @Override boolean supportsInlineMode(); @Override List<Block> execute(RssMacroParameters parameters, String content, MacroTransformationContext context); }
RssMacro extends AbstractBoxMacro<RssMacroParameters> { @Override public List<Block> execute(RssMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { List<Block> result; SyndFeed feed = this.romeFeedFactory.createFeed(parameters); this.setFeed(feed); if (parameters.isDecoration()) { result = super.execute(parameters, content == null ? StringUtils.EMPTY : content, context); } else { result = Arrays.<Block>asList(new GroupBlock(Collections.singletonMap(CLASS_ATTRIBUTE, FEED_CLASS_VALUE))); } generateEntries(result.get(0), feed, parameters); this.removeContextFeed(); return result; } RssMacro(); @Override boolean supportsInlineMode(); @Override List<Block> execute(RssMacroParameters parameters, String content, MacroTransformationContext context);  }