@Test
  public void getRichTextImageHasCorrectUrl() throws RepositoryException, RichTextException {
    final RichTextImage image =
        new RichTextImage("/content/gallery/image.png/image.png", "image.png");
    image.setSelectedResourceDefinition("hippogallery:original");

    final IRichTextImageFactory mockImageFactory = EasyMock.createMock(IRichTextImageFactory.class);
    expect(mockImageFactory.loadImageItem(eq("image.png/{_document}/hippogallery:original")))
        .andReturn(image);

    final IRichTextLinkFactory mockLinkFactory = EasyMock.createMock(IRichTextLinkFactory.class);
    expect(mockLinkFactory.getLinkUuids())
        .andReturn(Collections.singleton("0e8a928c-b83f-4bb9-9e52-1a22b7e9ee21"));

    final Node documentNode = MockNode.root();
    final Node imageFacetNode = documentNode.addNode("image.png", HippoNodeType.NT_FACETSELECT);
    imageFacetNode.setProperty(HippoNodeType.HIPPO_DOCBASE, "0e8a928c-b83f-4bb9-9e52-1a22b7e9ee21");

    final IModel<Node> mockNodeModel = EasyMock.createMock(IModel.class);
    expect(mockNodeModel.getObject()).andReturn(documentNode).anyTimes();

    final RichTextImageURLProvider urlProvider =
        new RichTextImageURLProvider(mockImageFactory, mockLinkFactory, mockNodeModel);

    replay(mockImageFactory, mockLinkFactory, mockNodeModel);

    model = new RichTextImageMetaDataModel(delegate, urlProvider);
    delegate.setObject("<img src=\"image.png/{_document}/hippogallery:original\"/>");

    assertEquals(
        "<img src=\"binaries/content/gallery/image.png/image.png/hippogallery:original\" data-facetselect=\"image.png/{_document}/hippogallery:original\" data-type=\"hippogallery:original\"/>",
        model.getObject());
  }
 public String getURL(String link) throws RichTextException {
   final String facetName = StringUtils.substringBefore(link, "/");
   final Node node = this.nodeModel.getObject();
   final String uuidOrNull = RichTextFacetHelper.getChildDocBaseOrNull(node, facetName);
   if (uuidOrNull != null && linkFactory.getLinkUuids().contains(uuidOrNull)) {
     RichTextImage rti = imageFactory.loadImageItem(link);
     return rti.getUrl();
   }
   return link;
 }