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));
}
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));
}
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);
}
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;
}
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;
}
Aggregations