Skip to content

Commit

Permalink
fix:add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
youngzil committed Oct 27, 2024
1 parent fce6ad1 commit 9a02b6f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Apollo 2.4.0
* [Feature add limit for items count per namespace](https://github.com/apolloconfig/apollo/pull/5227)
* [Feature: Add ConfigService cache record stats function](https://github.com/apolloconfig/apollo/pull/5247)
* [RefreshAdminServerAddressTask supports dynamic configuration of time interval](https://github.com/apolloconfig/apollo/pull/5248)
* [Feature: openapi query namespace support not fill item ](https://github.com/apolloconfig/apollo/pull/5249)
* [Feature: openapi query namespace support not fill item](https://github.com/apolloconfig/apollo/pull/5249)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/15?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,24 @@ public void testDeleteEmptyNamespace() {

@Test
public void testLoadNamespaceBO() {
boolean fillItemDetail = true;
NamespaceBO namespaceBO = loadNamespaceBO(fillItemDetail);

List<String> namespaceKey2 = namespaceBO.getItems().stream().map(s -> s.getItem().getKey()).collect(Collectors.toList());
assertThat(namespaceBO.getItemModifiedCnt()).isEqualTo(2);
assertThat(namespaceBO.getItems().size()).isEqualTo(2);
assertThat(namespaceKey2).isEqualTo(Arrays.asList("k1", "k2"));
}

@Test
public void testLoadNamespaceBOWithoutItemDetail() {
boolean fillItemDetail = false;
NamespaceBO namespaceBO = loadNamespaceBO(fillItemDetail);

assertThat(namespaceBO.getItems().size()).isEqualTo(0);
}

private NamespaceBO loadNamespaceBO(boolean fillItemDetail) {
String branchName = "branch";
NamespaceDTO namespaceDTO = createNamespace(testAppId, branchName, testNamespaceName);
when(namespaceAPI.loadNamespace(any(), any(), any(), any())).thenReturn(namespaceDTO);
Expand Down Expand Up @@ -265,11 +283,49 @@ public void testLoadNamespaceBO() {
assertThat(namespaceBO1.getItems().size()).isEqualTo(3);
assertThat(namespaceKey1).isEqualTo(Arrays.asList("k1", "k2", "k3"));

NamespaceBO namespaceBO2 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, true, false);
List<String> namespaceKey2 = namespaceBO2.getItems().stream().map(s -> s.getItem().getKey()).collect(Collectors.toList());
assertThat(namespaceBO2.getItemModifiedCnt()).isEqualTo(2);
assertThat(namespaceBO2.getItems().size()).isEqualTo(2);
assertThat(namespaceKey2).isEqualTo(Arrays.asList("k1", "k2"));
return namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, fillItemDetail, false);
}

@Test
public void testFindPublicNamespaceForAssociatedNamespace() {
String branchName = "branch";
NamespaceDTO namespaceDTO = createNamespace(testAppId, branchName, testNamespaceName);
when(namespaceAPI.findPublicNamespaceForAssociatedNamespace(any(), any(), any(), any())).thenReturn(namespaceDTO);

ReleaseDTO releaseDTO = new ReleaseDTO();
releaseDTO.setConfigurations("{\"k1\":\"k1\",\"k2\":\"k2\", \"k3\":\"\"}");
when(releaseService.loadLatestRelease(any(), any(), any(), any())).thenReturn(releaseDTO);

List<ItemDTO> itemDTOList = Lists.newArrayList();
ItemDTO itemDTO1 = new ItemDTO();
itemDTO1.setId(1);
itemDTO1.setNamespaceId(1);
itemDTO1.setKey("k1");
itemDTO1.setValue(String.valueOf(1));
itemDTOList.add(itemDTO1);

ItemDTO itemDTO2 = new ItemDTO();
itemDTO2.setId(2);
itemDTO2.setNamespaceId(2);
itemDTO2.setKey("k2");
itemDTO2.setValue(String.valueOf(2));
itemDTOList.add(itemDTO2);
when(itemService.findItems(any(), any(), any(), any())).thenReturn(itemDTOList);

List<ItemDTO> deletedItemDTOList = Lists.newArrayList();
ItemDTO deletedItemDTO = new ItemDTO();
deletedItemDTO.setId(3);
deletedItemDTO.setNamespaceId(3);
deletedItemDTO.setKey("k3");
deletedItemDTOList.add(deletedItemDTO);
when(itemService.findDeletedItems(any(), any(), any(), any())).thenReturn(deletedItemDTOList);

NamespaceBO namespaceBO = namespaceService.findPublicNamespaceForAssociatedNamespace(testEnv, testAppId, testClusterName, testNamespaceName);

List<String> namespaceKey2 = namespaceBO.getItems().stream().map(s -> s.getItem().getKey()).collect(Collectors.toList());
assertThat(namespaceBO.getItemModifiedCnt()).isEqualTo(3);
assertThat(namespaceBO.getItems().size()).isEqualTo(3);
assertThat(namespaceKey2).isEqualTo(Arrays.asList("k1", "k2", "k3"));
}

private AppNamespace createAppNamespace(String appId, String name, boolean isPublic) {
Expand Down

0 comments on commit 9a02b6f

Please sign in to comment.