AdminService { @Transactional public void deleteApp(App app, String operator) { String appId = app.getAppId(); logger.info("{} is deleting App:{}", operator, appId); List<Cluster> managedClusters = clusterService.findParentClusters(appId); if (Objects.nonNull(managedClusters)) { for (Cluster cluster : managedClusters) { clusterService.delete(cluster.getId(), operator); } } appNamespaceService.batchDelete(appId, operator); appService.delete(app.getId(), operator); } AdminService(
      final AppService appService,
      final @Lazy AppNamespaceService appNamespaceService,
      final @Lazy ClusterService clusterService,
      final @Lazy NamespaceService namespaceService); @Transactional App createNewApp(App app); @Transactional void deleteApp(App app, String operator);  }
@Test public void testDeleteApp() { String appId = "someAppId"; App app = new App(); app.setAppId(appId); app.setName("someAppName"); String owner = "someOwnerName"; app.setOwnerName(owner); app.setOwnerEmail("someOwnerName@ctrip.com"); app.setDataChangeCreatedBy(owner); app.setDataChangeLastModifiedBy(owner); app.setDataChangeCreatedTime(new Date()); app = adminService.createNewApp(app); Assert.assertEquals(appId, app.getAppId()); Assert.assertEquals(1, appNamespaceService.findByAppId(appId).size()); Assert.assertEquals(1, clusterService.findClusters(appId).size()); Assert.assertEquals(1, namespaceService.findNamespaces(appId, ConfigConsts.CLUSTER_NAME_DEFAULT).size()); adminService.deleteApp(app, owner); Assert.assertEquals(0, appNamespaceService.findByAppId(appId).size()); Assert.assertEquals(0, clusterService.findClusters(appId).size()); Assert .assertEquals(0, namespaceService.findByAppIdAndNamespaceName(appId, ConfigConsts.CLUSTER_NAME_DEFAULT).size()); }