-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Add edge case tests for NamespaceService.loadNamespaceBO #5574
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -293,6 +293,171 @@ public void testFindPublicNamespaceForAssociatedNamespace() { | |||||||||||||||||||||||||||||||
| assertThat(namespaceKey2).isEqualTo(Arrays.asList("k1", "k2", "k3")); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||
| public void testLoadNamespaceBOWithDeletedItems() { | ||||||||||||||||||||||||||||||||
| ReleaseDTO releaseDTO = createReleaseDTO(); | ||||||||||||||||||||||||||||||||
| when(releaseService.loadLatestRelease(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(releaseDTO); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| List<ItemDTO> itemDTOList = createItems(); | ||||||||||||||||||||||||||||||||
| when(itemService.findItems(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(itemDTOList); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| List<ItemDTO> deletedItemDTOList = Lists.newArrayList(); | ||||||||||||||||||||||||||||||||
| ItemDTO deletedItemDTO = new ItemDTO(); | ||||||||||||||||||||||||||||||||
| deletedItemDTO.setKey("deleted-key"); | ||||||||||||||||||||||||||||||||
| deletedItemDTOList.add(deletedItemDTO); | ||||||||||||||||||||||||||||||||
| when(itemService.findDeletedItems(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(deletedItemDTOList); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| when(namespaceAPI.loadNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(createNamespace(testAppId, testClusterName, testNamespaceName)); | ||||||||||||||||||||||||||||||||
| when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(createAppNamespace(testAppId, testNamespaceName, false)); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, true); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| assertNotNull(namespaceBO); | ||||||||||||||||||||||||||||||||
| assertEquals(testAppId, namespaceBO.getBaseInfo().getAppId()); | ||||||||||||||||||||||||||||||||
| assertEquals(testClusterName, namespaceBO.getBaseInfo().getClusterName()); | ||||||||||||||||||||||||||||||||
| assertEquals(testNamespaceName, namespaceBO.getBaseInfo().getNamespaceName()); | ||||||||||||||||||||||||||||||||
| assertEquals(3, namespaceBO.getItems().size()); | ||||||||||||||||||||||||||||||||
| verify(itemService, times(1)).findDeletedItems(testAppId, testEnv, testClusterName, testNamespaceName); | ||||||||||||||||||||||||||||||||
| verify(additionalUserInfoEnrichService, times(1)).enrichAdditionalUserInfo(any(), any()); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||
| public void testLoadNamespaceBOWithoutDeletedItems() { | ||||||||||||||||||||||||||||||||
| ReleaseDTO releaseDTO = createReleaseDTO(); | ||||||||||||||||||||||||||||||||
| when(releaseService.loadLatestRelease(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(releaseDTO); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| List<ItemDTO> itemDTOList = createItems(); | ||||||||||||||||||||||||||||||||
| when(itemService.findItems(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(itemDTOList); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| when(namespaceAPI.loadNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(createNamespace(testAppId, testClusterName, testNamespaceName)); | ||||||||||||||||||||||||||||||||
| when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(createAppNamespace(testAppId, testNamespaceName, false)); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, false); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| assertNotNull(namespaceBO); | ||||||||||||||||||||||||||||||||
| assertEquals(testAppId, namespaceBO.getBaseInfo().getAppId()); | ||||||||||||||||||||||||||||||||
| assertEquals(testClusterName, namespaceBO.getBaseInfo().getClusterName()); | ||||||||||||||||||||||||||||||||
| assertEquals(testNamespaceName, namespaceBO.getBaseInfo().getNamespaceName()); | ||||||||||||||||||||||||||||||||
| assertEquals(2, namespaceBO.getItems().size()); | ||||||||||||||||||||||||||||||||
| verify(itemService, times(0)).findDeletedItems(any(), any(), any(), any()); | ||||||||||||||||||||||||||||||||
| verify(additionalUserInfoEnrichService, times(1)).enrichAdditionalUserInfo(any(), any()); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||
| public void testLoadNamespaceBONamespaceNotFound() { | ||||||||||||||||||||||||||||||||
| when(namespaceAPI.loadNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(null); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| assertThatExceptionOfType(BadRequestException.class) | ||||||||||||||||||||||||||||||||
| .isThrownBy(() -> namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName)); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||
| public void testLoadNamespaceBONoLatestRelease() { | ||||||||||||||||||||||||||||||||
| when(namespaceAPI.loadNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(createNamespace(testAppId, testClusterName, testNamespaceName)); | ||||||||||||||||||||||||||||||||
| when(releaseService.loadLatestRelease(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(null); | ||||||||||||||||||||||||||||||||
| when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(createAppNamespace(testAppId, testNamespaceName, false)); | ||||||||||||||||||||||||||||||||
| when(itemService.findItems(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(createItems()); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName); | ||||||||||||||||||||||||||||||||
|
Comment on lines
+359
to
+365
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stub deleted items or disable them in these tests. These methods call the 4-arg 🔧 Minimal fix- NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName);
+ NamespaceBO namespaceBO =
+ namespaceService.loadNamespaceBO(
+ testAppId, testEnv, testClusterName, testNamespaceName, true, false);Apply the same change in:
If you want to keep exercising the default overload instead, stub Also applies to: 394-405, 413-438 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| assertNotNull(namespaceBO); | ||||||||||||||||||||||||||||||||
| assertEquals(2, namespaceBO.getItems().size()); | ||||||||||||||||||||||||||||||||
| assertTrue(namespaceBO.getItems().get(0).isModified()); | ||||||||||||||||||||||||||||||||
| assertTrue(namespaceBO.getItems().get(1).isModified()); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||
| public void testLoadNamespaceBONoItems() { | ||||||||||||||||||||||||||||||||
| ReleaseDTO releaseDTO = createReleaseDTO(); | ||||||||||||||||||||||||||||||||
| when(releaseService.loadLatestRelease(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(releaseDTO); | ||||||||||||||||||||||||||||||||
| when(namespaceAPI.loadNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(createNamespace(testAppId, testClusterName, testNamespaceName)); | ||||||||||||||||||||||||||||||||
| when(itemService.findItems(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(Lists.newArrayList()); | ||||||||||||||||||||||||||||||||
| when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(createAppNamespace(testAppId, testNamespaceName, false)); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| ItemDTO deletedItemDTO = new ItemDTO(); | ||||||||||||||||||||||||||||||||
| deletedItemDTO.setKey("deleted-key"); | ||||||||||||||||||||||||||||||||
| when(itemService.findDeletedItems(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(Lists.newArrayList(deletedItemDTO)); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| assertNotNull(namespaceBO); | ||||||||||||||||||||||||||||||||
| assertEquals(3, namespaceBO.getItems().size()); | ||||||||||||||||||||||||||||||||
| assertTrue(namespaceBO.getItems().get(0).isDeleted()); | ||||||||||||||||||||||||||||||||
| assertEquals("k1", namespaceBO.getItems().get(0).getItem().getKey()); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+405
to
+409
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fragile assertion depends on non-deterministic iteration order. The assertion at line 386 ( 🔧 Proposed fix to use order-independent assertion assertNotNull(namespaceBO);
assertEquals(3, namespaceBO.getItems().size());
- assertTrue(namespaceBO.getItems().get(0).isDeleted());
- assertEquals("k1", namespaceBO.getItems().get(0).getItem().getKey());
+ // All items should be marked as deleted since items list is empty
+ assertTrue(namespaceBO.getItems().stream().allMatch(item -> item.isDeleted()));
+ // Verify expected keys are present (order is non-deterministic)
+ List<String> keys = namespaceBO.getItems().stream()
+ .map(item -> item.getItem().getKey())
+ .collect(Collectors.toList());
+ assertThat(keys).asList().containsExactlyInAnyOrder("k1", "k2", "k3");📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: build[error] 383-383: Compilation error: cannot find symbol method assertNotNull(com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO). [error] 385-385: Compilation error: cannot find symbol method assertTrue(boolean). 🪛 GitHub Actions: portal-login-e2e[error] 383-383: Cannot find symbol: method assertNotNull(NamespaceBO). [error] 385-385: Cannot find symbol: method assertTrue(boolean). 🪛 GitHub Actions: portal-ui-e2e[error] 385-385: Cannot resolve symbol: NamespaceBO in assertion context (NamespaceServiceTest). [error] 385-385: Cannot resolve symbol: assertTrue(boolean) in test code. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||
| public void testLoadNamespaceBOWithPublicNamespace() { | ||||||||||||||||||||||||||||||||
| AppNamespace publicAppNamespace = createAppNamespace("public-app", testNamespaceName, true); | ||||||||||||||||||||||||||||||||
| when(namespaceAPI.loadNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(createNamespace(testAppId, testClusterName, testNamespaceName)); | ||||||||||||||||||||||||||||||||
| when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(null); | ||||||||||||||||||||||||||||||||
| when(appNamespaceService.findPublicAppNamespace(testNamespaceName)).thenReturn(publicAppNamespace); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| ReleaseDTO releaseDTO = createReleaseDTO(); | ||||||||||||||||||||||||||||||||
| when(releaseService.loadLatestRelease(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(releaseDTO); | ||||||||||||||||||||||||||||||||
| when(itemService.findItems(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(createItems()); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| assertNotNull(namespaceBO); | ||||||||||||||||||||||||||||||||
| assertTrue(namespaceBO.isPublic()); | ||||||||||||||||||||||||||||||||
| assertEquals("public-app", namespaceBO.getParentAppId()); | ||||||||||||||||||||||||||||||||
| verify(appNamespaceService, times(1)).findPublicAppNamespace(testNamespaceName); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||
| public void testLoadNamespaceBOWithPrivateNamespace() { | ||||||||||||||||||||||||||||||||
| AppNamespace privateAppNamespace = createAppNamespace(testAppId, testNamespaceName, false); | ||||||||||||||||||||||||||||||||
| when(namespaceAPI.loadNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(createNamespace(testAppId, testClusterName, testNamespaceName)); | ||||||||||||||||||||||||||||||||
| when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(privateAppNamespace); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| ReleaseDTO releaseDTO = createReleaseDTO(); | ||||||||||||||||||||||||||||||||
| when(releaseService.loadLatestRelease(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(releaseDTO); | ||||||||||||||||||||||||||||||||
| when(itemService.findItems(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(createItems()); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| assertNotNull(namespaceBO); | ||||||||||||||||||||||||||||||||
| assertEquals(testAppId, namespaceBO.getParentAppId()); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||
| public void testLoadNamespaceBOWithDirtyAppNamespace() { | ||||||||||||||||||||||||||||||||
| when(namespaceAPI.loadNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(createNamespace(testAppId, testClusterName, testNamespaceName)); | ||||||||||||||||||||||||||||||||
| when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(null); | ||||||||||||||||||||||||||||||||
| when(appNamespaceService.findPublicAppNamespace(testNamespaceName)).thenReturn(null); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| ReleaseDTO releaseDTO = createReleaseDTO(); | ||||||||||||||||||||||||||||||||
| when(releaseService.loadLatestRelease(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(releaseDTO); | ||||||||||||||||||||||||||||||||
| when(itemService.findItems(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(createItems()); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| assertNotNull(namespaceBO); | ||||||||||||||||||||||||||||||||
| assertTrue(namespaceBO.isPublic()); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||
| public void testLoadNamespaceBOItemModifiedCountCalculation() { | ||||||||||||||||||||||||||||||||
| ReleaseDTO releaseDTO = createReleaseDTO(); | ||||||||||||||||||||||||||||||||
| when(namespaceAPI.loadNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(createNamespace(testAppId, testClusterName, testNamespaceName)); | ||||||||||||||||||||||||||||||||
| when(releaseService.loadLatestRelease(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(releaseDTO); | ||||||||||||||||||||||||||||||||
| when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(createAppNamespace(testAppId, testNamespaceName, false)); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| List<ItemDTO> itemDTOList = createItems(); | ||||||||||||||||||||||||||||||||
| when(itemService.findItems(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(itemDTOList); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| ItemDTO deletedItemDTO = new ItemDTO(); | ||||||||||||||||||||||||||||||||
| deletedItemDTO.setKey("deleted-key"); | ||||||||||||||||||||||||||||||||
| when(itemService.findDeletedItems(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(Lists.newArrayList(deletedItemDTO)); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, true); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| assertNotNull(namespaceBO); | ||||||||||||||||||||||||||||||||
| assertEquals(3, namespaceBO.getItemModifiedCnt()); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| private ReleaseDTO createReleaseDTO() { | ||||||||||||||||||||||||||||||||
| ReleaseDTO releaseDTO = new ReleaseDTO(); | ||||||||||||||||||||||||||||||||
| releaseDTO.setConfigurations("{\"k1\":\"k1\",\"k2\":\"k2\", \"k3\":\"\"}"); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.