CheckConnectivityController extends BaseFormJsonController { @Override protected void doPost(@Nonnull HttpServletRequest request, @Nonnull HttpServletResponse response, @Nonnull EditableNode responseNode) { Map<String, String> properties = DockerCloudUtils.extractTCPluginParams(request); String uri = properties.get(DockerCloudUtils.INSTANCE_URI); boolean useTLS = Boolean.parseBoolean(properties.get(DockerCloudUtils.USE_TLS)); Exception error = null; try { DockerClientConfig dockerConfig = new DockerClientConfig(new URI(uri), DockerCloudUtils.DOCKER_API_TARGET_VERSION) .usingTls(useTLS) .connectionPoolSize(1) .connectTimeout(Duration.ofSeconds(20)); DockerClient client = dockerClientFactory.createClientWithAPINegotiation(dockerConfig); DockerAPIVersion effectiveApiVersion = client.getApiVersion(); Node versionNode = client.getVersion(); Node infoNode = client.getInfo(); responseNode.put("version", versionNode); responseNode.put("info", infoNode); responseNode.getOrCreateObject("meta") .put("serverTime", System.currentTimeMillis()) .put("effectiveApiVersion", effectiveApiVersion.getVersionString()); } catch (Exception e) { error = e; } if (error != null) { String msg = error.getMessage(); responseNode .put("error", msg != null ? msg : "") .put("failureCause", DockerCloudUtils.getStackTrace(error)); } } CheckConnectivityController(@Nonnull PluginDescriptor pluginDescriptor,
                                       @Nonnull WebControllerManager manager);   CheckConnectivityController(@Nonnull PluginDescriptor pluginDescriptor,
                                @Nonnull WebControllerManager manager,
                                @Nonnull DockerClientFactory dockerClientFactory);  static final String PATH; }
@Test public void doPost() throws IOException { dockerClientFty.addConfigurator(dockerClient -> dockerClient.setSupportedAPIVersion(DockerCloudUtils.DOCKER_API_TARGET_VERSION)); CheckConnectivityController ctrl = createController(); TestHttpServletRequest request = new TestHttpServletRequest(); request.parameters(TestUtils.getSampleDockerConfigParams()); EditableNode responseNode = Node.EMPTY_OBJECT.editNode(); ctrl.doPost(request, new TestHttpServletResponse(), responseNode); assertThat(responseNode.getObject("version", null)).isNotNull(); TestDockerClient client = dockerClientFty.getClient(); Node version = client.getVersion(); EditableNode versionNode = responseNode.getObject("version"); assertThat(versionNode).isEqualTo(version); Node info = client.getInfo(); EditableNode infoNode = responseNode.getObject("info"); assertThat(infoNode).isEqualTo(info); EditableNode meta = responseNode.getObject("meta"); assertThat(meta.getAsLong("serverTime")) .isCloseTo(System.currentTimeMillis(), Offset.offset(400L)); assertThat(meta.getAsString("effectiveApiVersion")) .isEqualTo(client.getApiVersion().getVersionString()); }