ElasticsearchInstaller { public Single<String> download(String downloadUrl, String destPath) { return download(downloadUrl, destPath, true); } ElasticsearchInstaller(Vertx vertx); Single<String> download(String downloadUrl, String destPath); Single<String> download(String downloadUrl, String destPath,
      boolean strip);  }
@Test public void download(TestContext context) throws IOException { URL zipFile = this.getClass().getResource(ZIP_NAME); byte[] zipFileContents = IOUtils.toByteArray(zipFile); stubFor(get(urlEqualTo("/" + ZIP_NAME)) .willReturn(aResponse() .withBody(zipFileContents))); Vertx vertx = rule.vertx(); Async async = context.async(); File dest = folder.newFolder(); dest.delete(); new ElasticsearchInstaller(new io.vertx.rxjava.core.Vertx(vertx)) .download(downloadUrl, dest.getAbsolutePath()) .subscribe(path -> { verify(getRequestedFor(urlEqualTo("/" + ZIP_NAME))); context.assertEquals(dest.getAbsolutePath(), path); context.assertTrue(dest.exists()); context.assertTrue(new File(dest, "bin/elasticsearch").exists()); if (!SystemUtils.IS_OS_WINDOWS) { context.assertTrue(new File(dest, "bin/elasticsearch").canExecute()); } async.complete(); }, context::fail); }
@Test public void download500(TestContext context) throws IOException { stubFor(get(urlEqualTo("/" + ZIP_NAME)) .willReturn(aResponse() .withStatus(500))); Vertx vertx = rule.vertx(); Async async = context.async(); File dest = folder.newFolder(); dest.delete(); new ElasticsearchInstaller(new io.vertx.rxjava.core.Vertx(vertx)) .download(downloadUrl, dest.getAbsolutePath()) .subscribe(path -> context.fail("Download is expected to fail"), err -> { verify(getRequestedFor(urlEqualTo("/" + ZIP_NAME))); context.assertFalse(dest.exists()); async.complete(); }); }
@Test public void downloadInvalidArchive(TestContext context) throws IOException { stubFor(get(urlEqualTo("/" + ZIP_NAME)) .willReturn(aResponse() .withBody("foobar"))); Vertx vertx = rule.vertx(); Async async = context.async(); File dest = folder.newFolder(); dest.delete(); new ElasticsearchInstaller(new io.vertx.rxjava.core.Vertx(vertx)) .download(downloadUrl, dest.getAbsolutePath()) .subscribe(path -> context.fail("Download is expected to fail"), err -> { verify(getRequestedFor(urlEqualTo("/" + ZIP_NAME))); context.assertFalse(dest.exists()); async.complete(); }); }
@Test public void downloadRandomAndClose(TestContext context) throws IOException { stubFor(get(urlEqualTo("/" + ZIP_NAME)) .willReturn(aResponse() .withFault(Fault.RANDOM_DATA_THEN_CLOSE))); Vertx vertx = rule.vertx(); Async async = context.async(); File dest = folder.newFolder(); dest.delete(); new ElasticsearchInstaller(new io.vertx.rxjava.core.Vertx(vertx)) .download(downloadUrl, dest.getAbsolutePath()) .subscribe(path -> context.fail("Download is expected to fail"), err -> { verify(getRequestedFor(urlEqualTo("/" + ZIP_NAME))); context.assertFalse(dest.exists()); async.complete(); }); }