@Test public void transform() throws Exception { String input = "" + "whatever" + "[[http: + "[[invalid]]" + "[[unsupportedrotocol: HTTPChecker httpChecker = this.componentManager.registerMockComponent(HTTPChecker.class); when(httpChecker.check("http: when(httpChecker.check("invalid")).thenReturn(0); LinkStateManager linkStateManager = this.componentManager.getInstance(LinkStateManager.class); transformAndWait(input, linkStateManager, 2); LinkCheckerScriptService service = this.componentManager.getInstance(ScriptService.class, "linkchecker"); Map<String, Map<String, LinkState>> states = service.getLinkStates(); LinkState state1 = states.get("http: assertEquals(200, state1.getResponseCode()); LinkState state2 = states.get("invalid").get("default"); assertEquals(0, state2.getResponseCode()); }
@Override public void transform(Block source, TransformationContext context) throws TransformationException { if (getLinkQueue().size() < MAX_LINKS_IN_QUEUE) { for (LinkBlock linkBlock : source.<LinkBlock>getBlocks( new ClassBlockMatcher(LinkBlock.class), Block.Axes.DESCENDANT)) { if (linkBlock.getReference().getType().equals(ResourceType.URL)) { String linkReference = linkBlock.getReference().getReference(); String contentReference = extractSourceContentReference(linkBlock); if (contentReference == null) { contentReference = "default"; } Map<String, Object> linkContextData = createLinkContextData(linkReference, contentReference); this.linkQueue.add(new LinkQueueItem(linkReference, contentReference, linkContextData)); } } } }
LinkCheckerTransformation extends AbstractTransformation implements Initializable { @Override public void transform(Block source, TransformationContext context) throws TransformationException { if (getLinkQueue().size() < MAX_LINKS_IN_QUEUE) { for (LinkBlock linkBlock : source.<LinkBlock>getBlocks( new ClassBlockMatcher(LinkBlock.class), Block.Axes.DESCENDANT)) { if (linkBlock.getReference().getType().equals(ResourceType.URL)) { String linkReference = linkBlock.getReference().getReference(); String contentReference = extractSourceContentReference(linkBlock); if (contentReference == null) { contentReference = "default"; } Map<String, Object> linkContextData = createLinkContextData(linkReference, contentReference); this.linkQueue.add(new LinkQueueItem(linkReference, contentReference, linkContextData)); } } } } }
LinkCheckerTransformation extends AbstractTransformation implements Initializable { @Override public void transform(Block source, TransformationContext context) throws TransformationException { if (getLinkQueue().size() < MAX_LINKS_IN_QUEUE) { for (LinkBlock linkBlock : source.<LinkBlock>getBlocks( new ClassBlockMatcher(LinkBlock.class), Block.Axes.DESCENDANT)) { if (linkBlock.getReference().getType().equals(ResourceType.URL)) { String linkReference = linkBlock.getReference().getReference(); String contentReference = extractSourceContentReference(linkBlock); if (contentReference == null) { contentReference = "default"; } Map<String, Object> linkContextData = createLinkContextData(linkReference, contentReference); this.linkQueue.add(new LinkQueueItem(linkReference, contentReference, linkContextData)); } } } }  }
LinkCheckerTransformation extends AbstractTransformation implements Initializable { @Override public void transform(Block source, TransformationContext context) throws TransformationException { if (getLinkQueue().size() < MAX_LINKS_IN_QUEUE) { for (LinkBlock linkBlock : source.<LinkBlock>getBlocks( new ClassBlockMatcher(LinkBlock.class), Block.Axes.DESCENDANT)) { if (linkBlock.getReference().getType().equals(ResourceType.URL)) { String linkReference = linkBlock.getReference().getReference(); String contentReference = extractSourceContentReference(linkBlock); if (contentReference == null) { contentReference = "default"; } Map<String, Object> linkContextData = createLinkContextData(linkReference, contentReference); this.linkQueue.add(new LinkQueueItem(linkReference, contentReference, linkContextData)); } } } }  @Override void initialize(); @Override void transform(Block source, TransformationContext context); void stopLinkCheckerThread(); Queue<LinkQueueItem> getLinkQueue(); }
LinkCheckerTransformation extends AbstractTransformation implements Initializable { @Override public void transform(Block source, TransformationContext context) throws TransformationException { if (getLinkQueue().size() < MAX_LINKS_IN_QUEUE) { for (LinkBlock linkBlock : source.<LinkBlock>getBlocks( new ClassBlockMatcher(LinkBlock.class), Block.Axes.DESCENDANT)) { if (linkBlock.getReference().getType().equals(ResourceType.URL)) { String linkReference = linkBlock.getReference().getReference(); String contentReference = extractSourceContentReference(linkBlock); if (contentReference == null) { contentReference = "default"; } Map<String, Object> linkContextData = createLinkContextData(linkReference, contentReference); this.linkQueue.add(new LinkQueueItem(linkReference, contentReference, linkContextData)); } } } }  @Override void initialize(); @Override void transform(Block source, TransformationContext context); void stopLinkCheckerThread(); Queue<LinkQueueItem> getLinkQueue();  }