@Test
  public void testDeriveImage() throws Throwable {
    ImageCreateSpec imageCreateSpec = new ImageCreateSpec();
    imageCreateSpec.setName("i1");
    imageCreateSpec.setReplicationType(ImageReplicationType.EAGER);

    ImageEntity vmImage =
        entityFactory.createImage(
            "image1", ImageState.READY, ImageReplicationType.EAGER, 100L, "n1", "v1", "n2", "v2");

    flushSession();

    String imageId = imageBackend.deriveImage(imageCreateSpec, vmImage).getId();

    flushSession();

    ImageEntity image = imageBackend.findById(imageId);
    assertThat(image.getName(), is(imageCreateSpec.getName()));
    assertThat(image.getReplicationType(), is(imageCreateSpec.getReplicationType()));
    assertThat(image.getState(), is(ImageState.CREATING));
    assertThat(image.getSize(), is(100L));
    assertThat(
        image.getImageSettingsMap(),
        is((Map<String, String>) ImmutableMap.of("n1", "v1", "n2", "v2")));
  }
    @Test(dataProvider = "vmCreateImageReplicationType")
    public void testPrepareVmCreateImage(ImageReplicationType replicationType) throws Throwable {
      ImageCreateSpec imageCreateSpec = new ImageCreateSpec();
      imageCreateSpec.setName("i1");
      imageCreateSpec.setReplicationType(replicationType);

      TaskEntity task = vmDcpBackend.prepareVmCreateImage(vmId, imageCreateSpec);

      assertThat(task, is(notNullValue()));
      assertThat(task.getState(), is(TaskEntity.State.QUEUED));
      assertThat(task.getSteps().size(), is(2));
      StepEntity step = task.getSteps().get(0);
      assertThat(
          step.getOperation(), is(com.vmware.photon.controller.api.Operation.CREATE_VM_IMAGE));
      assertThat(step.getTransientResourceEntities().size(), is(3));
      assertThat(step.getTransientResourceEntities(Vm.KIND).size(), is(1));
      assertThat(step.getTransientResourceEntities(Image.KIND).size(), is(2));

      assertThat(step.getTransientResourceEntities(Vm.KIND).get(0).getId(), is(vm.getId()));

      ImageEntity image = (ImageEntity) step.getTransientResourceEntities(ImageEntity.KIND).get(0);
      assertThat(image.getName(), is(imageCreateSpec.getName()));
      assertThat(image.getReplicationType(), is(imageCreateSpec.getReplicationType()));
      assertThat(image.getState(), is(ImageState.CREATING));
      assertThat(image.getSize(), is(createdImageState.size));
      assertThat(
          image.getImageSettingsMap(),
          is((Map<String, String>) ImmutableMap.of("n1", "v1", "n2", "v2")));

      ImageEntity vmImage =
          (ImageEntity) step.getTransientResourceEntities(ImageEntity.KIND).get(1);
      assertThat(vmImage.getId(), is(vm.getImageId()));

      step = task.getSteps().get(1);
      assertThat(
          step.getOperation(), is(com.vmware.photon.controller.api.Operation.REPLICATE_IMAGE));
    }