Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: openapi query namespace support not fill item #83

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Apollo Java 2.4.0

------------------
* [Fix the Cannot enhance @Configuration bean definition issue](https://github.com/apolloconfig/apollo-java/pull/82)
* [Feature openapi query namespace support not fill item](https://github.com/apolloconfig/apollo-java/pull/83)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/4?closed=1)
All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/4?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,25 @@
*/
public interface NamespaceOpenApiService {

OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName);
default OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName) {
return getNamespace(appId, env, clusterName, namespaceName, true);
}

List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName);
/**
* Retrieves a single namespace
* @since 2.4.0
*/
OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName, boolean fillItemDetail);
nobodyiam marked this conversation as resolved.
Show resolved Hide resolved

default List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName) {
return getNamespaces(appId, env, clusterName, true);
}

/**
* Retrieves a list namespaces
* @since 2.4.0
*/
List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName, boolean fillItemDetail);

OpenAppNamespaceDTO createAppNamespace(OpenAppNamespaceDTO appNamespaceDTO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,16 @@ public List<OpenAppDTO> getAppsByIds(List<String> appIds) {
return appService.getAppsInfo(appIds);
}

public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName) {
return namespaceService.getNamespaces(appId, env, clusterName);
}

/**
* Get the namespaces
* @since 2.4.0
*/
public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName) {
return namespaceService.getNamespaces(appId, env, clusterName);
public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName, boolean fillItemDetail) {
return namespaceService.getNamespaces(appId, env, clusterName, fillItemDetail);
}

/**
Expand All @@ -124,11 +129,16 @@ public OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO) {
return clusterService.createCluster(env, openClusterDTO);
}

public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName) {
return namespaceService.getNamespace(appId, env, clusterName, namespaceName);
}

/**
* Get the namespace
* @since 2.4.0
*/
public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName) {
return namespaceService.getNamespace(appId, env, clusterName, namespaceName);
public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName, boolean fillItemDetail) {
return namespaceService.getNamespace(appId, env, clusterName, namespaceName, fillItemDetail);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public NamespaceOpenApiService(CloseableHttpClient client, String baseUrl, Gson
}

@Override
public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName) {
public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName, boolean fillItemDetail) {
if (Strings.isNullOrEmpty(clusterName)) {
clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
}
Expand All @@ -58,6 +58,8 @@ public OpenNamespaceDTO getNamespace(String appId, String env, String clusterNam
.clustersPathVal(clusterName)
.namespacesPathVal(namespaceName);

pathBuilder.addParam("fillItemDetail", fillItemDetail);

try (CloseableHttpResponse response = get(pathBuilder)) {
return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenNamespaceDTO.class);
} catch (Throwable ex) {
Expand All @@ -68,7 +70,7 @@ public OpenNamespaceDTO getNamespace(String appId, String env, String clusterNam
}

@Override
public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName) {
public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName, boolean fillItemDetail) {
if (Strings.isNullOrEmpty(clusterName)) {
clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
}
Expand All @@ -82,6 +84,8 @@ public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clu
.clustersPathVal(clusterName)
.customResource("namespaces");

pathBuilder.addParam("fillItemDetail", fillItemDetail);

try (CloseableHttpResponse response = get(pathBuilder)) {
return gson.fromJson(EntityUtils.toString(response.getEntity()), OPEN_NAMESPACE_DTO_LIST_TYPE);
} catch (Throwable ex) {
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 @@ -56,49 +58,86 @@ public void setUp() throws Exception {

@Test
public void testGetNamespace() throws Exception {
verifyGetNamespace(true);
}

@Test
public void testGetNamespaceWithFillItemDetailFalse() throws Exception {
verifyGetNamespace(false);
}

private void verifyGetNamespace(boolean fillItemDetailValue) throws Exception {
fillItemDetail = fillItemDetailValue;

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

namespaceOpenApiService.getNamespace(someAppId, someEnv, someCluster, someNamespace);
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());
assertEquals(String.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)
public void testGetNamespaceWithError() throws Exception {
when(statusLine.getStatusCode()).thenReturn(404);

namespaceOpenApiService.getNamespace(someAppId, someEnv, someCluster, someNamespace);
namespaceOpenApiService.getNamespace(someAppId, someEnv, someCluster, someNamespace, true);
youngzil marked this conversation as resolved.
Show resolved Hide resolved
}

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

namespaceOpenApiService.getNamespace(someAppId, someEnv, someCluster, someNamespace, false);
}

@Test
public void testGetNamespaces() throws Exception {
verifyGetNamespace(true);
}

@Test
public void testGetNamespacesWithFillItemDetailFalse() throws Exception {
verifyGetNamespace(false);
}


private void verifyGetNamespaces(boolean fillItemDetailValue) throws Exception {
fillItemDetail = fillItemDetailValue;

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

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

namespaceOpenApiService.getNamespaces(someAppId, someEnv, someCluster);
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", someBaseUrl, someEnv, someAppId, someCluster),
get.getURI().toString());
.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);

namespaceOpenApiService.getNamespaces(someAppId, someEnv, someCluster);
namespaceOpenApiService.getNamespaces(someAppId, someEnv, someCluster, true);
nobodyiam marked this conversation as resolved.
Show resolved Hide resolved
}

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

namespaceOpenApiService.getNamespaces(someAppId, someEnv, someCluster, false);
}

@Test
Expand Down
Loading