/**
   * Creates, checks and terminates a Docker container.
   *
   * @param targetProperties the target properties
   * @throws Exception
   */
  private void testCreateAndTerminateVM(Map<String, String> targetProperties) throws Exception {

    DockerHandler target = new DockerHandler();
    Instance scopedInstance = new Instance("test-596598515");
    String path = InstanceHelpers.computeInstancePath(scopedInstance);

    TargetHandlerParameters parameters =
        new TargetHandlerParameters()
            .targetProperties(targetProperties)
            .messagingProperties(this.msgCfg)
            .applicationName("roboconf")
            .domain("my-domain")
            .scopedInstancePath(path);

    try {
      target.start();
      String containerId = target.createMachine(parameters);
      Assert.assertNotNull(containerId);
      Assert.assertNull(scopedInstance.data.get(Instance.MACHINE_ID));

      // DockerMachineConfigurator is implemented in such a way that it runs only
      // once when the image already exists. However, we must wait for the thread pool
      // executor to pick up the configurator.
      target.configureMachine(parameters, containerId, scopedInstance);

      // Be careful, the Docker target changes the machine ID
      containerId =
          DockerTestUtils.waitForMachineId(
              containerId, scopedInstance.data, DockerTestUtils.DOCKER_CONFIGURE_TIMEOUT);

      Assert.assertNotNull(containerId);

      // Check the machine is running
      Assert.assertTrue(target.isMachineRunning(parameters, containerId));

      // Just for verification, try to terminate an invalid container
      target.terminateMachine(parameters, "invalid identifier");
      Assert.assertTrue(target.isMachineRunning(parameters, containerId));

      // Terminate the container
      target.terminateMachine(parameters, containerId);
      Assert.assertFalse(target.isMachineRunning(parameters, containerId));

    } finally {
      target.stop();
    }
  }
  @Before
  public void checkDockerIsInstalled() throws Exception {

    Assume.assumeTrue(this.dockerIsInstalled);
    try {
      DockerTestUtils.checkDockerIsInstalled();
      prepareDockerTest();

    } catch (Exception e) {
      e.printStackTrace();
      this.logger.warning("Tests are skipped because Docker is not installed or misconfigured.");
      Utils.logException(this.logger, e);

      this.dockerIsInstalled = false;
      Assume.assumeNoException(e);
    }
  }