@Test public void testProviderMetadataWithUpdatedEndpointUpdatesAndRetainsAllDefaultPropertiesExceptEndpoint() { ProviderMetadata md = forApiOnEndpoint(IntegrationTestClient.class, "http: Properties props = new Properties(); props.putAll(md.getDefaultProperties()); props.setProperty(Constants.PROPERTY_ENDPOINT, "http: ProviderMetadata newMd = new UpdateProviderMetadataFromProperties(md).apply(props); assertEquals(newMd.getEndpoint(), "http: assertEquals(newMd.getDefaultProperties(), md.getDefaultProperties()); }
@Override public ProviderMetadata apply(Properties input) { Properties mutable = new Properties(); mutable.putAll(input); ApiMetadata apiMetadata = this.apiMetadata.toBuilder() .name(getAndRemove(mutable, PROPERTY_API, this.apiMetadata.getName())) .version(getAndRemove(mutable, PROPERTY_API_VERSION, this.apiMetadata.getVersion())) .buildVersion(getAndRemove(mutable, PROPERTY_BUILD_VERSION, this.apiMetadata.getBuildVersion().orNull())).build(); String endpoint = getAndRemove(mutable, PROPERTY_ENDPOINT, providerMetadata.isPresent() ? providerMetadata.get() .getEndpoint() : null); String providerId = getAndRemove(mutable, PROPERTY_PROVIDER, providerMetadata.isPresent() ? providerMetadata.get() .getId() : apiMetadata.getId()); String isoCodes = getAndRemove(mutable, PROPERTY_ISO3166_CODES, providerMetadata.isPresent() ? Joiner.on(',').join(providerMetadata.get() .getIso3166Codes()) : ""); ProviderMetadata providerMetadata = this.providerMetadata .or(AnonymousProviderMetadata.forApiWithEndpoint(apiMetadata, checkNotNull(endpoint, PROPERTY_ENDPOINT))) .toBuilder() .apiMetadata(apiMetadata) .id(providerId) .iso3166Codes(Splitter.on(',').omitEmptyStrings().split(isoCodes)) .endpoint(endpoint).defaultProperties(mutable).build(); return providerMetadata; }
UpdateProviderMetadataFromProperties implements Function<Properties, ProviderMetadata> { @Override public ProviderMetadata apply(Properties input) { Properties mutable = new Properties(); mutable.putAll(input); ApiMetadata apiMetadata = this.apiMetadata.toBuilder() .name(getAndRemove(mutable, PROPERTY_API, this.apiMetadata.getName())) .version(getAndRemove(mutable, PROPERTY_API_VERSION, this.apiMetadata.getVersion())) .buildVersion(getAndRemove(mutable, PROPERTY_BUILD_VERSION, this.apiMetadata.getBuildVersion().orNull())).build(); String endpoint = getAndRemove(mutable, PROPERTY_ENDPOINT, providerMetadata.isPresent() ? providerMetadata.get() .getEndpoint() : null); String providerId = getAndRemove(mutable, PROPERTY_PROVIDER, providerMetadata.isPresent() ? providerMetadata.get() .getId() : apiMetadata.getId()); String isoCodes = getAndRemove(mutable, PROPERTY_ISO3166_CODES, providerMetadata.isPresent() ? Joiner.on(',').join(providerMetadata.get() .getIso3166Codes()) : ""); ProviderMetadata providerMetadata = this.providerMetadata .or(AnonymousProviderMetadata.forApiWithEndpoint(apiMetadata, checkNotNull(endpoint, PROPERTY_ENDPOINT))) .toBuilder() .apiMetadata(apiMetadata) .id(providerId) .iso3166Codes(Splitter.on(',').omitEmptyStrings().split(isoCodes)) .endpoint(endpoint).defaultProperties(mutable).build(); return providerMetadata; } }
UpdateProviderMetadataFromProperties implements Function<Properties, ProviderMetadata> { @Override public ProviderMetadata apply(Properties input) { Properties mutable = new Properties(); mutable.putAll(input); ApiMetadata apiMetadata = this.apiMetadata.toBuilder() .name(getAndRemove(mutable, PROPERTY_API, this.apiMetadata.getName())) .version(getAndRemove(mutable, PROPERTY_API_VERSION, this.apiMetadata.getVersion())) .buildVersion(getAndRemove(mutable, PROPERTY_BUILD_VERSION, this.apiMetadata.getBuildVersion().orNull())).build(); String endpoint = getAndRemove(mutable, PROPERTY_ENDPOINT, providerMetadata.isPresent() ? providerMetadata.get() .getEndpoint() : null); String providerId = getAndRemove(mutable, PROPERTY_PROVIDER, providerMetadata.isPresent() ? providerMetadata.get() .getId() : apiMetadata.getId()); String isoCodes = getAndRemove(mutable, PROPERTY_ISO3166_CODES, providerMetadata.isPresent() ? Joiner.on(',').join(providerMetadata.get() .getIso3166Codes()) : ""); ProviderMetadata providerMetadata = this.providerMetadata .or(AnonymousProviderMetadata.forApiWithEndpoint(apiMetadata, checkNotNull(endpoint, PROPERTY_ENDPOINT))) .toBuilder() .apiMetadata(apiMetadata) .id(providerId) .iso3166Codes(Splitter.on(',').omitEmptyStrings().split(isoCodes)) .endpoint(endpoint).defaultProperties(mutable).build(); return providerMetadata; } UpdateProviderMetadataFromProperties(ProviderMetadata providerMetadata);  UpdateProviderMetadataFromProperties(ApiMetadata apiMetadata);  UpdateProviderMetadataFromProperties(ApiMetadata apiMetadata, Optional<ProviderMetadata> providerMetadata); }
UpdateProviderMetadataFromProperties implements Function<Properties, ProviderMetadata> { @Override public ProviderMetadata apply(Properties input) { Properties mutable = new Properties(); mutable.putAll(input); ApiMetadata apiMetadata = this.apiMetadata.toBuilder() .name(getAndRemove(mutable, PROPERTY_API, this.apiMetadata.getName())) .version(getAndRemove(mutable, PROPERTY_API_VERSION, this.apiMetadata.getVersion())) .buildVersion(getAndRemove(mutable, PROPERTY_BUILD_VERSION, this.apiMetadata.getBuildVersion().orNull())).build(); String endpoint = getAndRemove(mutable, PROPERTY_ENDPOINT, providerMetadata.isPresent() ? providerMetadata.get() .getEndpoint() : null); String providerId = getAndRemove(mutable, PROPERTY_PROVIDER, providerMetadata.isPresent() ? providerMetadata.get() .getId() : apiMetadata.getId()); String isoCodes = getAndRemove(mutable, PROPERTY_ISO3166_CODES, providerMetadata.isPresent() ? Joiner.on(',').join(providerMetadata.get() .getIso3166Codes()) : ""); ProviderMetadata providerMetadata = this.providerMetadata .or(AnonymousProviderMetadata.forApiWithEndpoint(apiMetadata, checkNotNull(endpoint, PROPERTY_ENDPOINT))) .toBuilder() .apiMetadata(apiMetadata) .id(providerId) .iso3166Codes(Splitter.on(',').omitEmptyStrings().split(isoCodes)) .endpoint(endpoint).defaultProperties(mutable).build(); return providerMetadata; } UpdateProviderMetadataFromProperties(ProviderMetadata providerMetadata);  UpdateProviderMetadataFromProperties(ApiMetadata apiMetadata);  UpdateProviderMetadataFromProperties(ApiMetadata apiMetadata, Optional<ProviderMetadata> providerMetadata); @Override ProviderMetadata apply(Properties input); }
UpdateProviderMetadataFromProperties implements Function<Properties, ProviderMetadata> { @Override public ProviderMetadata apply(Properties input) { Properties mutable = new Properties(); mutable.putAll(input); ApiMetadata apiMetadata = this.apiMetadata.toBuilder() .name(getAndRemove(mutable, PROPERTY_API, this.apiMetadata.getName())) .version(getAndRemove(mutable, PROPERTY_API_VERSION, this.apiMetadata.getVersion())) .buildVersion(getAndRemove(mutable, PROPERTY_BUILD_VERSION, this.apiMetadata.getBuildVersion().orNull())).build(); String endpoint = getAndRemove(mutable, PROPERTY_ENDPOINT, providerMetadata.isPresent() ? providerMetadata.get() .getEndpoint() : null); String providerId = getAndRemove(mutable, PROPERTY_PROVIDER, providerMetadata.isPresent() ? providerMetadata.get() .getId() : apiMetadata.getId()); String isoCodes = getAndRemove(mutable, PROPERTY_ISO3166_CODES, providerMetadata.isPresent() ? Joiner.on(',').join(providerMetadata.get() .getIso3166Codes()) : ""); ProviderMetadata providerMetadata = this.providerMetadata .or(AnonymousProviderMetadata.forApiWithEndpoint(apiMetadata, checkNotNull(endpoint, PROPERTY_ENDPOINT))) .toBuilder() .apiMetadata(apiMetadata) .id(providerId) .iso3166Codes(Splitter.on(',').omitEmptyStrings().split(isoCodes)) .endpoint(endpoint).defaultProperties(mutable).build(); return providerMetadata; } UpdateProviderMetadataFromProperties(ProviderMetadata providerMetadata);  UpdateProviderMetadataFromProperties(ApiMetadata apiMetadata);  UpdateProviderMetadataFromProperties(ApiMetadata apiMetadata, Optional<ProviderMetadata> providerMetadata); @Override ProviderMetadata apply(Properties input);  }