Search in sources :

Example 41 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.

the class NamespaceUtilTest method testNormalizeNamespaceWithPublicNamespace.

@Test
public void testNormalizeNamespaceWithPublicNamespace() throws Exception {
    String someAppId = "someAppId";
    String someNamespaceName = "someNamespaceName";
    String someNormalizedNamespaceName = "someNormalizedNamespaceName";
    AppNamespace someAppNamespace = mock(AppNamespace.class);
    when(someAppNamespace.getName()).thenReturn(someNormalizedNamespaceName);
    when(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, someNamespaceName)).thenReturn(null);
    when(appNamespaceServiceWithCache.findPublicNamespaceByName(someNamespaceName)).thenReturn(someAppNamespace);
    assertEquals(someNormalizedNamespaceName, namespaceUtil.normalizeNamespace(someAppId, someNamespaceName));
    verify(appNamespaceServiceWithCache, times(1)).findByAppIdAndNamespace(someAppId, someNamespaceName);
    verify(appNamespaceServiceWithCache, times(1)).findPublicNamespaceByName(someNamespaceName);
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test)

Example 42 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.

the class AppNamespaceControllerTest method testCreate.

@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreate() {
    String appId = "6666";
    String name = "testnamespace";
    String comment = "comment";
    AppNamespaceDTO dto = new AppNamespaceDTO();
    dto.setAppId(appId);
    dto.setName(name);
    dto.setComment(comment);
    dto.setDataChangeCreatedBy("apollo");
    AppNamespaceDTO resultDto = restTemplate.postForEntity(String.format("http://localhost:%d/apps/%s/appnamespaces", port, appId), dto, AppNamespaceDTO.class).getBody();
    Assert.assertEquals(appId, resultDto.getAppId());
    Assert.assertTrue(resultDto.getId() > 0);
    AppNamespace savedAppNs = namespaceRepository.findByAppIdAndName(appId, name);
    Assert.assertNotNull(savedAppNs);
    Assert.assertNotNull(savedAppNs.getDataChangeCreatedTime());
    Assert.assertNotNull(savedAppNs.getDataChangeLastModifiedTime());
    Assert.assertNotNull(savedAppNs.getDataChangeLastModifiedBy());
    Assert.assertNotNull(savedAppNs.getDataChangeCreatedBy());
}
Also used : AppNamespaceDTO(com.ctrip.framework.apollo.common.dto.AppNamespaceDTO) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 43 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.

the class NamespaceService method instanceOfAppNamespaces.

@Transactional
public void instanceOfAppNamespaces(String appId, String clusterName, String createBy) {
    List<AppNamespace> appNamespaces = appNamespaceService.findByAppId(appId);
    for (AppNamespace appNamespace : appNamespaces) {
        Namespace ns = new Namespace();
        ns.setAppId(appId);
        ns.setClusterName(clusterName);
        ns.setNamespaceName(appNamespace.getName());
        ns.setDataChangeCreatedBy(createBy);
        ns.setDataChangeLastModifiedBy(createBy);
        namespaceRepository.save(ns);
        auditService.audit(Namespace.class.getSimpleName(), ns.getId(), Audit.OP.INSERT, createBy);
    }
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Transactional(org.springframework.transaction.annotation.Transactional)

Example 44 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.

the class NamespaceServiceIntegrationTest method testDeleteNamespace.

@Test
@Sql(scripts = "/sql/namespace-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testDeleteNamespace() {
    Namespace namespace = new Namespace();
    namespace.setAppId(testApp);
    namespace.setClusterName(testCluster);
    namespace.setNamespaceName(testPrivateNamespace);
    namespace.setId(1);
    namespaceService.deleteNamespace(namespace, testUser);
    List<Item> items = itemService.findItemsWithoutOrdered(testApp, testCluster, testPrivateNamespace);
    List<Commit> commits = commitService.find(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10));
    AppNamespace appNamespace = appNamespaceService.findOne(testApp, testPrivateNamespace);
    List<Cluster> childClusters = clusterService.findChildClusters(testApp, testCluster);
    InstanceConfig instanceConfig = instanceConfigRepository.findOne(1L);
    List<Release> parentNamespaceReleases = releaseService.findActiveReleases(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10));
    List<Release> childNamespaceReleases = releaseService.findActiveReleases(testApp, testChildCluster, testPrivateNamespace, new PageRequest(0, 10));
    Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10));
    assertEquals(0, items.size());
    assertEquals(0, commits.size());
    assertNotNull(appNamespace);
    assertEquals(0, childClusters.size());
    assertEquals(0, parentNamespaceReleases.size());
    assertEquals(0, childNamespaceReleases.size());
    assertTrue(!releaseHistories.hasContent());
    assertNull(instanceConfig);
}
Also used : ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Item(com.ctrip.framework.apollo.biz.entity.Item) PageRequest(org.springframework.data.domain.PageRequest) Commit(com.ctrip.framework.apollo.biz.entity.Commit) InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Sql(org.springframework.test.context.jdbc.Sql)

Example 45 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.

the class NamespaceServiceTest method testFindPublicAppNamespace.

@Test
public void testFindPublicAppNamespace() {
    AppNamespace publicAppNamespace = MockBeanFactory.mockAppNamespace(null, testPublicAppNamespace, true);
    when(appNamespaceService.findPublicNamespaceByName(testPublicAppNamespace)).thenReturn(publicAppNamespace);
    Namespace firstParentNamespace = MockBeanFactory.mockNamespace("app", ConfigConsts.CLUSTER_NAME_DEFAULT, testPublicAppNamespace);
    Namespace secondParentNamespace = MockBeanFactory.mockNamespace("app1", ConfigConsts.CLUSTER_NAME_DEFAULT, testPublicAppNamespace);
    Namespace childNamespace = MockBeanFactory.mockNamespace("app2", ConfigConsts.CLUSTER_NAME_DEFAULT, testPublicAppNamespace);
    Pageable page = new PageRequest(0, 10);
    when(namespaceRepository.findByNamespaceName(testPublicAppNamespace, page)).thenReturn(Arrays.asList(firstParentNamespace, secondParentNamespace));
    doReturn(false).when(namespaceService).isChildNamespace(firstParentNamespace);
    doReturn(false).when(namespaceService).isChildNamespace(secondParentNamespace);
    doReturn(true).when(namespaceService).isChildNamespace(childNamespace);
    List<Namespace> namespaces = namespaceService.findPublicAppNamespaceAllNamespaces(testPublicAppNamespace, page);
    assertEquals(2, namespaces.size());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.biz.AbstractUnitTest)

Aggregations

AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)50 Test (org.junit.Test)25 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)8 Sql (org.springframework.test.context.jdbc.Sql)7 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)6 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)6 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 Matchers.anyString (org.mockito.Matchers.anyString)6 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)5 AbstractIntegrationTest (com.ctrip.framework.apollo.portal.AbstractIntegrationTest)5 Transactional (org.springframework.transaction.annotation.Transactional)5 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Release (com.ctrip.framework.apollo.biz.entity.Release)2 AppNamespaceCreationEvent (com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent)2 PageRequest (org.springframework.data.domain.PageRequest)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)1 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)1