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