ConsumerService { private ConsumerToken generateConsumerToken(Consumer consumer, Date expires) { long consumerId = consumer.getId(); String createdBy = userInfoHolder.getUser().getUserId(); Date createdTime = new Date(); ConsumerToken consumerToken = new ConsumerToken(); consumerToken.setConsumerId(consumerId); consumerToken.setExpires(expires); consumerToken.setDataChangeCreatedBy(createdBy); consumerToken.setDataChangeCreatedTime(createdTime); consumerToken.setDataChangeLastModifiedBy(createdBy); consumerToken.setDataChangeLastModifiedTime(createdTime); generateAndEnrichToken(consumer, consumerToken); return consumerToken; } ConsumerService(
      final UserInfoHolder userInfoHolder,
      final ConsumerTokenRepository consumerTokenRepository,
      final ConsumerRepository consumerRepository,
      final ConsumerAuditRepository consumerAuditRepository,
      final ConsumerRoleRepository consumerRoleRepository,
      final PortalConfig portalConfig,
      final RolePermissionService rolePermissionService,
      final UserService userService); Consumer createConsumer(Consumer consumer); ConsumerToken generateAndSaveConsumerToken(Consumer consumer, Date expires); ConsumerToken getConsumerTokenByAppId(String appId); Long getConsumerIdByToken(String token); Consumer getConsumerByConsumerId(long consumerId); List<ConsumerRole> assignNamespaceRoleToConsumer(String token, String appId, String namespaceName); @Transactional List<ConsumerRole> assignNamespaceRoleToConsumer(String token, String appId, String namespaceName, String env); @Transactional ConsumerRole assignAppRoleToConsumer(String token, String appId); @Transactional void createConsumerAudits(Iterable<ConsumerAudit> consumerAudits); @Transactional ConsumerToken createConsumerToken(ConsumerToken entity);  }
@Test public void testGenerateConsumerToken() throws Exception { String someConsumerAppId = "100003171"; Date generationTime = new GregorianCalendar(2016, Calendar.AUGUST, 9, 12, 10, 50).getTime(); String tokenSalt = "apollo"; assertEquals("d0da35292dd5079eeb73cc3a5f7c0759afabd806", consumerService .generateToken(someConsumerAppId, generationTime, tokenSalt)); }