use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class SpringSecurityUserInfoHolder method getUser.
@Override
public UserInfo getUser() {
String userId = this.getCurrentUsername();
UserInfo userInfoFound = this.userService.findByUserId(userId);
if (userInfoFound != null) {
return userInfoFound;
}
UserInfo userInfo = new UserInfo();
userInfo.setUserId(userId);
return userInfo;
}
use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class ConfigsExportServiceTest method testNamespaceExportImport.
@Test
public void testNamespaceExportImport() throws FileNotFoundException {
String filePath = "/tmp/apollo.zip";
File file = new File(filePath);
if (file.exists()) {
file.delete();
}
// export config
UserInfo userInfo = genUser();
when(userInfoHolder.getUser()).thenReturn(userInfo);
Env env = Env.DEV;
String appId1 = "app1";
String appId2 = "app2";
App app1 = genApp(appId1, appId1, "org1", "org2");
App app2 = genApp(appId2, appId2, "org1", "org2");
List<App> exportApps = Lists.newArrayList(app1, app2);
String appNamespaceName1 = "ns1";
String appNamespaceName2 = "ns2";
AppNamespace app1Namespace1 = genAppNamespace(appId1, appNamespaceName1, false);
AppNamespace app1Namespace2 = genAppNamespace(appId1, appNamespaceName2, true);
AppNamespace app2Namespace1 = genAppNamespace(appId2, appNamespaceName1, false);
List<AppNamespace> appNamespaces = Lists.newArrayList(app1Namespace1, app1Namespace2, app2Namespace1);
String clusterName1 = "c1";
String clusterName2 = "c2";
ClusterDTO app1Cluster1 = genCluster(clusterName1, appId1);
ClusterDTO app1Cluster2 = genCluster(clusterName2, appId1);
ClusterDTO app2Cluster1 = genCluster(clusterName1, appId2);
ClusterDTO app2Cluster2 = genCluster(clusterName2, appId2);
List<ClusterDTO> app1Clusters = Lists.newArrayList(app1Cluster1, app1Cluster2);
List<ClusterDTO> app2Clusters = Lists.newArrayList(app2Cluster1, app2Cluster2);
ItemBO item1 = genItem("k1", "v1");
ItemBO item2 = genItem("k2", "v2");
List<ItemBO> items = Lists.newArrayList(item1, item2);
String namespaceName1 = "namespace1";
String namespaceName2 = "namespace2";
NamespaceBO app1Cluster1Namespace1 = genNamespace(app1, app1Cluster1, items, namespaceName1);
NamespaceBO app1Cluster1Namespace2 = genNamespace(app1, app1Cluster1, items, namespaceName2);
List<NamespaceBO> app1Cluster1Namespace = Lists.newArrayList(app1Cluster1Namespace1, app1Cluster1Namespace2);
NamespaceBO app1Cluster2Namespace1 = genNamespace(app1, app1Cluster2, items, namespaceName1);
List<NamespaceBO> app1Cluster2Namespace = Lists.newArrayList(app1Cluster2Namespace1);
NamespaceBO app2Cluster1Namespace1 = genNamespace(app2, app1Cluster1, items, namespaceName1);
List<NamespaceBO> app2Cluster1Namespace = Lists.newArrayList(app2Cluster1Namespace1);
NamespaceBO app2Cluster2Namespace1 = genNamespace(app2, app1Cluster2, items, namespaceName1);
NamespaceBO app2Cluster2Namespace2 = genNamespace(app2, app1Cluster2, items, namespaceName2);
List<NamespaceBO> app2Cluster2Namespace = Lists.newArrayList(app2Cluster2Namespace1, app2Cluster2Namespace2);
when(appService.findAll()).thenReturn(exportApps);
when(appNamespaceService.findAll()).thenReturn(appNamespaces);
when(permissionValidator.isAppAdmin(any())).thenReturn(true);
when(clusterService.findClusters(env, appId1)).thenReturn(app1Clusters);
when(clusterService.findClusters(env, appId2)).thenReturn(app2Clusters);
when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1)).thenReturn(app1Cluster1Namespace);
when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2)).thenReturn(app1Cluster2Namespace);
when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1)).thenReturn(app2Cluster1Namespace);
when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2)).thenReturn(app2Cluster2Namespace);
FileOutputStream fileOutputStream = new FileOutputStream("/tmp/apollo.zip");
configsExportService.exportData(fileOutputStream, Lists.newArrayList(Env.DEV));
// import config
when(appNamespaceService.findByAppIdAndName(any(), any())).thenReturn(null);
when(appNamespaceService.importAppNamespaceInLocal(any())).thenReturn(app1Namespace1);
when(appService.load(any())).thenReturn(null);
when(appService.load(any(), any())).thenThrow(new RuntimeException());
when(clusterService.loadCluster(any(), any(), any())).thenThrow(new RuntimeException());
when(namespaceService.loadNamespaceBaseInfo(any(), any(), any(), any())).thenThrow(new RuntimeException());
when(namespaceService.createNamespace(any(), any())).thenReturn(genNamespaceDTO(1));
when(itemService.findItems(any(), any(), any(), any())).thenReturn(Lists.newArrayList());
HttpStatusCodeException itemNotFoundException = new HttpClientErrorException(HttpStatus.NOT_FOUND);
when(itemService.loadItem(any(), any(), any(), any(), anyString())).thenThrow(itemNotFoundException);
FileInputStream fileInputStream = new FileInputStream("/tmp/apollo.zip");
ZipInputStream zipInputStream = new ZipInputStream(fileInputStream);
try {
configsImportService.importDataFromZipFile(Lists.newArrayList(Env.DEV), zipInputStream, false);
} catch (Exception e) {
e.printStackTrace();
}
verify(appNamespaceService, times(3)).importAppNamespaceInLocal(any());
verify(applicationEventPublisher, times(3)).publishEvent(any());
verify(appService, times(2)).createAppInRemote(any(), any());
verify(clusterService, times(4)).createCluster(any(), any());
verify(namespaceService, times(6)).createNamespace(any(), any());
verify(roleInitializationService, times(6)).initNamespaceRoles(any(), any(), anyString());
verify(roleInitializationService, times(6)).initNamespaceEnvRoles(any(), any(), anyString());
verify(itemService, times(12)).createItem(any(), any(), any(), any(), any());
}
use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class ConfigsExportServiceTest method genUser.
private UserInfo genUser() {
UserInfo userInfo = new UserInfo();
userInfo.setUserId("apollo");
userInfo.setName("apollo");
userInfo.setEmail("apollo@apollo.com");
return userInfo;
}
use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class ConsumerServiceTest method createUser.
private UserInfo createUser(String userId) {
UserInfo userInfo = new UserInfo();
userInfo.setUserId(userId);
return userInfo;
}
use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class ConsumerServiceTest method testAssignNamespaceRoleToConsumer.
@Test
public void testAssignNamespaceRoleToConsumer() {
Long consumerId = 1L;
String token = "token";
doReturn(consumerId).when(consumerService).getConsumerIdByToken(token);
String testNamespace = "namespace";
String modifyRoleName = RoleUtils.buildModifyNamespaceRoleName(testAppId, testNamespace);
String releaseRoleName = RoleUtils.buildReleaseNamespaceRoleName(testAppId, testNamespace);
String envModifyRoleName = RoleUtils.buildModifyNamespaceRoleName(testAppId, testNamespace, Env.DEV.toString());
String envReleaseRoleName = RoleUtils.buildReleaseNamespaceRoleName(testAppId, testNamespace, Env.DEV.toString());
long modifyRoleId = 1;
long releaseRoleId = 2;
long envModifyRoleId = 3;
long envReleaseRoleId = 4;
Role modifyRole = createRole(modifyRoleId, modifyRoleName);
Role releaseRole = createRole(releaseRoleId, releaseRoleName);
Role envModifyRole = createRole(envModifyRoleId, modifyRoleName);
Role envReleaseRole = createRole(envReleaseRoleId, releaseRoleName);
when(rolePermissionService.findRoleByRoleName(modifyRoleName)).thenReturn(modifyRole);
when(rolePermissionService.findRoleByRoleName(releaseRoleName)).thenReturn(releaseRole);
when(rolePermissionService.findRoleByRoleName(envModifyRoleName)).thenReturn(envModifyRole);
when(rolePermissionService.findRoleByRoleName(envReleaseRoleName)).thenReturn(envReleaseRole);
when(consumerRoleRepository.findByConsumerIdAndRoleId(consumerId, modifyRoleId)).thenReturn(null);
UserInfo owner = createUser(testOwner);
when(userInfoHolder.getUser()).thenReturn(owner);
ConsumerRole namespaceModifyConsumerRole = createConsumerRole(consumerId, modifyRoleId);
ConsumerRole namespaceEnvModifyConsumerRole = createConsumerRole(consumerId, envModifyRoleId);
ConsumerRole namespaceReleaseConsumerRole = createConsumerRole(consumerId, releaseRoleId);
ConsumerRole namespaceEnvReleaseConsumerRole = createConsumerRole(consumerId, envReleaseRoleId);
doReturn(namespaceModifyConsumerRole).when(consumerService).createConsumerRole(consumerId, modifyRoleId, testOwner);
doReturn(namespaceEnvModifyConsumerRole).when(consumerService).createConsumerRole(consumerId, envModifyRoleId, testOwner);
doReturn(namespaceReleaseConsumerRole).when(consumerService).createConsumerRole(consumerId, releaseRoleId, testOwner);
doReturn(namespaceEnvReleaseConsumerRole).when(consumerService).createConsumerRole(consumerId, envReleaseRoleId, testOwner);
consumerService.assignNamespaceRoleToConsumer(token, testAppId, testNamespace);
consumerService.assignNamespaceRoleToConsumer(token, testAppId, testNamespace, Env.DEV.toString());
verify(consumerRoleRepository).save(namespaceModifyConsumerRole);
verify(consumerRoleRepository).save(namespaceEnvModifyConsumerRole);
verify(consumerRoleRepository).save(namespaceReleaseConsumerRole);
verify(consumerRoleRepository).save(namespaceEnvReleaseConsumerRole);
}
Aggregations