@Test
public void testHLSDistribution() throws Exception {

  // Distribute only some of the elements in the mediapackage
  mp = MediaPackageParser
          .getFromXml(IOUtils.toString(getClass().getResourceAsStream("/hls_1_var_mediapackage.xml"), "UTF-8"));
  String[] elementIds = { "master", "variant", "segments", "dublincore", "mpeg7" };
  Job job = service.distribute("engage-player", mp, Arrays.stream(elementIds).collect(Collectors.toSet()), true);
  JobBarrier jobBarrier = new JobBarrier(null, serviceRegistry, 500, job);
  jobBarrier.waitForJobs();
  File mpDir = new File(distributionRoot,
          PathSupport.path(defaultOrganization.getId(), "engage-player", mp.getIdentifier().toString()));
  Assert.assertTrue(mpDir.exists());
  File mediaDir = new File(mpDir, "master");
  File variantDir = new File(mpDir, "variant");
  File segmentDir = new File(mpDir, "segments");
  File metadataDir = new File(mpDir, "dublincore");
  File attachmentsDir = new File(mpDir, "mpeg7");
  Assert.assertTrue(mediaDir.exists());
  Assert.assertTrue(variantDir.exists());
  Assert.assertTrue(segmentDir.exists());
  Assert.assertTrue(metadataDir.exists());
  Assert.assertTrue(attachmentsDir.exists());
  Assert.assertTrue(new File(mediaDir, "master.m3u8").exists()); // the filenames are changed to reflect the element
                                                                 // ID
  Assert.assertTrue(new File(variantDir, "variant_0.m3u8").exists()); // the filenames are changed to reflect the
                                                                    // element ID
  Assert.assertTrue(new File(segmentDir, "file_0.mp4").exists()); // the filenames are changed to reflect the element
                                                                  // ID
  Assert.assertTrue(new File(metadataDir, "dublincore.xml").exists());
  Assert.assertTrue(new File(attachmentsDir, "mpeg7.xml").exists()); // the filenames are changed to reflect the
                                                                     // element ID
  Assert.assertFalse(new File(metadataDir, "mpeg7.xml").exists());
  Assert.assertFalse(new File(attachmentsDir, "attachment.txt").exists());
  File playlist = new File(mediaDir, "master.m3u8");
  logger.info("Reading playlist " + playlist);
  Optional<String> hasRelativeLink = Files.lines(playlist.toPath())
          .filter(s -> s.contains("../variant/variant_0.m3u8"))
          .findFirst();
  Assert.assertTrue(hasRelativeLink.isPresent());
  playlist = new File(variantDir, "variant_0.m3u8");
  hasRelativeLink = Files.lines(playlist.toPath()).filter(s -> s.contains("../segments/file_0.mp4"))
          .findFirst();
  Assert.assertTrue(hasRelativeLink.isPresent());
}