AdminService { @Transactional public App createNewApp(App app) { String createBy = app.getDataChangeCreatedBy(); App createdApp = appService.save(app); String appId = createdApp.getAppId(); appNamespaceService.createDefaultAppNamespace(appId, createBy); clusterService.createDefaultCluster(appId, createBy); namespaceService.instanceOfAppNamespaces(appId, ConfigConsts.CLUSTER_NAME_DEFAULT, createBy); return app; } AdminService(
      final AppService appService,
      final @Lazy AppNamespaceService appNamespaceService,
      final @Lazy ClusterService clusterService,
      final @Lazy NamespaceService namespaceService); @Transactional App createNewApp(App app); @Transactional void deleteApp(App app, String operator);  }
@Test public void testCreateNewApp() { String appId = "someAppId"; App app = new App(); app.setAppId(appId); app.setName("someAppName"); String owner = "someOwnerName"; app.setOwnerName(owner); app.setOwnerEmail("someOwnerName@ctrip.com"); app.setDataChangeCreatedBy(owner); app.setDataChangeLastModifiedBy(owner); app.setDataChangeCreatedTime(new Date()); app = adminService.createNewApp(app); Assert.assertEquals(appId, app.getAppId()); List<Cluster> clusters = clusterService.findParentClusters(app.getAppId()); Assert.assertEquals(1, clusters.size()); Assert.assertEquals(ConfigConsts.CLUSTER_NAME_DEFAULT, clusters.get(0).getName()); List<Namespace> namespaces = namespaceService.findNamespaces(appId, clusters.get(0).getName()); Assert.assertEquals(1, namespaces.size()); Assert.assertEquals(ConfigConsts.NAMESPACE_APPLICATION, namespaces.get(0).getNamespaceName()); List<Audit> audits = auditService.findByOwner(owner); Assert.assertEquals(4, audits.size()); }
@Test(expected = ServiceException.class) public void testCreateDuplicateApp() { String appId = "someAppId"; App app = new App(); app.setAppId(appId); app.setName("someAppName"); String owner = "someOwnerName"; app.setOwnerName(owner); app.setOwnerEmail("someOwnerName@ctrip.com"); app.setDataChangeCreatedBy(owner); app.setDataChangeLastModifiedBy(owner); app.setDataChangeCreatedTime(new Date()); appRepository.save(app); adminService.createNewApp(app); }