Skip to content

Commit

Permalink
feat:
Browse files Browse the repository at this point in the history
1. remove @deprecated
2. add unit test
  • Loading branch information
youngzil committed Oct 17, 2024
1 parent ce0c403 commit ac6dc39
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
*/
public interface NamespaceOpenApiService {

/**
* @deprecated use {@link NamespaceOpenApiService#getNamespace(String, String, String, String, boolean)} instead
*/
default OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName) {
return getNamespace(appId, env, clusterName, namespaceName, true);
}
Expand All @@ -39,9 +36,6 @@ default OpenNamespaceDTO getNamespace(String appId, String env, String clusterNa
*/
OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName, boolean fillItemDetail);

/**
* @deprecated use {@link NamespaceOpenApiService#getNamespaces(String, String, String, boolean)} instead
*/
default List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName) {
return getNamespaces(appId, env, clusterName, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,8 @@ public List<OpenAppDTO> getAppsByIds(List<String> appIds) {
return appService.getAppsInfo(appIds);
}

/**
* @deprecated use {@link ApolloOpenApiClient#getNamespaces(String, String, String, boolean)} instead
*/
public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName) {
return namespaceService.getNamespaces(appId, env, clusterName, true);
return namespaceService.getNamespaces(appId, env, clusterName);
}

/**
Expand Down Expand Up @@ -132,11 +129,8 @@ public OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO) {
return clusterService.createCluster(env, openClusterDTO);
}

/**
* @deprecated use {@link ApolloOpenApiClient#getNamespace(String, String, String, String, boolean)} instead
*/
public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName) {
return namespaceService.getNamespace(appId, env, clusterName, namespaceName, true);
return namespaceService.getNamespace(appId, env, clusterName, namespaceName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class NamespaceOpenApiServiceTest extends AbstractOpenApiServiceTest {
private String someEnv;
private String someCluster;
private String someNamespace;
private boolean fillItemDetail;

@Override
@Before
Expand All @@ -47,6 +48,7 @@ public void setUp() throws Exception {
someEnv = "someEnv";
someCluster = "someCluster";
someNamespace = "someNamespace";
fillItemDetail = true;

StringEntity responseEntity = new StringEntity("{}");
when(someHttpResponse.getEntity()).thenReturn(responseEntity);
Expand All @@ -58,15 +60,33 @@ public void setUp() throws Exception {
public void testGetNamespace() throws Exception {
final ArgumentCaptor<HttpGet> request = ArgumentCaptor.forClass(HttpGet.class);

namespaceOpenApiService.getNamespace(someAppId, someEnv, someCluster, someNamespace, true);
namespaceOpenApiService.getNamespace(someAppId, someEnv, someCluster, someNamespace);

verify(httpClient, times(1)).execute(request.capture());

HttpGet get = request.getValue();

assertEquals(String
.format("%s/envs/%s/apps/%s/clusters/%s/namespaces/%s?fillItemDetail=%s", someBaseUrl, someEnv, someAppId, someCluster,
someNamespace, fillItemDetail), get.getURI().toString());
}

@Test
public void testGetNamespaceWithFillItemDetailFalse() throws Exception {

fillItemDetail = false;

final ArgumentCaptor<HttpGet> request = ArgumentCaptor.forClass(HttpGet.class);

namespaceOpenApiService.getNamespace(someAppId, someEnv, someCluster, someNamespace, fillItemDetail);

verify(httpClient, times(1)).execute(request.capture());

HttpGet get = request.getValue();

assertEquals(String
.format("%s/envs/%s/apps/%s/clusters/%s/namespaces/%s", someBaseUrl, someEnv, someAppId, someCluster,
someNamespace), get.getURI().toString());
.format("%s/envs/%s/apps/%s/clusters/%s/namespaces/%s?fillItemDetail=%s", someBaseUrl, someEnv, someAppId, someCluster,
someNamespace, fillItemDetail), get.getURI().toString());
}

@Test(expected = RuntimeException.class)
Expand All @@ -83,17 +103,38 @@ public void testGetNamespaces() throws Exception {

final ArgumentCaptor<HttpGet> request = ArgumentCaptor.forClass(HttpGet.class);

namespaceOpenApiService.getNamespaces(someAppId, someEnv, someCluster, true);
namespaceOpenApiService.getNamespaces(someAppId, someEnv, someCluster);

verify(httpClient, times(1)).execute(request.capture());

HttpGet get = request.getValue();

assertEquals(String
.format("%s/envs/%s/apps/%s/clusters/%s/namespaces", someBaseUrl, someEnv, someAppId, someCluster),
.format("%s/envs/%s/apps/%s/clusters/%s/namespaces?fillItemDetail=%s", someBaseUrl, someEnv, someAppId, someCluster, fillItemDetail),
get.getURI().toString());
}

@Test
public void testGetNamespacesWithFillItemDetailFalse() throws Exception {

fillItemDetail = false;

StringEntity responseEntity = new StringEntity("[]");
when(someHttpResponse.getEntity()).thenReturn(responseEntity);

final ArgumentCaptor<HttpGet> request = ArgumentCaptor.forClass(HttpGet.class);

namespaceOpenApiService.getNamespaces(someAppId, someEnv, someCluster, fillItemDetail);

verify(httpClient, times(1)).execute(request.capture());

HttpGet get = request.getValue();

assertEquals(String
.format("%s/envs/%s/apps/%s/clusters/%s/namespaces?fillItemDetail=%s", someBaseUrl, someEnv, someAppId, someCluster, fillItemDetail),
get.getURI().toString());
}

@Test(expected = RuntimeException.class)
public void testGetNamespacesWithError() throws Exception {
when(statusLine.getStatusCode()).thenReturn(404);
Expand Down

0 comments on commit ac6dc39

Please sign in to comment.