@Test
public void testAddClip() throws Exception {

  TrackImpl videoTrack = new TrackImpl();
  videoTrack.setIdentifier("track-1");
  videoTrack.setFlavor(new MediaPackageElementFlavor("source", "presentation"));
  videoTrack.setURI(new URI("http://hostname/video.mp4"));
  videoTrack.addStream(new VideoStreamImpl());
  videoTrack.setDuration(1000000000000L);
  SmilResponse smilResponse = smilService.createNewSmil();
  smilResponse = smilService.addParallel(smilResponse.getSmil());
  SmilMediaContainer par = (SmilMediaContainer) smilResponse.getEntity();
  // add video track into parallel element
  smilResponse = smilService.addClip(smilResponse.getSmil(), par.getId(), videoTrack, 1000L, 1000000L);
  // logger.info(smilResponse.getSmil().toXML());
  SmilMediaObject media = null;
  for (SmilObject entity : smilResponse.getEntities()) {
    if (entity instanceof SmilMediaObject) {
      media = (SmilMediaObject) entity;
      break;
    }
  }
  assertNotNull(media);
  assertEquals(media.getId(), ((SmilMediaContainer) smilResponse.getSmil().getBody().getMediaElements().get(0))
          .getElements().get(0).getId());
  assertTrue(media instanceof SmilMediaVideoImpl);
  assertSame(((SmilMediaElement) media).getMediaType(), SmilMediaElement.MediaType.VIDEO);
  // 1000 milliseconds = 1 second
  assertEquals(1000L, ((SmilMediaElement) media).getClipBeginMS());
  // duration is 1000000 milliseconds = 1000 soconds
  // start + duration = 1s + 1000s = 1001s
  assertEquals(1001000L, ((SmilMediaElement) media).getClipEndMS());
  TrackImpl audioTrack = new TrackImpl();
  audioTrack.setIdentifier("track-2");
  audioTrack.setFlavor(new MediaPackageElementFlavor("source", "presenter"));
  audioTrack.setURI(new URI("http://hostname/audio.mp3"));
  audioTrack.addStream(new AudioStreamImpl());
  audioTrack.setDuration(1000000000000L);
  // add audio track into parallel element
  smilResponse = smilService.addClip(smilResponse.getSmil(), par.getId(), audioTrack, 1000L, 1000000L);
  // logger.info(smilResponse.getSmil().toXML());
  media = null;
  for (SmilObject entity : smilResponse.getEntities()) {
    if (entity instanceof SmilMediaObject) {
      media = (SmilMediaObject) entity;
      break;
    }
  }
  assertNotNull(media);
  assertEquals(media.getId(), ((SmilMediaContainer) smilResponse.getSmil().getBody().getMediaElements().get(0)).getElements().get(1).getId());
  assertTrue(media instanceof SmilMediaAudioImpl);
  assertSame(((SmilMediaElement) media).getMediaType(), SmilMediaElement.MediaType.AUDIO);
  // 1000 milliseconds = 1 second
  assertEquals(1000L, ((SmilMediaElement) media).getClipBeginMS());
  // duration is 1000000 milliseconds = 1000 soconds
  // start + duration = 1s + 1000s = 1001s
  assertEquals(1001000L, ((SmilMediaElement) media).getClipEndMS());
  // add new par
  smilResponse = smilService.addParallel(smilResponse.getSmil());
  par = (SmilMediaContainer) smilResponse.getEntity();
  // add tracks (as array) to par
  smilResponse = smilService.addClips(smilResponse.getSmil(), par.getId(),
          new Track[]{audioTrack, videoTrack}, 15000L, 1000L);
  // logger.info(smilResponse.getSmil().toXML());
  assertSame(2, smilResponse.getEntitiesCount());
  assertTrue(smilResponse.getEntities()[0] instanceof SmilMediaElement);
  // get audio element
  SmilMediaElement mediaElement = (SmilMediaElement) smilResponse.getEntities()[0];
  assertTrue(mediaElement.getMediaType() == SmilMediaElement.MediaType.AUDIO);
  // 15000ms = 15s
  assertEquals(15000L, mediaElement.getClipBeginMS());
  // start + duration = 15s + 1s = 16s
  assertEquals(16000L, mediaElement.getClipEndMS());
  // get video element
  mediaElement = (SmilMediaElement) smilResponse.getEntities()[1];
  assertTrue(mediaElement.getMediaType() == SmilMediaElement.MediaType.VIDEO);
  // 15000ms = 15s
  assertEquals(15000L, mediaElement.getClipBeginMS());
  // start + duration = 15s + 1s = 16s
  assertEquals(16000L, mediaElement.getClipEndMS());
}