use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class NamespaceUtilTest method testNormalizeNamespaceWithPublicNamespace.
@Test
public void testNormalizeNamespaceWithPublicNamespace() throws Exception {
String someAppId = "someAppId";
String someNamespaceName = "someNamespaceName";
String someNormalizedNamespaceName = "someNormalizedNamespaceName";
AppNamespace someAppNamespace = mock(AppNamespace.class);
when(someAppNamespace.getName()).thenReturn(someNormalizedNamespaceName);
when(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, someNamespaceName)).thenReturn(null);
when(appNamespaceServiceWithCache.findPublicNamespaceByName(someNamespaceName)).thenReturn(someAppNamespace);
assertEquals(someNormalizedNamespaceName, namespaceUtil.normalizeNamespace(someAppId, someNamespaceName));
verify(appNamespaceServiceWithCache, times(1)).findByAppIdAndNamespace(someAppId, someNamespaceName);
verify(appNamespaceServiceWithCache, times(1)).findPublicNamespaceByName(someNamespaceName);
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class AppNamespaceControllerTest method testCreate.
@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreate() {
String appId = "6666";
String name = "testnamespace";
String comment = "comment";
AppNamespaceDTO dto = new AppNamespaceDTO();
dto.setAppId(appId);
dto.setName(name);
dto.setComment(comment);
dto.setDataChangeCreatedBy("apollo");
AppNamespaceDTO resultDto = restTemplate.postForEntity(String.format("http://localhost:%d/apps/%s/appnamespaces", port, appId), dto, AppNamespaceDTO.class).getBody();
Assert.assertEquals(appId, resultDto.getAppId());
Assert.assertTrue(resultDto.getId() > 0);
AppNamespace savedAppNs = namespaceRepository.findByAppIdAndName(appId, name);
Assert.assertNotNull(savedAppNs);
Assert.assertNotNull(savedAppNs.getDataChangeCreatedTime());
Assert.assertNotNull(savedAppNs.getDataChangeLastModifiedTime());
Assert.assertNotNull(savedAppNs.getDataChangeLastModifiedBy());
Assert.assertNotNull(savedAppNs.getDataChangeCreatedBy());
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class NamespaceService method instanceOfAppNamespaces.
@Transactional
public void instanceOfAppNamespaces(String appId, String clusterName, String createBy) {
List<AppNamespace> appNamespaces = appNamespaceService.findByAppId(appId);
for (AppNamespace appNamespace : appNamespaces) {
Namespace ns = new Namespace();
ns.setAppId(appId);
ns.setClusterName(clusterName);
ns.setNamespaceName(appNamespace.getName());
ns.setDataChangeCreatedBy(createBy);
ns.setDataChangeLastModifiedBy(createBy);
namespaceRepository.save(ns);
auditService.audit(Namespace.class.getSimpleName(), ns.getId(), Audit.OP.INSERT, createBy);
}
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace 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.common.entity.AppNamespace in project apollo by ctripcorp.
the class NamespaceServiceTest method testFindPublicAppNamespace.
@Test
public void testFindPublicAppNamespace() {
AppNamespace publicAppNamespace = MockBeanFactory.mockAppNamespace(null, testPublicAppNamespace, true);
when(appNamespaceService.findPublicNamespaceByName(testPublicAppNamespace)).thenReturn(publicAppNamespace);
Namespace firstParentNamespace = MockBeanFactory.mockNamespace("app", ConfigConsts.CLUSTER_NAME_DEFAULT, testPublicAppNamespace);
Namespace secondParentNamespace = MockBeanFactory.mockNamespace("app1", ConfigConsts.CLUSTER_NAME_DEFAULT, testPublicAppNamespace);
Namespace childNamespace = MockBeanFactory.mockNamespace("app2", ConfigConsts.CLUSTER_NAME_DEFAULT, testPublicAppNamespace);
Pageable page = new PageRequest(0, 10);
when(namespaceRepository.findByNamespaceName(testPublicAppNamespace, page)).thenReturn(Arrays.asList(firstParentNamespace, secondParentNamespace));
doReturn(false).when(namespaceService).isChildNamespace(firstParentNamespace);
doReturn(false).when(namespaceService).isChildNamespace(secondParentNamespace);
doReturn(true).when(namespaceService).isChildNamespace(childNamespace);
List<Namespace> namespaces = namespaceService.findPublicAppNamespaceAllNamespaces(testPublicAppNamespace, page);
assertEquals(2, namespaces.size());
}
Aggregations