@Transactional
  @PreAuthorize(value = "@permissionValidator.isSuperAdmin()")
  @PostMapping(value = "/consumers")
  public ConsumerInfo create(
      @RequestBody ConsumerCreateRequestVO requestVO,
      @RequestParam(value = "expires", required = false)
      @DateTimeFormat(pattern = "yyyyMMddHHmmss") Date expires
  ) {
    if (StringUtils.isBlank(requestVO.getAppId())) {
      throw BadRequestException.appIdIsBlank();
    }
    if (StringUtils.isBlank(requestVO.getName())) {
      throw BadRequestException.appNameIsBlank();
    }
    if (StringUtils.isBlank(requestVO.getOwnerName())) {
      throw BadRequestException.ownerNameIsBlank();
    }
    if (StringUtils.isBlank(requestVO.getOrgId())) {
      throw BadRequestException.orgIdIsBlank();
    }

    Consumer createdConsumer = consumerService.createConsumer(convertToConsumer(requestVO));

    if (Objects.isNull(expires)) {
      expires = DEFAULT_EXPIRES;
    }

    ConsumerToken consumerToken = consumerService.generateAndSaveConsumerToken(createdConsumer, expires);
    if (requestVO.isAllowCreateApplication()) {
      consumerService.assignCreateApplicationRoleToConsumer(consumerToken.getToken());
    }
    return consumerService.getConsumerInfoByAppId(requestVO.getAppId());
  }
@Test
  void createWithBadRequest() {
    ConsumerService consumerService = Mockito.mock(ConsumerService.class);
    ConsumerController consumerController = new ConsumerController(consumerService);

    ConsumerCreateRequestVO requestVO = new ConsumerCreateRequestVO();
    // blank appId
    assertThrows(BadRequestException.class, () -> consumerController.create(requestVO, null));
    requestVO.setAppId("appId1");

    // blank name
    assertThrows(BadRequestException.class, () -> consumerController.create(requestVO, null));
    requestVO.setName("app 1");

    // blank ownerName
    assertThrows(BadRequestException.class, () -> consumerController.create(requestVO, null));
    requestVO.setOwnerName("user1");

    // blank orgId
    assertThrows(BadRequestException.class, () -> consumerController.create(requestVO, null));
    requestVO.setOrgId("orgId1");
  }