Search in sources :

Example 61 with AppNamespace

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;
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Transactional(org.springframework.transaction.annotation.Transactional)

Example 62 with 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);
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Example 63 with AppNamespace

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);
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Example 64 with AppNamespace

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);
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Example 65 with AppNamespace

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);
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Aggregations

AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)71 Test (org.junit.Test)32 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)15 Sql (org.springframework.test.context.jdbc.Sql)13 AbstractIntegrationTest (com.ctrip.framework.apollo.portal.AbstractIntegrationTest)11 Transactional (org.springframework.transaction.annotation.Transactional)9 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)7 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)7 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)6 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 AppNamespaceCreationEvent (com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)3 App (com.ctrip.framework.apollo.common.entity.App)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Release (com.ctrip.framework.apollo.biz.entity.Release)2 AppNamespaceDTO (com.ctrip.framework.apollo.common.dto.AppNamespaceDTO)2 NamespaceBO (com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)2 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)2