NamespaceOpenApiService extends AbstractOpenApiService { public OpenNamespaceLockDTO getNamespaceLock(String appId, String env, String clusterName, String namespaceName) { if (Strings.isNullOrEmpty(clusterName)) { clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT; } if (Strings.isNullOrEmpty(namespaceName)) { namespaceName = ConfigConsts.NAMESPACE_APPLICATION; } checkNotEmpty(appId, "App id"); checkNotEmpty(env, "Env"); String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/lock", escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName)); try (CloseableHttpResponse response = get(path)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenNamespaceLockDTO.class); } catch (Throwable ex) { throw new RuntimeException(String .format("Get namespace lock for appId: %s, cluster: %s, namespace: %s in env: %s failed", appId, clusterName, namespaceName, env), ex); } } NamespaceOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson); OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName); List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName); OpenAppNamespaceDTO createAppNamespace(OpenAppNamespaceDTO appNamespaceDTO); OpenNamespaceLockDTO getNamespaceLock(String appId, String env, String clusterName, String namespaceName);  }
@Test public void testGetNamespaceLock() throws Exception { final ArgumentCaptor<HttpGet> request = ArgumentCaptor.forClass(HttpGet.class); namespaceOpenApiService.getNamespaceLock(someAppId, someEnv, someCluster, someNamespace); verify(httpClient, times(1)).execute(request.capture()); HttpGet post = request.getValue(); assertEquals(String .format("%s/envs/%s/apps/%s/clusters/%s/namespaces/%s/lock", someBaseUrl, someEnv, someAppId, someCluster, someNamespace), post.getURI().toString()); }
@Test(expected = RuntimeException.class) public void testGetNamespaceLockWithError() throws Exception { when(statusLine.getStatusCode()).thenReturn(404); namespaceOpenApiService.getNamespaceLock(someAppId, someEnv, someCluster, someNamespace); }