ItemOpenApiService extends AbstractOpenApiService { public void removeItem(String appId, String env, String clusterName, String namespaceName, String key, String operator) { if (Strings.isNullOrEmpty(clusterName)) { clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT; } if (Strings.isNullOrEmpty(namespaceName)) { namespaceName = ConfigConsts.NAMESPACE_APPLICATION; } checkNotEmpty(appId, "App id"); checkNotEmpty(env, "Env"); checkNotEmpty(key, "Item key"); checkNotEmpty(operator, "Operator"); String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s?operator=%s", escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName), escapePath(key), escapeParam(operator)); try (CloseableHttpResponse ignored = delete(path)) { } catch (Throwable ex) { throw new RuntimeException(String .format("Remove item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", key, appId, clusterName, namespaceName, env), ex); } } ItemOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson); OpenItemDTO getItem(String appId, String env, String clusterName, String namespaceName, String key); OpenItemDTO createItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO); void updateItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO); void createOrUpdateItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO); void removeItem(String appId, String env, String clusterName, String namespaceName, String key, String operator);  }
@Test public void testRemoveItem() throws Exception { String someKey = "someKey"; String someOperator = "someOperator"; final ArgumentCaptor<HttpDelete> request = ArgumentCaptor.forClass(HttpDelete.class); itemOpenApiService.removeItem(someAppId, someEnv, someCluster, someNamespace, someKey, someOperator); verify(httpClient, times(1)).execute(request.capture()); HttpDelete delete = request.getValue(); assertEquals(String .format("%s/envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s?operator=%s", someBaseUrl, someEnv, someAppId, someCluster, someNamespace, someKey, someOperator), delete.getURI().toString()); }
@Test(expected = RuntimeException.class) public void testRemoveItemWithError() throws Exception { String someKey = "someKey"; String someOperator = "someOperator"; when(statusLine.getStatusCode()).thenReturn(404); itemOpenApiService.removeItem(someAppId, someEnv, someCluster, someNamespace, someKey, someOperator); }