Search in sources :

Example 41 with ItemDTO

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

the class ItemService method buildItem.

private ItemDTO buildItem(long namespaceId, int lineNum, ItemDTO sourceItem) {
    ItemDTO createdItem = new ItemDTO();
    BeanUtils.copyEntityProperties(sourceItem, createdItem);
    createdItem.setLineNum(lineNum);
    createdItem.setNamespaceId(namespaceId);
    return createdItem;
}
Also used : ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO)

Example 42 with ItemDTO

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

the class ItemService method buildNormalItem.

private ItemDTO buildNormalItem(Long id, Long namespaceId, String key, String value, String comment, int lineNum) {
    ItemDTO item = new ItemDTO(key, value, comment, lineNum);
    item.setId(id);
    item.setNamespaceId(namespaceId);
    return item;
}
Also used : ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO)

Example 43 with ItemDTO

use of com.ctrip.framework.apollo.common.dto.ItemDTO 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 44 with ItemDTO

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

the class PropertyResolverTest method testUpdateItem.

@Test
public void testUpdateItem() {
    ItemChangeSets changeSets = resolver.resolve(1, "a=d", mockBaseItemHas3Key());
    List<ItemDTO> updateItems = changeSets.getUpdateItems();
    Assert.assertEquals(1, updateItems.size());
    Assert.assertEquals("d", updateItems.get(0).getValue());
}
Also used : ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Aggregations

ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)44 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)14 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)12 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)11 Test (org.junit.Test)11 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)7 Item (com.ctrip.framework.apollo.biz.entity.Item)6 OpenItemDTO (com.ctrip.framework.apollo.openapi.dto.OpenItemDTO)6 HashMap (java.util.HashMap)6 ItemBO (com.ctrip.framework.apollo.portal.entity.bo.ItemBO)5 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)4 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)4 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 Sql (org.springframework.test.context.jdbc.Sql)4 ConfigChangeContentBuilder (com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder)3 NamespaceBO (com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)3 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)3 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)3 RestTemplate (org.springframework.web.client.RestTemplate)3