DockerModuleHandle implements ModuleHandle { String getCreateContainerDoc(int exposedPort) { JsonObject j = new JsonObject(); j.put("AttachStdin", Boolean.FALSE); j.put("AttachStdout", Boolean.TRUE); j.put("AttachStderr", Boolean.TRUE); j.put("StopSignal", "SIGTERM"); if (env != null) { JsonArray a = new JsonArray(); for (EnvEntry nv : env) { a.add(nv.getName() + "=" + nv.getValue()); } j.put("env", a); } j.put("Image", image); JsonObject hp = new JsonObject().put("HostPort", Integer.toString(hostPort)); JsonArray ep = new JsonArray().add(hp); JsonObject pb = new JsonObject(); pb.put(exposedPort + "/tcp", ep); JsonObject hc = new JsonObject(); hc.put("PortBindings", pb); hc.put("PublishAllPorts", Boolean.FALSE); j.put("HostConfig", hc); if (this.cmd != null && this.cmd.length > 0) { JsonArray a = new JsonArray(); for (String cmdElement : cmd) { a.add(cmdElement); } j.put("Cmd", a); } if (dockerArgs != null) { JsonObject dockerArgsJson = new JsonObject(dockerArgs.properties()); VariableSubstitutor.replace(dockerArgsJson, Integer.toString(hostPort), containerHost); j.mergeIn(dockerArgsJson); } String doc = j.encodePrettily(); logger.info("createContainer {}", (Supplier<String>) () -> { if (! j.containsKey("env")) { return doc; } j.put("env", new JsonArray().add("...")); return j.encodePrettily(); }); return doc; } DockerModuleHandle(Vertx vertx, LaunchDescriptor desc,
                     String id, Ports ports, String containerHost, int port, JsonObject config,
                     Logger logger);   DockerModuleHandle(Vertx vertx, LaunchDescriptor desc,
      String id, Ports ports, String containerHost, int port, JsonObject config); @Override Future<Void> start(); @Override Future<Void> stop();  }
@Test public void testGetCreateContainerDoc() { LaunchDescriptor launchDescriptor = new LaunchDescriptor(); launchDescriptor.setEnv(new EnvEntry [] { new EnvEntry("username", "foobar"), new EnvEntry("password", "uvwxyz%p%c")}); launchDescriptor.setDockerArgs(new AnyDescriptor().set("%p", "%p")); Logger logger = mock(Logger.class); StringBuilder logMessage = new StringBuilder(); doAnswer(AdditionalAnswers.answerVoid( (String msg, Supplier<Object> supplier) -> logMessage.append(msg).append(supplier.get()))) .when(logger).info(anyString(), any(Supplier.class)); DockerModuleHandle dockerModuleHandle = new DockerModuleHandle(Vertx.vertx(), launchDescriptor, "mod-users-5.0.0-SNAPSHOT", new Ports(9232, 9233), "localhost", 9232, new JsonObject(), logger); assertThat(dockerModuleHandle.getCreateContainerDoc(8000)) .contains("8000/tcp") .contains("\"%p\" : \"9232\"") .contains("foobar") .contains("uvwxyz%p%c"); assertThat(logMessage.toString()) .contains("8000/tcp") .contains("\"%p\" : \"9232\"") .doesNotContain("foobar") .doesNotContain("uvwxyz"); }