@Test
public void testAddAndDistributeElements() throws Exception {

  URI catalogURI = LiveScheduleServiceImplTest.class.getResource("/series.xml").toURI();
  DublinCoreCatalog seriesDC = DublinCores.read(catalogURI.toURL().openStream());
  EasyMock.expect(seriesService.getSeries(SERIES_ID)).andReturn(seriesDC).anyTimes();
  Job job = createJob(1L, "anything", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
          + "<catalog id=\"9ad6ebcb-b414-4b15-ab62-5e5ddede447e\" type=\"dublincore/episode\" xmlns=\"http://mediapackage.opencastproject.org\">"
          + "<mimetype>text/xml</mimetype>"
          + "<url>http://10.10.10.50/static/mh_default_org/engage-live/episode.xml</url></catalog>"
          + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
          + "<catalog id=\"23113662-1a84-457a-85d5-0b3e32d2413a\" type=\"dublincore/series\" xmlns=\"http://mediapackage.opencastproject.org\">"
          + "<mimetype>text/xml</mimetype>"
          + "<url>http://10.10.10.50/static/mh_default_org/engage-live/series.xml</url></catalog>"
          + "###<?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://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml</url></attachment>");
  EasyMock.expect(downloadDistributionService.distribute(EasyMock.anyString(), EasyMock.anyObject(MediaPackage.class),
          EasyMock.anyObject(Set.class), EasyMock.anyBoolean())).andReturn(job).once();
  EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job).anyTimes();
  URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp.xml").toURI();
  MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder()
          .loadFromXml(mpURI.toURL().openStream());
  replayServices();
  Snapshot s = EasyMock.createNiceMock(Snapshot.class);
  EasyMock.expect(s.getMediaPackage()).andReturn(mp);
  EasyMock.replay(s);
  service.setDownloadDistributionService(downloadDistributionService);
  MediaPackage mp1 = service.addAndDistributeElements(s);
  Catalog[] catalogs = mp1.getCatalogs(MediaPackageElements.EPISODE);
  Assert.assertNotNull(catalogs);
  Assert.assertEquals(1, catalogs.length);
  Catalog catalog = catalogs[0];
  Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/episode.xml",
          catalog.getURI().toString());
  Assert.assertEquals("dublincore/episode", catalog.getFlavor().toString());
  catalogs = mp1.getCatalogs(MediaPackageElements.SERIES);
  Assert.assertNotNull(catalogs);
  Assert.assertEquals(1, catalogs.length);
  catalog = catalogs[0];
  Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/series.xml", catalog.getURI().toString());
  Assert.assertEquals("dublincore/series", catalog.getFlavor().toString());
  Attachment[] atts = mp1.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE);
  Assert.assertNotNull(atts);
  Assert.assertEquals(1, atts.length);
  Attachment att = atts[0];
  Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml",
          att.getURI().toString());
  Assert.assertEquals("security/xacml+episode", att.getFlavor().toString());
  EasyMock.verify(downloadDistributionService, workspace);
}