ClusterService { @Transactional public void createDefaultCluster(String appId, String createBy) { if (!isClusterNameUnique(appId, ConfigConsts.CLUSTER_NAME_DEFAULT)) { throw new ServiceException("cluster not unique"); } Cluster cluster = new Cluster(); cluster.setName(ConfigConsts.CLUSTER_NAME_DEFAULT); cluster.setAppId(appId); cluster.setDataChangeCreatedBy(createBy); cluster.setDataChangeLastModifiedBy(createBy); clusterRepository.save(cluster); auditService.audit(Cluster.class.getSimpleName(), cluster.getId(), Audit.OP.INSERT, createBy); } ClusterService(
      final ClusterRepository clusterRepository,
      final AuditService auditService,
      final @Lazy NamespaceService namespaceService); boolean isClusterNameUnique(String appId, String clusterName); Cluster findOne(String appId, String name); Cluster findOne(long clusterId); List<Cluster> findParentClusters(String appId); @Transactional Cluster saveWithInstanceOfAppNamespaces(Cluster entity); @Transactional Cluster saveWithoutInstanceOfAppNamespaces(Cluster entity); @Transactional void delete(long id, String operator); @Transactional Cluster update(Cluster cluster); @Transactional void createDefaultCluster(String appId, String createBy); List<Cluster> findChildClusters(String appId, String parentClusterName); List<Cluster> findClusters(String appId);  }
@Test(expected = ServiceException.class) public void testCreateDuplicateCluster() { 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()); adminService.createNewApp(app); clusterService.createDefaultCluster(appId, owner); }