Search in sources :

Example 26 with Item

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

the class NamespacePublishInfoTest method testNamespaceEverPublishedAndModifiedAfter.

@Test
public void testNamespaceEverPublishedAndModifiedAfter() {
    Cluster cluster = createCluster(ConfigConsts.CLUSTER_NAME_DEFAULT);
    Namespace namespace = createNamespace(ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION);
    Item item = createItem(namespace.getId(), "a", "b");
    Release release = createRelease("{\"a\":\"c\"}");
    when(clusterService.findParentClusters(testApp)).thenReturn(Collections.singletonList(cluster));
    when(namespaceRepository.findByAppIdAndClusterNameOrderByIdAsc(testApp, ConfigConsts.CLUSTER_NAME_DEFAULT)).thenReturn(Collections.singletonList(namespace));
    when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release);
    when(itemService.findItemsModifiedAfterDate(anyLong(), anyObject())).thenReturn(Collections.singletonList(item));
    Map<String, Boolean> result = namespaceService.namespacePublishInfo(testApp);
    Assert.assertEquals(1, result.size());
    Assert.assertTrue(result.get(ConfigConsts.CLUSTER_NAME_DEFAULT));
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.biz.AbstractUnitTest)

Example 27 with Item

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

the class NamespacePublishInfoTest method testNamespaceNotEverPublishedButHasItems.

@Test
public void testNamespaceNotEverPublishedButHasItems() {
    Cluster cluster = createCluster(ConfigConsts.CLUSTER_NAME_DEFAULT);
    Namespace namespace = createNamespace(ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION);
    Item item = createItem(namespace.getId(), "a", "b");
    when(clusterService.findParentClusters(testApp)).thenReturn(Collections.singletonList(cluster));
    when(namespaceRepository.findByAppIdAndClusterNameOrderByIdAsc(testApp, ConfigConsts.CLUSTER_NAME_DEFAULT)).thenReturn(Collections.singletonList(namespace));
    when(itemService.findLastOne(anyLong())).thenReturn(item);
    Map<String, Boolean> result = namespaceService.namespacePublishInfo(testApp);
    Assert.assertEquals(1, result.size());
    Assert.assertTrue(result.get(ConfigConsts.CLUSTER_NAME_DEFAULT));
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.biz.AbstractUnitTest)

Example 28 with Item

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

the class NamespaceServiceIntegrationTest method testDeleteNamespace.

@Test
@Sql(scripts = "/sql/namespace-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testDeleteNamespace() {
    Namespace namespace = new Namespace();
    namespace.setAppId(testApp);
    namespace.setClusterName(testCluster);
    namespace.setNamespaceName(testPrivateNamespace);
    namespace.setId(1);
    namespaceService.deleteNamespace(namespace, testUser);
    List<Item> items = itemService.findItemsWithoutOrdered(testApp, testCluster, testPrivateNamespace);
    List<Commit> commits = commitService.find(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10));
    AppNamespace appNamespace = appNamespaceService.findOne(testApp, testPrivateNamespace);
    List<Cluster> childClusters = clusterService.findChildClusters(testApp, testCluster);
    InstanceConfig instanceConfig = instanceConfigRepository.findOne(1L);
    List<Release> parentNamespaceReleases = releaseService.findActiveReleases(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10));
    List<Release> childNamespaceReleases = releaseService.findActiveReleases(testApp, testChildCluster, testPrivateNamespace, new PageRequest(0, 10));
    Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10));
    assertEquals(0, items.size());
    assertEquals(0, commits.size());
    assertNotNull(appNamespace);
    assertEquals(0, childClusters.size());
    assertEquals(0, parentNamespaceReleases.size());
    assertEquals(0, childNamespaceReleases.size());
    assertTrue(!releaseHistories.hasContent());
    assertNull(instanceConfig);
}
Also used : ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Item(com.ctrip.framework.apollo.biz.entity.Item) PageRequest(org.springframework.data.domain.PageRequest) Commit(com.ctrip.framework.apollo.biz.entity.Commit) InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Sql(org.springframework.test.context.jdbc.Sql)

Example 29 with Item

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

the class ItemController method update.

@PreAcquireNamespaceLock
@RequestMapping(path = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{itemId}", method = RequestMethod.PUT)
public ItemDTO update(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @PathVariable("namespaceName") String namespaceName, @PathVariable("itemId") long itemId, @RequestBody ItemDTO itemDTO) {
    Item entity = BeanUtils.transfrom(Item.class, itemDTO);
    ConfigChangeContentBuilder builder = new ConfigChangeContentBuilder();
    Item managedEntity = itemService.findOne(itemId);
    if (managedEntity == null) {
        throw new BadRequestException("item not exist");
    }
    Item beforeUpdateItem = BeanUtils.transfrom(Item.class, managedEntity);
    // protect. only value,comment,lastModifiedBy can be modified
    managedEntity.setValue(entity.getValue());
    managedEntity.setComment(entity.getComment());
    managedEntity.setDataChangeLastModifiedBy(entity.getDataChangeLastModifiedBy());
    entity = itemService.update(managedEntity);
    builder.updateItem(beforeUpdateItem, entity);
    itemDTO = BeanUtils.transfrom(ItemDTO.class, entity);
    if (builder.hasContent()) {
        Commit commit = new Commit();
        commit.setAppId(appId);
        commit.setClusterName(clusterName);
        commit.setNamespaceName(namespaceName);
        commit.setChangeSets(builder.build());
        commit.setDataChangeCreatedBy(itemDTO.getDataChangeLastModifiedBy());
        commit.setDataChangeLastModifiedBy(itemDTO.getDataChangeLastModifiedBy());
        commitService.save(commit);
    }
    return itemDTO;
}
Also used : ConfigChangeContentBuilder(com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder) Item(com.ctrip.framework.apollo.biz.entity.Item) Commit(com.ctrip.framework.apollo.biz.entity.Commit) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) PreAcquireNamespaceLock(com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with Item

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

the class ConfigChangeContentBuilder method cloneItem.

Item cloneItem(Item source) {
    Item target = new Item();
    BeanUtils.copyProperties(source, target);
    return target;
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item)

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