ClusterOpenApiService extends AbstractOpenApiService { public OpenClusterDTO getCluster(String appId, String env, String clusterName) { checkNotEmpty(appId, "App id"); checkNotEmpty(env, "Env"); if (Strings.isNullOrEmpty(clusterName)) { clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT; } String path = String.format("envs/%s/apps/%s/clusters/%s", escapePath(env), escapePath(appId), escapePath(clusterName)); try (CloseableHttpResponse response = get(path)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenClusterDTO.class); } catch (Throwable ex) { throw new RuntimeException(String .format("Get cluster for appId: %s, cluster: %s in env: %s failed", appId, clusterName, env), ex); } } ClusterOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson); OpenClusterDTO getCluster(String appId, String env, String clusterName); OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO);  }
@Test public void testGetCluster() throws Exception { String someCluster = "someCluster"; final ArgumentCaptor<HttpGet> request = ArgumentCaptor.forClass(HttpGet.class); clusterOpenApiService.getCluster(someAppId, someEnv, someCluster); verify(httpClient, times(1)).execute(request.capture()); HttpGet get = request.getValue(); assertEquals(String .format("%s/envs/%s/apps/%s/clusters/%s", someBaseUrl, someEnv, someAppId, someCluster), get.getURI().toString()); }
@Test(expected = RuntimeException.class) public void testGetClusterWithError() throws Exception { String someCluster = "someCluster"; when(statusLine.getStatusCode()).thenReturn(404); clusterOpenApiService.getCluster(someAppId, someEnv, someCluster); }