public void testMojoExecution() throws Exception {
    assertNotNull(mojo);
    mojo.execute();

    HttpClient client = HttpClientBuilder.create().build();

    HttpGet get = new HttpGet("http://localhost:" + elasticsearchNode.getHttpPort());

    final int connectionTimeout = 500; // millis
    RequestConfig requestConfig =
        RequestConfig.custom()
            .setConnectionRequestTimeout(connectionTimeout)
            .setConnectTimeout(connectionTimeout)
            .setSocketTimeout(connectionTimeout)
            .build();
    get.setConfig(requestConfig);

    try {
      client.execute(get);

      fail("The ES cluster should have been down by now");
    } catch (HttpHostConnectException | ConnectTimeoutException expected) {
    }

    assertTrue(elasticsearchNode.isClosed());
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    String dataPath = new File("target/test-harness/elasticsearch-data").getAbsolutePath();

    Map<ElasticsearchPort, Integer> esPorts = NetUtil.findOpenPortsForElasticsearch();
    int httpPort = esPorts.get(ElasticsearchPort.HTTP);
    int tcpPort = esPorts.get(ElasticsearchPort.TCP);

    elasticsearchNode = ElasticsearchNode.start(dataPath, httpPort, tcpPort);

    // Configure mojo with context
    File testPom = new File(getBasedir(), "src/test/resources/goals/stop/pom.xml");
    mojo = (StopElasticsearchNodeMojo) lookupMojo("stop", testPom);
    mojo.setPluginContext(new HashMap());
    mojo.getPluginContext().put("test", elasticsearchNode);
  }