@Test
public void encounteringAnUrlForTheFirstTimeAndPersistingIt() throws Exception {

    Element mdAsXml = getMdAsXml();
    AbstractMetadata md = insertMetadataInDb(mdAsXml);
    UrlAnalyzer toTest = createToTest();
    toTest.processMetadata(mdAsXml, md);
    Set<String> urlFromDb = linkRepository.findAll().stream().map(Link::getUrl).collect(Collectors.toSet());
    assertTrue(urlFromDb.contains("HTTPS://acme.de/"));
    assertTrue(urlFromDb.contains("ftp://mon-site.mondomaine/mon-repertoire"));
    assertTrue(urlFromDb.contains("http://apps.titellus.net/geonetwork/srv/api/records/da165110-88fd-11da-a88f-000d939bc5d8/attachments/thumbnail_s.gif"));
    assertTrue(urlFromDb.contains("http://apps.titellus.net/geonetwork/srv/api/records/da165110-88fd-11da-a88f-000d939bc5d8/attachments/thumbnail.gif"));
    assertTrue(urlFromDb.contains("http://www.fao.org/ag/AGL/aglw/aquastat/watresafrica/index.stm"));
    assertTrue(urlFromDb.contains("http://data.fao.org/maps/wms"));
    assertEquals(6, urlFromDb.size());
    SimpleJpaRepository metadataLinkRepository = new SimpleJpaRepository<MetadataLink, Integer>(MetadataLink.class, entityManager);
    List<MetadataLink> metadataLinkList = metadataLinkRepository.findAll();
    assertEquals(
            metadataLinkList.stream().map(x -> x.getLink().getId()).collect(Collectors.toSet()),
            linkRepository.findAll().stream().map(Link::getId).collect(Collectors.toSet()));
    assertEquals(
            metadataLinkList.stream().map(x -> x.getMetadataId()).collect(Collectors.toSet()),
            Collections.singleton(md.getId()));
}