@Test public void shouldBeAbleToConvertAClientRepresentationIntoANewClient() { Authority authority = authority().save(); Audience audience = audience().save(); Scope scope = scope().save(); GrantType grantType = grantType().save(); ClientRepresentation representation = ClientDSL.client().withDescription("desc").withAudiences(audienceConversionService.convert(audience)).withAuthorities(authorityConversionService.convert(authority)).withScopes(scopeConversionService.convert(scope)).withGrantTypes(grantTypeConversionService.convert(grantType)).build(); Client client = clientConversionService.convert(representation); assertThat(client.getAuthorities()).hasSize(1); assertThat(client.getAuthorities()).contains(authority); assertThat(client.getAudiences()).hasSize(1); assertThat(client.getAudiences()).contains(audience); assertThat(client.getGrantTypes()).hasSize(1); assertThat(client.getGrantTypes()).contains(grantType); assertThat(client.getScopes()).hasSize(1); assertThat(client.getScopes()).contains(scope); assertThat(client.getDescription()).isEqualTo("desc"); assertThat(client.getAccessTokenValiditySeconds()).isEqualTo(representation.getAccessTokenValiditySeconds()); assertThat(client.getRefreshTokenValiditySeconds()).isEqualTo(representation.getRefreshTokenValiditySeconds()); assertThat(client.getClientId()).isEqualTo(representation.getClientId()); assertThat(client.getClientSecret()).isEqualTo(representation.getClientSecret()); }
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);  }