Search in sources :

Example 16 with Item

use of com.ctrip.framework.apollo.biz.entity.Item in project apollo by ctripcorp.

the class NamespaceUnlockAspectTest method testChildNamespaceModified.

@Test
public void testChildNamespaceModified() {
    long childNamespaceId = 1, parentNamespaceId = 2;
    Namespace childNamespace = createNamespace(childNamespaceId);
    Namespace parentNamespace = createNamespace(parentNamespaceId);
    Release childRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
    List<Item> childItems = Arrays.asList(createItem("k1", "v3"));
    Release parentRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
    when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
    when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(parentRelease);
    when(itemService.findItemsWithoutOrdered(childNamespaceId)).thenReturn(childItems);
    when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
    boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
    Assert.assertTrue(isModified);
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 17 with Item

use of com.ctrip.framework.apollo.biz.entity.Item in project apollo by ctripcorp.

the class NamespaceUnlockAspectTest method testChildNamespaceNotModified.

@Test
public void testChildNamespaceNotModified() {
    long childNamespaceId = 1, parentNamespaceId = 2;
    Namespace childNamespace = createNamespace(childNamespaceId);
    Namespace parentNamespace = createNamespace(parentNamespaceId);
    Release childRelease = createRelease("{\"k1\":\"v3\", \"k2\":\"v2\"}");
    List<Item> childItems = Arrays.asList(createItem("k1", "v3"));
    Release parentRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
    when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
    when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(parentRelease);
    when(itemService.findItemsWithoutOrdered(childNamespaceId)).thenReturn(childItems);
    when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
    boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
    Assert.assertFalse(isModified);
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 18 with Item

use of com.ctrip.framework.apollo.biz.entity.Item in project apollo by ctripcorp.

the class NamespaceUnlockAspectTest method testParentNamespaceNotReleased.

@Test
public void testParentNamespaceNotReleased() {
    long childNamespaceId = 1, parentNamespaceId = 2;
    Namespace childNamespace = createNamespace(childNamespaceId);
    Namespace parentNamespace = createNamespace(parentNamespaceId);
    Release childRelease = createRelease("{\"k1\":\"v3\", \"k2\":\"v2\"}");
    List<Item> childItems = Arrays.asList(createItem("k1", "v2"), createItem("k2", "v2"));
    when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
    when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(null);
    when(itemService.findItemsWithOrdered(childNamespaceId)).thenReturn(childItems);
    when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
    boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
    Assert.assertTrue(isModified);
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 19 with Item

use of com.ctrip.framework.apollo.biz.entity.Item in project apollo by ctripcorp.

the class ItemSetControllerTest method testItemSetUpdated.

@Test
@Sql(scripts = "/controller/test-itemset.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testItemSetUpdated() {
    String appId = "someAppId";
    AppDTO app = restTemplate.getForObject("http://localhost:" + port + "/apps/" + appId, AppDTO.class);
    ClusterDTO cluster = restTemplate.getForObject("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/default", ClusterDTO.class);
    NamespaceDTO namespace = restTemplate.getForObject("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName() + "/namespaces/application", NamespaceDTO.class);
    Assert.assertEquals("someAppId", app.getAppId());
    Assert.assertEquals("default", cluster.getName());
    Assert.assertEquals("application", namespace.getNamespaceName());
    ItemChangeSets createChangeSet = new ItemChangeSets();
    createChangeSet.setDataChangeLastModifiedBy("created");
    RestTemplate createdRestTemplate = new TestRestTemplate();
    createdRestTemplate.setMessageConverters(restTemplate.getMessageConverters());
    int createdSize = 3;
    for (int i = 0; i < createdSize; i++) {
        ItemDTO item = new ItemDTO();
        item.setNamespaceId(namespace.getId());
        item.setKey("key_" + i);
        item.setValue("created_value_" + i);
        createChangeSet.addCreateItem(item);
    }
    ResponseEntity<Void> response = createdRestTemplate.postForEntity("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName() + "/namespaces/" + namespace.getNamespaceName() + "/itemset", createChangeSet, Void.class);
    Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
    ItemDTO[] items = createdRestTemplate.getForObject("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName() + "/namespaces/" + namespace.getNamespaceName() + "/items", ItemDTO[].class);
    ItemChangeSets updateChangeSet = new ItemChangeSets();
    updateChangeSet.setDataChangeLastModifiedBy("updated");
    RestTemplate updatedRestTemplate = new TestRestTemplate();
    updatedRestTemplate.setMessageConverters(restTemplate.getMessageConverters());
    int updatedSize = 2;
    for (int i = 0; i < updatedSize; i++) {
        items[i].setValue("updated_value_" + i);
        updateChangeSet.addUpdateItem(items[i]);
    }
    response = updatedRestTemplate.postForEntity("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName() + "/namespaces/" + namespace.getNamespaceName() + "/itemset", updateChangeSet, Void.class);
    Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
    List<Item> savedItems = itemRepository.findByNamespaceIdOrderByLineNumAsc(namespace.getId());
    Assert.assertEquals(createdSize, savedItems.size());
    Item item0 = savedItems.get(0);
    Assert.assertEquals("key_0", item0.getKey());
    Assert.assertEquals("updated_value_0", item0.getValue());
    Assert.assertEquals("created", item0.getDataChangeCreatedBy());
    Assert.assertEquals("updated", item0.getDataChangeLastModifiedBy());
    Assert.assertNotNull(item0.getDataChangeCreatedTime());
    Assert.assertNotNull(item0.getDataChangeLastModifiedTime());
}
Also used : TestRestTemplate(org.springframework.boot.test.TestRestTemplate) ClusterDTO(com.ctrip.framework.apollo.common.dto.ClusterDTO) ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) Item(com.ctrip.framework.apollo.biz.entity.Item) NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) AppDTO(com.ctrip.framework.apollo.common.dto.AppDTO) TestRestTemplate(org.springframework.boot.test.TestRestTemplate) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 20 with Item

use of com.ctrip.framework.apollo.biz.entity.Item in project apollo by ctripcorp.

the class ItemSetControllerTest method testItemSetDeleted.

@Test
@Sql(scripts = "/controller/test-itemset.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testItemSetDeleted() {
    String appId = "someAppId";
    AppDTO app = restTemplate.getForObject("http://localhost:" + port + "/apps/" + appId, AppDTO.class);
    ClusterDTO cluster = restTemplate.getForObject("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/default", ClusterDTO.class);
    NamespaceDTO namespace = restTemplate.getForObject("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName() + "/namespaces/application", NamespaceDTO.class);
    Assert.assertEquals("someAppId", app.getAppId());
    Assert.assertEquals("default", cluster.getName());
    Assert.assertEquals("application", namespace.getNamespaceName());
    ItemChangeSets createChangeSet = new ItemChangeSets();
    createChangeSet.setDataChangeLastModifiedBy("created");
    RestTemplate createdTemplate = new TestRestTemplate();
    createdTemplate.setMessageConverters(restTemplate.getMessageConverters());
    int createdSize = 3;
    for (int i = 0; i < createdSize; i++) {
        ItemDTO item = new ItemDTO();
        item.setNamespaceId(namespace.getId());
        item.setKey("key_" + i);
        item.setValue("created_value_" + i);
        createChangeSet.addCreateItem(item);
    }
    ResponseEntity<Void> response = createdTemplate.postForEntity("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName() + "/namespaces/" + namespace.getNamespaceName() + "/itemset", createChangeSet, Void.class);
    Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
    ItemDTO[] items = restTemplate.getForObject("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName() + "/namespaces/" + namespace.getNamespaceName() + "/items", ItemDTO[].class);
    ItemChangeSets deleteChangeSet = new ItemChangeSets();
    deleteChangeSet.setDataChangeLastModifiedBy("deleted");
    RestTemplate deletedTemplate = new TestRestTemplate();
    deletedTemplate.setMessageConverters(restTemplate.getMessageConverters());
    int deletedSize = 1;
    for (int i = 0; i < deletedSize; i++) {
        items[i].setValue("deleted_value_" + i);
        deleteChangeSet.addDeleteItem(items[i]);
    }
    response = deletedTemplate.postForEntity("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName() + "/namespaces/" + namespace.getNamespaceName() + "/itemset", deleteChangeSet, Void.class);
    Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
    List<Item> savedItems = itemRepository.findByNamespaceIdOrderByLineNumAsc(namespace.getId());
    Assert.assertEquals(createdSize - deletedSize, savedItems.size());
    Item item0 = savedItems.get(0);
    Assert.assertEquals("key_1", item0.getKey());
    Assert.assertEquals("created_value_1", item0.getValue());
    Assert.assertEquals("created", item0.getDataChangeCreatedBy());
    Assert.assertNotNull(item0.getDataChangeCreatedTime());
}
Also used : TestRestTemplate(org.springframework.boot.test.TestRestTemplate) ClusterDTO(com.ctrip.framework.apollo.common.dto.ClusterDTO) ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) Item(com.ctrip.framework.apollo.biz.entity.Item) NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) AppDTO(com.ctrip.framework.apollo.common.dto.AppDTO) TestRestTemplate(org.springframework.boot.test.TestRestTemplate) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

Item (com.ctrip.framework.apollo.biz.entity.Item)30 Test (org.junit.Test)13 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)12 Release (com.ctrip.framework.apollo.biz.entity.Release)11 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)6 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)4 Commit (com.ctrip.framework.apollo.biz.entity.Commit)4 ConfigChangeContentBuilder (com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder)4 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)4 Sql (org.springframework.test.context.jdbc.Sql)4 Transactional (org.springframework.transaction.annotation.Transactional)4 PreAcquireNamespaceLock (com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock)3 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)3 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)3 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)3 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)3 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)3 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)3 TestRestTemplate (org.springframework.boot.test.TestRestTemplate)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3