@Test
public void deleteMetadaLinkWhenMdDisappeared() throws Exception {

    // user will have to purge himself orphan link (no metadatalink anymore) using ui:
    //      one can imagine that when network switches for example url have to be kept aside
    // orphan metadatalink (no metadata anymore) purge can be trigered when checking link:
    //      this is toTest.purge method purpose.
    // note that metadata table and medatalink table are loosely coupled:
    //      no constraints beetween them.
    Element mdAsXml = getMdAsXml();
    AbstractMetadata md = insertMetadataInDb(mdAsXml);
    UrlAnalyzer toTest = createToTest();
    toTest.processMetadata(mdAsXml, md);
    SimpleJpaRepository metadataLinkRepository = new SimpleJpaRepository<MetadataLink, Integer>(MetadataLink.class, entityManager);
    List<MetadataLink> metadataLinkList = metadataLinkRepository.findAll();
    assertEquals(6, metadataLinkList.size());
    dataManager.deleteMetadata(context, md.getId() + "");
    linkRepository.findAll().stream().forEach(toTest::purgeMetataLink);
    metadataLinkList = metadataLinkRepository.findAll();
    assertEquals(0, metadataLinkList.size());
    Set<String> urlFromDb = linkRepository.findAll().stream().map(Link::getUrl).collect(Collectors.toSet());
    assertEquals(6, urlFromDb.size());
}