Search in sources :

Example 31 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO in project apollo by ctripcorp.

the class NamespaceServiceTest method testDeleteEmptyNamespace.

@Test
public void testDeleteEmptyNamespace() {
    String branchName = "branch";
    String operator = "user";
    AppNamespace publicNamespace = createAppNamespace(testAppId, testNamespaceName, true);
    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);
    NamespaceDTO namespace = createNamespace(testAppId, testClusterName, testNamespaceName);
    when(namespaceAPI.getPublicAppNamespaceAllNamespaces(testEnv, testNamespaceName, 0, 10)).thenReturn(Collections.singletonList(namespace));
    when(userInfoHolder.getUser()).thenReturn(createUser(operator));
    namespaceService.deleteNamespace(testAppId, testEnv, testClusterName, testNamespaceName);
    verify(namespaceAPI, times(1)).deleteNamespace(testEnv, testAppId, testClusterName, testNamespaceName, operator);
}
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 32 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO in project apollo by ctripcorp.

the class NamespaceServiceTest method testFindNamespace.

@Test
public void testFindNamespace() {
    AppNamespace applicationAppNamespace = mock(AppNamespace.class);
    AppNamespace hermesAppNamespace = mock(AppNamespace.class);
    NamespaceDTO application = new NamespaceDTO();
    application.setId(1);
    application.setClusterName(testClusterName);
    application.setAppId(testAppId);
    application.setNamespaceName(testNamespaceName);
    NamespaceDTO hermes = new NamespaceDTO();
    hermes.setId(2);
    hermes.setClusterName("default");
    hermes.setAppId(testAppId);
    hermes.setNamespaceName("hermes");
    List<NamespaceDTO> namespaces = Arrays.asList(application, hermes);
    ReleaseDTO someRelease = new ReleaseDTO();
    someRelease.setConfigurations("{\"a\":\"123\",\"b\":\"123\"}");
    ItemDTO i1 = new ItemDTO("a", "123", "", 1);
    ItemDTO i2 = new ItemDTO("b", "1", "", 2);
    ItemDTO i3 = new ItemDTO("", "", "#dddd", 3);
    ItemDTO i4 = new ItemDTO("c", "1", "", 4);
    List<ItemDTO> someItems = Arrays.asList(i1, i2, i3, i4);
    when(applicationAppNamespace.getFormat()).thenReturn(ConfigFileFormat.Properties.getValue());
    when(hermesAppNamespace.getFormat()).thenReturn(ConfigFileFormat.XML.getValue());
    when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(applicationAppNamespace);
    when(appNamespaceService.findPublicAppNamespace("hermes")).thenReturn(hermesAppNamespace);
    when(namespaceAPI.findNamespaceByCluster(testAppId, Env.DEV, testClusterName)).thenReturn(namespaces);
    when(releaseService.loadLatestRelease(testAppId, Env.DEV, testClusterName, testNamespaceName)).thenReturn(someRelease);
    when(releaseService.loadLatestRelease(testAppId, Env.DEV, testClusterName, "hermes")).thenReturn(someRelease);
    when(itemService.findItems(testAppId, Env.DEV, testClusterName, testNamespaceName)).thenReturn(someItems);
    List<NamespaceBO> namespaceVOs = namespaceService.findNamespaceBOs(testAppId, Env.DEV, testClusterName);
    assertEquals(2, namespaceVOs.size());
    NamespaceBO namespaceVO = namespaceVOs.get(0);
    assertEquals(4, namespaceVO.getItems().size());
    assertEquals("a", namespaceVO.getItems().get(0).getItem().getKey());
    assertEquals(2, namespaceVO.getItemModifiedCnt());
    assertEquals(testAppId, namespaceVO.getBaseInfo().getAppId());
    assertEquals(testClusterName, namespaceVO.getBaseInfo().getClusterName());
    assertEquals(testNamespaceName, namespaceVO.getBaseInfo().getNamespaceName());
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) NamespaceBO(com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Example 33 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO in project apollo by ctripcorp.

the class SearchControllerTest method testSearchItem.

@Test
public void testSearchItem() {
    String query = "timeout";
    PageRequest request = PageRequest.of(0, 20);
    PageDTO<App> apps = new PageDTO<>(Lists.newLinkedList(), request, 0);
    PageDTO<NamespaceDTO> devNamespaces = genPageNamespace(10, request, 20);
    PageDTO<NamespaceDTO> fatNamespaces = genPageNamespace(15, request, 30);
    when(appService.searchByAppIdOrAppName(query, request)).thenReturn(apps);
    when(portalConfig.supportSearchByItem()).thenReturn(true);
    when(portalSettings.getActiveEnvs()).thenReturn(Lists.newArrayList(Env.DEV, Env.FAT));
    when(namespaceService.findNamespacesByItem(Env.DEV, query, request)).thenReturn(devNamespaces);
    when(namespaceService.findNamespacesByItem(Env.FAT, query, request)).thenReturn(fatNamespaces);
    PageDTO<App> result = searchController.search(query, request);
    Assert.assertTrue(result.hasContent());
    Assert.assertEquals(25, result.getContent().size());
    Assert.assertEquals(30, result.getTotal());
    verify(appService, times(0)).findAll(request);
    verify(appService, times(1)).searchByAppIdOrAppName(query, request);
    verify(namespaceService).findNamespacesByItem(Env.DEV, query, request);
    verify(namespaceService).findNamespacesByItem(Env.FAT, query, request);
}
Also used : App(com.ctrip.framework.apollo.common.entity.App) PageRequest(org.springframework.data.domain.PageRequest) NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) PageDTO(com.ctrip.framework.apollo.common.dto.PageDTO) Test(org.junit.Test)

Example 34 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO in project apollo by ctripcorp.

the class SearchControllerTest method genPageNamespace.

private PageDTO<NamespaceDTO> genPageNamespace(int size, Pageable pageable, int total) {
    List<NamespaceDTO> result = Lists.newLinkedList();
    for (int i = 0; i < size; i++) {
        NamespaceDTO namespaceDTO = new NamespaceDTO();
        result.add(namespaceDTO);
    }
    return new PageDTO<>(result, pageable, total);
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) PageDTO(com.ctrip.framework.apollo.common.dto.PageDTO)

Example 35 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO in project apollo by ctripcorp.

the class ConfigsExportServiceTest method genNamespace.

private NamespaceBO genNamespace(App app, ClusterDTO clusterDTO, List<ItemBO> itemBOS, String namespaceName) {
    NamespaceBO namespaceBO = new NamespaceBO();
    NamespaceDTO baseInfo = new NamespaceDTO();
    baseInfo.setNamespaceName(namespaceName);
    baseInfo.setAppId(app.getAppId());
    baseInfo.setClusterName(clusterDTO.getName());
    namespaceBO.setBaseInfo(baseInfo);
    namespaceBO.setFormat(ConfigFileFormat.Properties.getValue());
    namespaceBO.setItems(itemBOS);
    return namespaceBO;
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) NamespaceBO(com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)

Aggregations

NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)36 Test (org.junit.Test)13 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)12 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)10 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)8 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)7 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)7 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)4 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)4 Sql (org.springframework.test.context.jdbc.Sql)4 Item (com.ctrip.framework.apollo.biz.entity.Item)3 PageDTO (com.ctrip.framework.apollo.common.dto.PageDTO)3 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)3 OpenNamespaceDTO (com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO)3 NamespaceBO (com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)3 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)3 Env (com.ctrip.framework.apollo.portal.environment.Env)3 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RestTemplate (org.springframework.web.client.RestTemplate)3