FlattrMacro implements IMacroRunnable { @Override public String getHtml(IMacroContext macroContext) { try { IMacroSettings settings = macroContext.getSettings(); String userId = settings.getSetting("userId"); if (StringUtils.isNotBlank(userId)) { HtmlSerializerContext htmlSerializerContext = macroContext.getHtmlSerializerContext(); String projectName = htmlSerializerContext.getProjectName(); String branchName = htmlSerializerContext.getBranchName(); String path = htmlSerializerContext.getPagePath(); String pageUri = htmlSerializerContext.getPageUri(path); String pageUrl = htmlSerializerContext.getUrl(pageUri); IPageStore pageStore = htmlSerializerContext.getPageStore(); Page page = pageStore.getPage(projectName, branchName, path, false); String title = page.getTitle(); String tags = StringUtils.join(page.getTags(), ","); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("https: .queryParam("user_id", userId) .queryParam("url", pageUrl) .queryParam("title", title) .queryParam("category", "text"); if (StringUtils.isNotBlank(tags)) { builder.queryParam("tags", tags); } String url = builder.build() .encode(Charsets.UTF_8.name()) .toUriString(); return "<a href=\"" + StringEscapeUtils.escapeHtml4(url) + "\">" + "<img src=\"https: } } catch (IOException e) { log.warn("error while rendering Flattr macro", e); } return null; }  @Override String getHtml(IMacroContext macroContext); @Override String cleanupHtml(String html);  }
@Test public void getHtml() { String html = macro.getHtml(macroContext); @SuppressWarnings("nls") String re = "^<a href=\"([^\"]+)\">" + "<img src=\"https: "</a>$"; assertRE(re, html); Matcher matcher = Pattern.compile(re, Pattern.DOTALL).matcher(html); matcher.find(); String url = StringEscapeUtils.unescapeHtml4(matcher.group(1)); UriComponents components = UriComponentsBuilder.fromHttpUrl(url).build(); assertEquals("https", components.getScheme()); assertEquals("flattr.com", components.getHost()); assertEquals(-1, components.getPort()); assertEquals("/submit/auto", components.getPath()); MultiValueMap<String, String> params = components.getQueryParams(); assertEquals(FLATTR_USER_ID, params.getFirst("user_id")); assertEquals(PAGE_URL, params.getFirst("url")); assertEquals(PAGE_TITLE, params.getFirst("title")); assertEquals("text", params.getFirst("category")); assertTrue(params.getFirst("tags").equals(TAG_1 + "," + TAG_2) || params.getFirst("tags").equals(TAG_2 + "," + TAG_1)); }