use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class AppNamespaceService method deleteAppNamespace.
@Transactional
public AppNamespace deleteAppNamespace(String appId, String namespaceName) {
AppNamespace appNamespace = appNamespaceRepository.findByAppIdAndName(appId, namespaceName);
if (appNamespace == null) {
throw new BadRequestException(String.format("AppNamespace not exists. AppId = %s, NamespaceName = %s", appId, namespaceName));
}
String operator = userInfoHolder.getUser().getUserId();
// this operator is passed to com.ctrip.framework.apollo.portal.listener.DeletionListener.onAppNamespaceDeletionEvent
appNamespace.setDataChangeLastModifiedBy(operator);
// delete app namespace in portal db
appNamespaceRepository.delete(appId, namespaceName, operator);
// delete Permission and Role related data
rolePermissionService.deleteRolePermissionsByAppIdAndNamespace(appId, namespaceName, operator);
return appNamespace;
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class NamespaceServiceTest method testDeleteNamespaceBranchHasInstance.
@Test(expected = BadRequestException.class)
public void testDeleteNamespaceBranchHasInstance() {
AppNamespace publicNamespace = createAppNamespace(testAppId, testNamespaceName, true);
String branchName = "branch";
NamespaceDTO branch = createNamespace(testAppId, branchName, testNamespaceName);
when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(publicNamespace);
when(instanceService.getInstanceCountByNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(0);
when(branchService.findBranchBaseInfo(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(branch);
when(instanceService.getInstanceCountByNamespace(testAppId, testEnv, branchName, testNamespaceName)).thenReturn(10);
namespaceService.deleteNamespace(testAppId, testEnv, testClusterName, testNamespaceName);
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class NamespaceServiceTest method testDeletePrivateNamespace.
@Test
public void testDeletePrivateNamespace() {
String operator = "user";
AppNamespace privateNamespace = createAppNamespace(testAppId, testNamespaceName, false);
when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(privateNamespace);
when(userInfoHolder.getUser()).thenReturn(createUser(operator));
namespaceService.deleteNamespace(testAppId, testEnv, testClusterName, testNamespaceName);
verify(namespaceAPI, times(1)).deleteNamespace(testEnv, testAppId, testClusterName, testNamespaceName, operator);
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class NamespaceServiceTest method testDeleteNamespaceHasInstance.
@Test(expected = BadRequestException.class)
public void testDeleteNamespaceHasInstance() {
AppNamespace publicNamespace = createAppNamespace(testAppId, testNamespaceName, true);
when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(publicNamespace);
when(instanceService.getInstanceCountByNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(10);
namespaceService.deleteNamespace(testAppId, testEnv, testClusterName, testNamespaceName);
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class NamespaceServiceTest method testDeleteNamespaceWithAssociatedNamespace.
@Test(expected = BadRequestException.class)
public void testDeleteNamespaceWithAssociatedNamespace() {
AppNamespace publicNamespace = createAppNamespace(testAppId, testNamespaceName, true);
String branchName = "branch";
NamespaceDTO branch = createNamespace(testAppId, branchName, testNamespaceName);
when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(publicNamespace);
when(instanceService.getInstanceCountByNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(0);
when(branchService.findBranchBaseInfo(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(branch);
when(instanceService.getInstanceCountByNamespace(testAppId, testEnv, branchName, testNamespaceName)).thenReturn(0);
when(appNamespaceService.findPublicAppNamespace(testNamespaceName)).thenReturn(publicNamespace);
when(namespaceAPI.countPublicAppNamespaceAssociatedNamespaces(testEnv, testNamespaceName)).thenReturn(10);
namespaceService.deleteNamespace(testAppId, testEnv, testClusterName, testNamespaceName);
}
Aggregations