@Transactional
  @ApolloAuditLog(type = OpType.CREATE, name = "App.create")
  public App createAppAndAddRolePermission(
      App app, Set<String> admins
  ) {
    App createdApp = this.createAppInLocal(app);

    publisher.publishEvent(new AppCreationEvent(createdApp));

    if (!CollectionUtils.isEmpty(admins)) {
      rolePermissionService
          .assignRoleToUsers(RoleUtils.buildAppMasterRoleName(createdApp.getAppId()),
              admins, userInfoHolder.getUser().getUserId());
    }

    return createdApp;
  }
@Test
  void createAppAndAddRolePermission() {
    final String userId = "user100";
    final String appId = "appId100";
    {
      UserInfo userInfo = new UserInfo();
      userInfo.setUserId(userId);
      userInfo.setEmail("xxx@xxx.com");
      Mockito.when(userService.findByUserId(Mockito.eq(userId)))
          .thenReturn(userInfo);
    }

    final App app = new App();
    app.setAppId(appId);
    app.setOwnerName(userId);
    Set<String> admins = new HashSet<>(Arrays.asList("user1", "user2"));

    final App createdApp = new App();
    createdApp.setAppId(appId);
    createdApp.setOwnerName(userId);
    {
      Mockito.when(appRepository.save(Mockito.eq(app)))
          .thenReturn(createdApp);
    }
    appService.createAppAndAddRolePermission(app, admins);
    Mockito.verify(appRepository, Mockito.times(1))
        .findByAppId(Mockito.eq(appId));
    Mockito.verify(userService, Mockito.times(1))
        .findByUserId(Mockito.eq(userId));
    Mockito.verify(userInfoHolder, Mockito.times(2))
        .getUser();
    Mockito.verify(appRepository, Mockito.times(1))
        .save(Mockito.eq(app));
    Mockito.verify(appNamespaceService, Mockito.times(1))
        .createDefaultAppNamespace(Mockito.eq(appId));
    Mockito.verify(roleInitializationService, Mockito.times(1))
        .initAppRoles(Mockito.eq(createdApp));

    Mockito.verify(rolePermissionService, Mockito.times(1))
        .assignRoleToUsers(Mockito.any(), Mockito.eq(admins), Mockito.eq(OPERATOR_USER_ID));
  }