Search in sources :

Example 21 with ItemChangeSets

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

the class ItemService method compare.

public List<ItemDiffs> compare(List<NamespaceIdentifier> comparedNamespaces, List<ItemDTO> sourceItems) {
    List<ItemDiffs> result = new LinkedList<>();
    for (NamespaceIdentifier namespace : comparedNamespaces) {
        ItemDiffs itemDiffs = new ItemDiffs(namespace);
        try {
            itemDiffs.setDiffs(parseChangeSets(namespace, sourceItems));
        } catch (BadRequestException e) {
            itemDiffs.setDiffs(new ItemChangeSets());
            itemDiffs.setExtInfo("该集群下没有名为 " + namespace.getNamespaceName() + " 的namespace");
        }
        result.add(itemDiffs);
    }
    return result;
}
Also used : NamespaceIdentifier(com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier) ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) ItemDiffs(com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs) LinkedList(java.util.LinkedList)

Example 22 with ItemChangeSets

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

the class PropertyResolverTest method testAddItemBeforeHasItem.

@Test
public void testAddItemBeforeHasItem() {
    ItemChangeSets changeSets = resolver.resolve(1, "x=y\na=b\nb=c\nc=d", mockBaseItemHas3Key());
    Assert.assertEquals("x", changeSets.getCreateItems().get(0).getKey());
    Assert.assertEquals(1, changeSets.getCreateItems().size());
    Assert.assertEquals(3, changeSets.getUpdateItems().size());
}
Also used : ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Example 23 with ItemChangeSets

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

the class PropertyResolverTest method testDeleteCommentItem.

@Test
public void testDeleteCommentItem() {
    ItemChangeSets changeSets = resolver.resolve(1, "a=b\n\nb=c", mockBaseItemWith2Key1Comment1Blank());
    Assert.assertEquals(2, changeSets.getDeleteItems().size());
    Assert.assertEquals(2, changeSets.getUpdateItems().size());
    Assert.assertEquals(1, changeSets.getCreateItems().size());
}
Also used : ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Example 24 with ItemChangeSets

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

the class PropertyResolverTest method testAllSituation.

@Test
public void testAllSituation() {
    ItemChangeSets changeSets = resolver.resolve(1, "#ww\nd=e\nb=c\na=b\n\nq=w\n#eee", mockBaseItemWith2Key1Comment1Blank());
    Assert.assertEquals(2, changeSets.getDeleteItems().size());
    Assert.assertEquals(2, changeSets.getUpdateItems().size());
    Assert.assertEquals(5, changeSets.getCreateItems().size());
}
Also used : ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Example 25 with ItemChangeSets

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

the class PropertyResolverTest method testAddItemBeforeNoItem.

@Test
public void testAddItemBeforeNoItem() {
    ItemChangeSets changeSets = resolver.resolve(1, "a=b\nb=c", Collections.emptyList());
    Assert.assertEquals(2, changeSets.getCreateItems().size());
}
Also used : ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Aggregations

ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)28 Test (org.junit.Test)18 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)15 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)14 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)8 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)5 ItemDiffs (com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs)5 NamespaceIdentifier (com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier)5 Item (com.ctrip.framework.apollo.biz.entity.Item)3 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)3 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)3 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)3 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)3 Sql (org.springframework.test.context.jdbc.Sql)3 RestTemplate (org.springframework.web.client.RestTemplate)3 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)2 Env (com.ctrip.framework.apollo.portal.environment.Env)2 HashMap (java.util.HashMap)2 ConfigTextResolver (com.ctrip.framework.apollo.portal.component.txtresolver.ConfigTextResolver)1 NamespaceBO (com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)1