@Test(expected = RuntimeException.class) public void testCreateClusterWithError() throws Exception { String someCluster = "someCluster"; String someCreatedBy = "someCreatedBy"; OpenClusterDTO clusterDTO = new OpenClusterDTO(); clusterDTO.setAppId(someAppId); clusterDTO.setName(someCluster); clusterDTO.setDataChangeCreatedBy(someCreatedBy); when(statusLine.getStatusCode()).thenReturn(400); clusterOpenApiService.createCluster(someEnv, clusterDTO); }
public OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO) { checkNotEmpty(openClusterDTO.getAppId(), "App id"); checkNotEmpty(env, "Env"); checkNotEmpty(openClusterDTO.getName(), "Cluster name"); checkNotEmpty(openClusterDTO.getDataChangeCreatedBy(), "Created by"); String path = String.format("envs/%s/apps/%s/clusters", escapePath(env), escapePath(openClusterDTO.getAppId())); try (CloseableHttpResponse response = post(path, openClusterDTO)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenClusterDTO.class); } catch (Throwable ex) { throw new RuntimeException(String .format("Create cluster: %s for appId: %s in env: %s failed", openClusterDTO.getName(), openClusterDTO.getAppId(), env), ex); } }
ClusterOpenApiService extends AbstractOpenApiService { public OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO) { checkNotEmpty(openClusterDTO.getAppId(), "App id"); checkNotEmpty(env, "Env"); checkNotEmpty(openClusterDTO.getName(), "Cluster name"); checkNotEmpty(openClusterDTO.getDataChangeCreatedBy(), "Created by"); String path = String.format("envs/%s/apps/%s/clusters", escapePath(env), escapePath(openClusterDTO.getAppId())); try (CloseableHttpResponse response = post(path, openClusterDTO)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenClusterDTO.class); } catch (Throwable ex) { throw new RuntimeException(String .format("Create cluster: %s for appId: %s in env: %s failed", openClusterDTO.getName(), openClusterDTO.getAppId(), env), ex); } } }
ClusterOpenApiService extends AbstractOpenApiService { public OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO) { checkNotEmpty(openClusterDTO.getAppId(), "App id"); checkNotEmpty(env, "Env"); checkNotEmpty(openClusterDTO.getName(), "Cluster name"); checkNotEmpty(openClusterDTO.getDataChangeCreatedBy(), "Created by"); String path = String.format("envs/%s/apps/%s/clusters", escapePath(env), escapePath(openClusterDTO.getAppId())); try (CloseableHttpResponse response = post(path, openClusterDTO)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenClusterDTO.class); } catch (Throwable ex) { throw new RuntimeException(String .format("Create cluster: %s for appId: %s in env: %s failed", openClusterDTO.getName(), openClusterDTO.getAppId(), env), ex); } } ClusterOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson); }
ClusterOpenApiService extends AbstractOpenApiService { public OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO) { checkNotEmpty(openClusterDTO.getAppId(), "App id"); checkNotEmpty(env, "Env"); checkNotEmpty(openClusterDTO.getName(), "Cluster name"); checkNotEmpty(openClusterDTO.getDataChangeCreatedBy(), "Created by"); String path = String.format("envs/%s/apps/%s/clusters", escapePath(env), escapePath(openClusterDTO.getAppId())); try (CloseableHttpResponse response = post(path, openClusterDTO)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenClusterDTO.class); } catch (Throwable ex) { throw new RuntimeException(String .format("Create cluster: %s for appId: %s in env: %s failed", openClusterDTO.getName(), openClusterDTO.getAppId(), env), ex); } } ClusterOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson); OpenClusterDTO getCluster(String appId, String env, String clusterName); OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO); }
ClusterOpenApiService extends AbstractOpenApiService { public OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO) { checkNotEmpty(openClusterDTO.getAppId(), "App id"); checkNotEmpty(env, "Env"); checkNotEmpty(openClusterDTO.getName(), "Cluster name"); checkNotEmpty(openClusterDTO.getDataChangeCreatedBy(), "Created by"); String path = String.format("envs/%s/apps/%s/clusters", escapePath(env), escapePath(openClusterDTO.getAppId())); try (CloseableHttpResponse response = post(path, openClusterDTO)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenClusterDTO.class); } catch (Throwable ex) { throw new RuntimeException(String .format("Create cluster: %s for appId: %s in env: %s failed", openClusterDTO.getName(), openClusterDTO.getAppId(), env), ex); } } ClusterOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson); OpenClusterDTO getCluster(String appId, String env, String clusterName); OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO);  }