Search in sources :

Example 1 with NamespaceDTO

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

the class NamespaceController method getNamespaceLock.

@RequestMapping(value = "/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock", method = RequestMethod.GET)
public OpenNamespaceLockDTO getNamespaceLock(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName, @PathVariable String namespaceName) {
    NamespaceDTO namespace = namespaceService.loadNamespaceBaseInfo(appId, Env.fromString(env), clusterName, namespaceName);
    NamespaceLockDTO lockDTO = namespaceLockService.getNamespaceLock(appId, Env.fromString(env), clusterName, namespaceName);
    return OpenApiBeanUtils.transformFromNamespaceLockDTO(namespace.getNamespaceName(), lockDTO);
}
Also used : OpenAppNamespaceDTO(com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO) NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) OpenNamespaceDTO(com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO) NamespaceLockDTO(com.ctrip.framework.apollo.common.dto.NamespaceLockDTO) OpenNamespaceLockDTO(com.ctrip.framework.apollo.openapi.dto.OpenNamespaceLockDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with NamespaceDTO

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

the class ServerNamespaceOpenApiService method getNamespaceLock.

@Override
public OpenNamespaceLockDTO getNamespaceLock(String appId, String env, String clusterName, String namespaceName) {
    NamespaceDTO namespace = namespaceService.loadNamespaceBaseInfo(appId, Env.valueOf(env), clusterName, namespaceName);
    NamespaceLockDTO lockDTO = namespaceLockService.getNamespaceLock(appId, Env.valueOf(env), clusterName, namespaceName);
    return OpenApiBeanUtils.transformFromNamespaceLockDTO(namespace.getNamespaceName(), lockDTO);
}
Also used : OpenAppNamespaceDTO(com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO) NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) OpenNamespaceDTO(com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO) NamespaceLockDTO(com.ctrip.framework.apollo.common.dto.NamespaceLockDTO) OpenNamespaceLockDTO(com.ctrip.framework.apollo.openapi.dto.OpenNamespaceLockDTO)

Example 3 with NamespaceDTO

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

the class ConfigServiceTest method generateNamespaceDTO.

private NamespaceDTO generateNamespaceDTO(String appId, String clusterName, String namespaceName) {
    NamespaceDTO namespaceDTO = new NamespaceDTO();
    namespaceDTO.setAppId(appId);
    namespaceDTO.setId(1);
    namespaceDTO.setClusterName(clusterName);
    namespaceDTO.setNamespaceName(namespaceName);
    return namespaceDTO;
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO)

Example 4 with NamespaceDTO

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

the class ConfigServiceTest method testCompareTargetNamespaceHasNoItems.

@Test
public void testCompareTargetNamespaceHasNoItems() {
    ItemDTO sourceItem1 = new ItemDTO("a", "b", "comment", 1);
    List<ItemDTO> sourceItems = Collections.singletonList(sourceItem1);
    String appId = "6666", env = "LOCAL", clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT, namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
    List<NamespaceIdentifier> namespaceIdentifiers = generateNamespaceIdentifier(appId, env, clusterName, namespaceName);
    NamespaceDTO namespaceDTO = generateNamespaceDTO(appId, clusterName, namespaceName);
    when(namespaceAPI.loadNamespace(appId, Env.valueOf(env), clusterName, namespaceName)).thenReturn(namespaceDTO);
    when(itemAPI.findItems(appId, Env.valueOf(env), clusterName, namespaceName)).thenReturn(null);
    UserInfo userInfo = new UserInfo();
    userInfo.setUserId("test");
    when(userInfoHolder.getUser()).thenReturn(userInfo);
    List<ItemDiffs> itemDiffses = configService.compare(namespaceIdentifiers, sourceItems);
    assertEquals(1, itemDiffses.size());
    ItemDiffs itemDiffs = itemDiffses.get(0);
    ItemChangeSets changeSets = itemDiffs.getDiffs();
    assertEquals(0, changeSets.getUpdateItems().size());
    assertEquals(0, changeSets.getDeleteItems().size());
    List<ItemDTO> createItems = changeSets.getCreateItems();
    ItemDTO createItem = createItems.get(0);
    assertEquals(1, createItem.getLineNum());
    assertEquals("a", createItem.getKey());
    assertEquals("b", createItem.getValue());
    assertEquals("comment", createItem.getComment());
}
Also used : NamespaceIdentifier(com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier) NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) ItemDiffs(com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Example 5 with NamespaceDTO

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

the class ConfigServiceTest method testUpdateConfigByText.

@Test
public void testUpdateConfigByText() {
    String appId = "6666";
    String clusterName = "default";
    String namespaceName = "application";
    long someNamespaceId = 123L;
    NamespaceTextModel model = new NamespaceTextModel();
    model.setEnv("DEV");
    model.setNamespaceName(namespaceName);
    model.setClusterName(clusterName);
    model.setAppId(appId);
    model.setConfigText("a=b\nb=c\nc=d\nd=e");
    model.setFormat(ConfigFileFormat.Properties.getValue());
    List<ItemDTO> itemDTOs = mockBaseItemHas3Key();
    ItemChangeSets changeSets = new ItemChangeSets();
    changeSets.addCreateItem(new ItemDTO("d", "c", "", 4));
    NamespaceDTO someNamespaceDto = mock(NamespaceDTO.class);
    when(someNamespaceDto.getId()).thenReturn(someNamespaceId);
    when(namespaceAPI.loadNamespace(appId, model.getEnv(), clusterName, namespaceName)).thenReturn(someNamespaceDto);
    when(itemAPI.findItems(appId, Env.DEV, clusterName, namespaceName)).thenReturn(itemDTOs);
    when(resolver.resolve(someNamespaceId, model.getConfigText(), itemDTOs)).thenReturn(changeSets);
    UserInfo userInfo = new UserInfo();
    userInfo.setUserId("test");
    when(userInfoHolder.getUser()).thenReturn(userInfo);
    try {
        configService.updateConfigItemByText(model);
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) NamespaceTextModel(com.ctrip.framework.apollo.portal.entity.model.NamespaceTextModel) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

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