@Test public void shouldBeAbleToConvertAClientIntoAClientRepresentation() { Authority authority = authority().build(); Audience audience = audience().build(); Scope scope = scope().build(); GrantType grantType = grantType().build(); Client client = client().withAudience(audience).withDescription("description").withAuthority(authority).withScope(scope).withGrantType(grantType).build(); ClientRepresentation representation = clientConversionService.convert(client); assertThat(representation.getId()).isEqualTo(client.getId()); assertThat(representation.getCreated()).isEqualTo(client.getCreated()); assertThat(representation.getUpdated()).isEqualTo(client.getUpdated()); assertThat(representation.getClientId()).isEqualTo(client.getClientId()); assertThat(representation.getClientSecret()).isNull(); assertThat(representation.getDescription()).isEqualTo("description"); assertThat(representation.getAccessTokenValiditySeconds()).isEqualTo(client.getAccessTokenValiditySeconds()); assertThat(representation.getRefreshTokenValiditySeconds()).isEqualTo(client.getRefreshTokenValiditySeconds()); assertThat(representation.getAudiences()).hasSize(1); assertThat(representation.getAuthorities()).hasSize(1); assertThat(representation.getScopes()).hasSize(1); assertThat(representation.getGrantTypes()).hasSize(1); }
public ClientRepresentation convert(Client client) { ClientRepresentation representation = new ClientRepresentation(); representation.setId(client.getId()); representation.setCreated(client.getCreated()); representation.setUpdated(client.getUpdated()); representation.setClientId(client.getClientId()); representation.setName(client.getName()); representation.setDescription(client.getDescription()); representation.setAudiences(client.getAudiences().stream().map(audience -> audienceConversionService.convert(audience)).collect(Collectors.toCollection(HashSet::new))); representation.setAuthorities(client.getAuthorities().stream().map(authority -> authorityConversionService.convert(authority)).collect(Collectors.toCollection(HashSet::new))); representation.setGrantTypes(client.getGrantTypes().stream().map(grantType -> grantTypeConversionService.convert(grantType)).collect(Collectors.toCollection(HashSet::new))); representation.setScopes(client.getScopes().stream().map(scope -> scopeConversionService.convert(scope)).collect(Collectors.toCollection(HashSet::new))); representation.setRedirectUri(client.getRedirectUri()); representation.setAccessTokenValiditySeconds(client.getAccessTokenValiditySeconds()); representation.setRefreshTokenValiditySeconds(client.getRefreshTokenValiditySeconds()); return representation; }
ClientConversionService { public ClientRepresentation convert(Client client) { ClientRepresentation representation = new ClientRepresentation(); representation.setId(client.getId()); representation.setCreated(client.getCreated()); representation.setUpdated(client.getUpdated()); representation.setClientId(client.getClientId()); representation.setName(client.getName()); representation.setDescription(client.getDescription()); representation.setAudiences(client.getAudiences().stream().map(audience -> audienceConversionService.convert(audience)).collect(Collectors.toCollection(HashSet::new))); representation.setAuthorities(client.getAuthorities().stream().map(authority -> authorityConversionService.convert(authority)).collect(Collectors.toCollection(HashSet::new))); representation.setGrantTypes(client.getGrantTypes().stream().map(grantType -> grantTypeConversionService.convert(grantType)).collect(Collectors.toCollection(HashSet::new))); representation.setScopes(client.getScopes().stream().map(scope -> scopeConversionService.convert(scope)).collect(Collectors.toCollection(HashSet::new))); representation.setRedirectUri(client.getRedirectUri()); representation.setAccessTokenValiditySeconds(client.getAccessTokenValiditySeconds()); representation.setRefreshTokenValiditySeconds(client.getRefreshTokenValiditySeconds()); return representation; } }
ClientConversionService { public ClientRepresentation convert(Client client) { ClientRepresentation representation = new ClientRepresentation(); representation.setId(client.getId()); representation.setCreated(client.getCreated()); representation.setUpdated(client.getUpdated()); representation.setClientId(client.getClientId()); representation.setName(client.getName()); representation.setDescription(client.getDescription()); representation.setAudiences(client.getAudiences().stream().map(audience -> audienceConversionService.convert(audience)).collect(Collectors.toCollection(HashSet::new))); representation.setAuthorities(client.getAuthorities().stream().map(authority -> authorityConversionService.convert(authority)).collect(Collectors.toCollection(HashSet::new))); representation.setGrantTypes(client.getGrantTypes().stream().map(grantType -> grantTypeConversionService.convert(grantType)).collect(Collectors.toCollection(HashSet::new))); representation.setScopes(client.getScopes().stream().map(scope -> scopeConversionService.convert(scope)).collect(Collectors.toCollection(HashSet::new))); representation.setRedirectUri(client.getRedirectUri()); representation.setAccessTokenValiditySeconds(client.getAccessTokenValiditySeconds()); representation.setRefreshTokenValiditySeconds(client.getRefreshTokenValiditySeconds()); return representation; } @Autowired  ClientConversionService(ScopeConversionService scopeConversionService, GrantTypeConversionService grantTypeConversionService, AuthorityConversionService authorityConversionService, AudienceConversionService audienceConversionService, AuthorityService authorityService, AudienceService audienceService, ScopeService scopeService, GrantTypeService grantTypeService); }
ClientConversionService { public ClientRepresentation convert(Client client) { ClientRepresentation representation = new ClientRepresentation(); representation.setId(client.getId()); representation.setCreated(client.getCreated()); representation.setUpdated(client.getUpdated()); representation.setClientId(client.getClientId()); representation.setName(client.getName()); representation.setDescription(client.getDescription()); representation.setAudiences(client.getAudiences().stream().map(audience -> audienceConversionService.convert(audience)).collect(Collectors.toCollection(HashSet::new))); representation.setAuthorities(client.getAuthorities().stream().map(authority -> authorityConversionService.convert(authority)).collect(Collectors.toCollection(HashSet::new))); representation.setGrantTypes(client.getGrantTypes().stream().map(grantType -> grantTypeConversionService.convert(grantType)).collect(Collectors.toCollection(HashSet::new))); representation.setScopes(client.getScopes().stream().map(scope -> scopeConversionService.convert(scope)).collect(Collectors.toCollection(HashSet::new))); representation.setRedirectUri(client.getRedirectUri()); representation.setAccessTokenValiditySeconds(client.getAccessTokenValiditySeconds()); representation.setRefreshTokenValiditySeconds(client.getRefreshTokenValiditySeconds()); return representation; } @Autowired  ClientConversionService(ScopeConversionService scopeConversionService, GrantTypeConversionService grantTypeConversionService, AuthorityConversionService authorityConversionService, AudienceConversionService audienceConversionService, AuthorityService authorityService, AudienceService audienceService, ScopeService scopeService, GrantTypeService grantTypeService); ClientRepresentation convert(Client client); Client convert(ClientRepresentation representation); Client convert(ClientRepresentation representation, Client client); }
ClientConversionService { public ClientRepresentation convert(Client client) { ClientRepresentation representation = new ClientRepresentation(); representation.setId(client.getId()); representation.setCreated(client.getCreated()); representation.setUpdated(client.getUpdated()); representation.setClientId(client.getClientId()); representation.setName(client.getName()); representation.setDescription(client.getDescription()); representation.setAudiences(client.getAudiences().stream().map(audience -> audienceConversionService.convert(audience)).collect(Collectors.toCollection(HashSet::new))); representation.setAuthorities(client.getAuthorities().stream().map(authority -> authorityConversionService.convert(authority)).collect(Collectors.toCollection(HashSet::new))); representation.setGrantTypes(client.getGrantTypes().stream().map(grantType -> grantTypeConversionService.convert(grantType)).collect(Collectors.toCollection(HashSet::new))); representation.setScopes(client.getScopes().stream().map(scope -> scopeConversionService.convert(scope)).collect(Collectors.toCollection(HashSet::new))); representation.setRedirectUri(client.getRedirectUri()); representation.setAccessTokenValiditySeconds(client.getAccessTokenValiditySeconds()); representation.setRefreshTokenValiditySeconds(client.getRefreshTokenValiditySeconds()); return representation; } @Autowired  ClientConversionService(ScopeConversionService scopeConversionService, GrantTypeConversionService grantTypeConversionService, AuthorityConversionService authorityConversionService, AudienceConversionService audienceConversionService, AuthorityService authorityService, AudienceService audienceService, ScopeService scopeService, GrantTypeService grantTypeService); ClientRepresentation convert(Client client); Client convert(ClientRepresentation representation); Client convert(ClientRepresentation representation, Client client);  }