@Test
public void testReplaceAndDistributeAcl() throws Exception {

  URI mpURI = LiveScheduleServiceImplTest.class.getResource("/live-mp.xml").toURI();
  MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder()
          .loadFromXml(mpURI.toURL().openStream());
  Job job = createJob(1L, "anything", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
          + "<attachment id=\"security-policy-episode\" type=\"security/xacml+episode\" xmlns=\"http://mediapackage.opencastproject.org\">"
          + "<mimetype>text/xml</mimetype><url>http://host/security-policy-episode.xml</url></attachment>");
  EasyMock.expect(downloadDistributionService.distribute(EasyMock.anyString(), EasyMock.anyObject(MediaPackage.class),
          EasyMock.anyObject(String.class), EasyMock.anyBoolean())).andReturn(job).once();
  EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job).anyTimes();
  replayServices();
  service.setDownloadDistributionService(downloadDistributionService);
  AccessControlList acl = new AccessControlList(new AccessControlEntry("user", "read", true));
  MediaPackage mp1 = service.replaceAndDistributeAcl(mp, acl);
  Attachment[] atts = mp1.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE);
  Assert.assertNotNull(atts);
  Assert.assertEquals(1, atts.length);
  Attachment att = atts[0];
  Assert.assertEquals("http://host/security-policy-episode.xml", att.getURI().toString());
  Assert.assertEquals("security/xacml+episode", att.getFlavor().toString());
  EasyMock.verify(downloadDistributionService);
}