From 21ce5b3ab2d6096199d5c2da9379769ed3600b9c Mon Sep 17 00:00:00 2001 From: yiliu6 Date: Tue, 25 Oct 2022 16:34:04 +0800 Subject: [PATCH 01/11] fix sources cannot be appended --- ...ingServicePropertiesBeanPostProcessor.java | 28 +++++++++++++++++-- ...afkaBinderOAuth2AutoConfigurationTest.java | 4 +-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java index 1862fb6ae2ac..4bef94d52b01 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java @@ -4,6 +4,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.cloud.stream.binder.DefaultBinderFactory; import org.springframework.cloud.stream.config.BinderProperties; import org.springframework.cloud.stream.config.BindingServiceProperties; @@ -48,9 +49,12 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro } private String buildKafkaBinderSources(BinderProperties binderProperties) { + Map flattenedProperties = new HashMap<>(); + flatten(null, binderProperties.getEnvironment(), flattenedProperties); + StringBuilder sources = new StringBuilder(AzureKafkaSpringCloudStreamConfiguration.AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS); - if (binderProperties.getEnvironment().get(SPRING_MAIN_SOURCES_PROPERTY) != null) { - sources.append("," + binderProperties.getEnvironment().get(SPRING_MAIN_SOURCES_PROPERTY)); + if (flattenedProperties.get(SPRING_MAIN_SOURCES_PROPERTY) != null) { + sources.append("," + flattenedProperties.get(SPRING_MAIN_SOURCES_PROPERTY)); } return sources.toString(); } @@ -58,4 +62,24 @@ private String buildKafkaBinderSources(BinderProperties binderProperties) { private void configureBinderSources(BinderProperties binderProperties, String sources) { binderProperties.getEnvironment().put(SPRING_MAIN_SOURCES_PROPERTY, sources); } + + /** + * Ensures that nested properties are flattened (i.e., foo.bar=baz instead of + * foo={bar=baz}). Copied from {@link DefaultBinderFactory}. + * @param propertyName property name to flatten + * @param value value that contains the property name + * @param flattenedProperties map to which we'll add the falttened property + */ + @SuppressWarnings("unchecked") + private void flatten(String propertyName, Object value, + Map flattenedProperties) { + if (value instanceof Map) { + ((Map) value).forEach((k, v) -> flatten( + (propertyName != null ? propertyName + "." : "") + k, v, + flattenedProperties)); + } + else { + flattenedProperties.put(propertyName, value.toString()); + } + } } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java index 278df9dfaf34..f2a9d958b8bc 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java @@ -62,13 +62,13 @@ void shouldConfigureWithKafkaBinderConfigurationClass() { @Test void shouldConfigureWhenBinderNameSpecified() { this.contextRunner - .withPropertyValues("spring.cloud.stream.binders.kafka.environment.key=value") + .withPropertyValues("spring.cloud.stream.binders.kafka.environment.spring.main.sources=value") .run(context -> { assertThat(context).hasSingleBean(AzureEventHubsKafkaBinderOAuth2AutoConfiguration.class); assertThat(context).hasSingleBean(BindingServicePropertiesBeanPostProcessor.class); assertThat(context).hasSingleBean(BindingServiceProperties.class); - testBinderSources(context.getBean(BindingServiceProperties.class), "kafka", AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS); + testBinderSources(context.getBean(BindingServiceProperties.class), "kafka", AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS + ",value" ); }); } From beca90dae9a06e5185f748a3222d2ff1e40704d4 Mon Sep 17 00:00:00 2001 From: yiliu6 Date: Tue, 25 Oct 2022 16:37:54 +0800 Subject: [PATCH 02/11] add changelog --- sdk/spring/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/spring/CHANGELOG.md b/sdk/spring/CHANGELOG.md index eeaf3d1745c2..8af0ccf8aa64 100644 --- a/sdk/spring/CHANGELOG.md +++ b/sdk/spring/CHANGELOG.md @@ -9,6 +9,7 @@ Upgrade Spring Boot dependencies version to 2.7.4 and Spring Cloud dependencies - Fix bug: RestOperations is not well configured when jwkResolver is null. [#31218](https://github.com/Azure/azure-sdk-for-java/issues/31218). - Fix bug: Duplicated "scope" parameter. [#31191](https://github.com/Azure/azure-sdk-for-java/issues/31191). - Fix bug: NimbusJwtDecoder still uses `RestTemplate()` instead `RestTemplateBuilder` [#31233](https://github.com/Azure/azure-sdk-for-java/issues/31233) +- Fix bug: `spring.main.sources` configuration from Spring Cloud Stream Kafka binder cannot take effect. [#31715](https://github.com/Azure/azure-sdk-for-java/pull/31715) ## 4.4.0 (2022-09-26) Upgrade Spring Boot dependencies version to 2.7.3 and Spring Cloud dependencies version to 2021.0.3 From 7efce9c6f3fb69b503e37a5061f91602377e862c Mon Sep 17 00:00:00 2001 From: yiliu6 Date: Tue, 25 Oct 2022 16:59:32 +0800 Subject: [PATCH 03/11] fix checkstyle --- .../kafka/BindingServicePropertiesBeanPostProcessor.java | 3 +-- .../AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java index 4bef94d52b01..d38eb2b2158e 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java @@ -77,8 +77,7 @@ private void flatten(String propertyName, Object value, ((Map) value).forEach((k, v) -> flatten( (propertyName != null ? propertyName + "." : "") + k, v, flattenedProperties)); - } - else { + } else { flattenedProperties.put(propertyName, value.toString()); } } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java index f2a9d958b8bc..54d15151d1da 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java @@ -68,7 +68,7 @@ void shouldConfigureWhenBinderNameSpecified() { assertThat(context).hasSingleBean(BindingServicePropertiesBeanPostProcessor.class); assertThat(context).hasSingleBean(BindingServiceProperties.class); - testBinderSources(context.getBean(BindingServiceProperties.class), "kafka", AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS + ",value" ); + testBinderSources(context.getBean(BindingServiceProperties.class), "kafka", AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS + ",value"); }); } From d59fa73ef1622380c61dedf491b1b0a07a9e7201 Mon Sep 17 00:00:00 2001 From: yiliu6 Date: Tue, 25 Oct 2022 17:14:25 +0800 Subject: [PATCH 04/11] fix changelog error --- sdk/spring/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/spring/CHANGELOG.md b/sdk/spring/CHANGELOG.md index 458b5319257e..c162c4b7b12f 100644 --- a/sdk/spring/CHANGELOG.md +++ b/sdk/spring/CHANGELOG.md @@ -478,7 +478,7 @@ This section includes changes in the `spring-cloud-azure-autoconfigure` module. * Property name "spring.cloud.azure.active-directory.graph-base-uri" changed to "spring.cloud.azure.active-directory.profile.environment.microsoft-graph-endpoint". * Property name "spring.cloud.azure.active-directory.graph-membership-uri" changed to "spring.cloud.azure.active-directory.profile.environment.microsoft-graph-endpoint" and "spring.cloud.azure.active-directory.user-group.use-transitive-members". - Change AAD B2C configuration properties to use the namespace for credential and environment properties [#25799](https://github.com/Azure/azure-sdk-for-java/pull/25799). -- Change Event Hubs processor configuration properties `spring.cloud.azure.eventhbs.processor.partition-ownership-expiration-interval` to `spring.cloud.azure.eventhbs.processor.load-balancing.partition-ownership-expiration-interval` [#25851](https://github.com/Azure/azure-sdk-for-java/pull/25851). +- Change Event Hubs processor configuration properties `spring.cloud.azure.eventhubs.processor.partition-ownership-expiration-interval` to `spring.cloud.azure.eventhubs.processor.load-balancing.partition-ownership-expiration-interval` [#25851](https://github.com/Azure/azure-sdk-for-java/pull/25851). - Change Event Hubs configuration properties `spring.cloud.azure.eventhubs.fqdn` to `spring.cloud.azure.eventhubs.fully-qualified-namespace` [#25851](https://github.com/Azure/azure-sdk-for-java/pull/25851). - Rename all `*CP` classes to `*ConfigurationProperties` [#26209](https://github.com/Azure/azure-sdk-for-java/pull/26209). From 02cbda9ef3956df4924ec3141cae053747062087 Mon Sep 17 00:00:00 2001 From: yiliu6 Date: Thu, 27 Oct 2022 09:29:18 +0800 Subject: [PATCH 05/11] modify the way to read/write spring.main.sources --- ...ingServicePropertiesBeanPostProcessor.java | 52 ++++++++--------- ...afkaBinderOAuth2AutoConfigurationTest.java | 58 +++++++++++++------ 2 files changed, 64 insertions(+), 46 deletions(-) diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java index d38eb2b2158e..e3c065a40865 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java @@ -4,11 +4,12 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.cloud.stream.binder.DefaultBinderFactory; import org.springframework.cloud.stream.config.BinderProperties; import org.springframework.cloud.stream.config.BindingServiceProperties; +import org.springframework.util.StringUtils; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; /** @@ -29,7 +30,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro BindingServiceProperties bindingServiceProperties = (BindingServiceProperties) bean; if (bindingServiceProperties.getBinders().isEmpty()) { BinderProperties kafkaBinderSourceProperty = new BinderProperties(); - configureBinderSources(kafkaBinderSourceProperty, AzureKafkaSpringCloudStreamConfiguration.AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS); + configureBinderSources(kafkaBinderSourceProperty); Map kafkaBinderPropertyMap = new HashMap<>(); kafkaBinderPropertyMap.put(KAKFA_BINDER_DEFAULT_NAME, kafkaBinderSourceProperty); @@ -40,7 +41,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro if (entry.getKey() != null && entry.getValue() != null && (KAKFA_BINDER_TYPE.equalsIgnoreCase(entry.getValue().getType()) || KAKFA_BINDER_DEFAULT_NAME.equalsIgnoreCase(entry.getKey()))) { - configureBinderSources(entry.getValue(), buildKafkaBinderSources(entry.getValue())); + configureBinderSources(entry.getValue()); } } } @@ -48,37 +49,32 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro return bean; } - private String buildKafkaBinderSources(BinderProperties binderProperties) { - Map flattenedProperties = new HashMap<>(); - flatten(null, binderProperties.getEnvironment(), flattenedProperties); - + private void configureBinderSources(BinderProperties binderProperties) { + Map originalSources = readSpringMainPropertiesMap(binderProperties.getEnvironment()); StringBuilder sources = new StringBuilder(AzureKafkaSpringCloudStreamConfiguration.AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS); - if (flattenedProperties.get(SPRING_MAIN_SOURCES_PROPERTY) != null) { - sources.append("," + flattenedProperties.get(SPRING_MAIN_SOURCES_PROPERTY)); + if (StringUtils.hasText((String) originalSources.get("sources"))) { + sources.append("," + originalSources.get("sources")); } - return sources.toString(); + originalSources.put("sources", sources.toString()); } - private void configureBinderSources(BinderProperties binderProperties, String sources) { - binderProperties.getEnvironment().put(SPRING_MAIN_SOURCES_PROPERTY, sources); - } - - /** - * Ensures that nested properties are flattened (i.e., foo.bar=baz instead of - * foo={bar=baz}). Copied from {@link DefaultBinderFactory}. - * @param propertyName property name to flatten - * @param value value that contains the property name - * @param flattenedProperties map to which we'll add the falttened property - */ @SuppressWarnings("unchecked") - private void flatten(String propertyName, Object value, - Map flattenedProperties) { - if (value instanceof Map) { - ((Map) value).forEach((k, v) -> flatten( - (propertyName != null ? propertyName + "." : "") + k, v, - flattenedProperties)); + static Map readSpringMainPropertiesMap(Map map) { + + if (map.containsKey("spring")) { + Map spring = (Map) map.get("spring"); + if (spring.containsKey("main")) { + return (Map) spring.get("main"); + } else { + LinkedHashMap main = new LinkedHashMap<>(); + spring.put("main", main); + return main; + } } else { - flattenedProperties.put(propertyName, value.toString()); + Map main = new LinkedHashMap<>(); + Map spring = new LinkedHashMap() {{ put("main", main); }}; + map.put("spring", spring); + return main; } } } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java index 54d15151d1da..febd469dab24 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java @@ -2,19 +2,21 @@ // Licensed under the MIT License. package com.azure.spring.cloud.autoconfigure.kafka; +import java.util.Map; + import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.cloud.stream.binder.kafka.config.KafkaBinderConfiguration; import org.springframework.cloud.stream.config.BinderFactoryAutoConfiguration; -import org.springframework.cloud.stream.config.BinderProperties; import org.springframework.cloud.stream.config.BindingServiceProperties; import org.springframework.context.support.ConversionServiceFactoryBean; import org.springframework.integration.support.utils.IntegrationUtils; import static com.azure.spring.cloud.autoconfigure.kafka.AzureKafkaSpringCloudStreamConfiguration.AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS; import static com.azure.spring.cloud.autoconfigure.kafka.BindingServicePropertiesBeanPostProcessor.SPRING_MAIN_SOURCES_PROPERTY; +import static com.azure.spring.cloud.autoconfigure.kafka.BindingServicePropertiesBeanPostProcessor.readSpringMainPropertiesMap; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -62,13 +64,44 @@ void shouldConfigureWithKafkaBinderConfigurationClass() { @Test void shouldConfigureWhenBinderNameSpecified() { this.contextRunner - .withPropertyValues("spring.cloud.stream.binders.kafka.environment.spring.main.sources=value") + .withPropertyValues("spring.cloud.stream.binders.kafka.environment.key=value") .run(context -> { assertThat(context).hasSingleBean(AzureEventHubsKafkaBinderOAuth2AutoConfiguration.class); assertThat(context).hasSingleBean(BindingServicePropertiesBeanPostProcessor.class); assertThat(context).hasSingleBean(BindingServiceProperties.class); - testBinderSources(context.getBean(BindingServiceProperties.class), "kafka", AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS + ",value"); + testBinderSources(context.getBean(BindingServiceProperties.class), "kafka", AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS); + assertEquals("value", context.getBean(BindingServiceProperties.class).getBinders().get("kafka").getEnvironment().get("key")); + }); + } + + @Test + @SuppressWarnings("unchecked") + void shouldConfigureWhenOtherSpringEnvironmentSpecified() { + this.contextRunner + .withPropertyValues("spring.cloud.stream.binders.kafka.environment.spring.profiles.active=value") + .run(context -> { + assertThat(context).hasSingleBean(AzureEventHubsKafkaBinderOAuth2AutoConfiguration.class); + assertThat(context).hasSingleBean(BindingServicePropertiesBeanPostProcessor.class); + assertThat(context).hasSingleBean(BindingServiceProperties.class); + + testBinderSources(context.getBean(BindingServiceProperties.class), "kafka", AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS); + assertEquals("value", ((Map>) context.getBean(BindingServiceProperties.class).getBinders().get("kafka").getEnvironment().get("spring")) + .get("profiles").get("active")); + }); + } + + @Test + void shouldConfigureWhenOtherSpringMainEnvironmentSpecified() { + this.contextRunner + .withPropertyValues("spring.cloud.stream.binders.kafka.environment.spring.main.banner-mode=console") + .run(context -> { + assertThat(context).hasSingleBean(AzureEventHubsKafkaBinderOAuth2AutoConfiguration.class); + assertThat(context).hasSingleBean(BindingServicePropertiesBeanPostProcessor.class); + assertThat(context).hasSingleBean(BindingServiceProperties.class); + + testBinderSources(context.getBean(BindingServiceProperties.class), "kafka", AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS); + assertEquals("console", readSpringMainPropertiesMap(context.getBean(BindingServiceProperties.class).getBinders().get("kafka").getEnvironment()).get("banner-mode")); }); } @@ -107,32 +140,21 @@ void shouldConfigureWithMultipleBinders() { @Test void shouldAppendOriginalSources() { - - new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(AzureEventHubsKafkaBinderOAuth2AutoConfiguration.class)) - .withBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, ConversionServiceFactoryBean.class, - ConversionServiceFactoryBean::new) - .withBean(BindingServiceProperties.class, () -> { - BindingServiceProperties bindingServiceProperties = new BindingServiceProperties(); - BinderProperties kafkaBinderSourceProperty = new BinderProperties(); - kafkaBinderSourceProperty.getEnvironment().put(SPRING_MAIN_SOURCES_PROPERTY, "test"); - bindingServiceProperties.getBinders().put("kafka", kafkaBinderSourceProperty); - return bindingServiceProperties; - }) + this.contextRunner + .withPropertyValues("spring.cloud.stream.binders.kafka.environment.spring.main.sources=value") .run(context -> { assertThat(context).hasSingleBean(AzureEventHubsKafkaBinderOAuth2AutoConfiguration.class); assertThat(context).hasSingleBean(BindingServicePropertiesBeanPostProcessor.class); assertThat(context).hasSingleBean(BindingServiceProperties.class); - testBinderSources(context.getBean(BindingServiceProperties.class), "kafka", AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS + ",test"); + testBinderSources(context.getBean(BindingServiceProperties.class), "kafka", AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS + ",value"); }); } private void testBinderSources(BindingServiceProperties bindingServiceProperties, String binderName, String binderSources) { assertFalse(bindingServiceProperties.getBinders().isEmpty()); assertNotNull(bindingServiceProperties.getBinders().get(binderName)); - assertEquals(binderSources, - bindingServiceProperties.getBinders().get(binderName).getEnvironment().get(SPRING_MAIN_SOURCES_PROPERTY)); + assertEquals(binderSources, readSpringMainPropertiesMap(bindingServiceProperties.getBinders().get(binderName).getEnvironment()).get("sources")); } From 53a36de75c3d18000d1702af02a7da1a461681a5 Mon Sep 17 00:00:00 2001 From: yiliu6 Date: Thu, 27 Oct 2022 17:05:49 +0800 Subject: [PATCH 06/11] add tests --- ...ingServicePropertiesBeanPostProcessor.java | 11 +- ...afkaBinderOAuth2AutoConfigurationTest.java | 6 +- ...ervicePropertiesBeanPostProcessorTest.java | 113 ++++++++++++++++++ 3 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java index e3c065a40865..fd0337e23d1f 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java @@ -30,7 +30,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro BindingServiceProperties bindingServiceProperties = (BindingServiceProperties) bean; if (bindingServiceProperties.getBinders().isEmpty()) { BinderProperties kafkaBinderSourceProperty = new BinderProperties(); - configureBinderSources(kafkaBinderSourceProperty); + configureBinderSources(readSpringMainPropertiesMap(kafkaBinderSourceProperty.getEnvironment())); Map kafkaBinderPropertyMap = new HashMap<>(); kafkaBinderPropertyMap.put(KAKFA_BINDER_DEFAULT_NAME, kafkaBinderSourceProperty); @@ -41,7 +41,8 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro if (entry.getKey() != null && entry.getValue() != null && (KAKFA_BINDER_TYPE.equalsIgnoreCase(entry.getValue().getType()) || KAKFA_BINDER_DEFAULT_NAME.equalsIgnoreCase(entry.getKey()))) { - configureBinderSources(entry.getValue()); + readSpringMainPropertiesMap(entry.getValue().getEnvironment()); + configureBinderSources(readSpringMainPropertiesMap(entry.getValue().getEnvironment())); } } } @@ -49,8 +50,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro return bean; } - private void configureBinderSources(BinderProperties binderProperties) { - Map originalSources = readSpringMainPropertiesMap(binderProperties.getEnvironment()); + void configureBinderSources(Map originalSources) { StringBuilder sources = new StringBuilder(AzureKafkaSpringCloudStreamConfiguration.AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS); if (StringUtils.hasText((String) originalSources.get("sources"))) { sources.append("," + originalSources.get("sources")); @@ -59,8 +59,7 @@ private void configureBinderSources(BinderProperties binderProperties) { } @SuppressWarnings("unchecked") - static Map readSpringMainPropertiesMap(Map map) { - + Map readSpringMainPropertiesMap(Map map) { if (map.containsKey("spring")) { Map spring = (Map) map.get("spring"); if (spring.containsKey("main")) { diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java index febd469dab24..560c0b268692 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java @@ -16,7 +16,6 @@ import static com.azure.spring.cloud.autoconfigure.kafka.AzureKafkaSpringCloudStreamConfiguration.AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS; import static com.azure.spring.cloud.autoconfigure.kafka.BindingServicePropertiesBeanPostProcessor.SPRING_MAIN_SOURCES_PROPERTY; -import static com.azure.spring.cloud.autoconfigure.kafka.BindingServicePropertiesBeanPostProcessor.readSpringMainPropertiesMap; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -30,6 +29,7 @@ class AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest { // Required by the init method of BindingServiceProperties .withBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, ConversionServiceFactoryBean.class, ConversionServiceFactoryBean::new); + private final BindingServicePropertiesBeanPostProcessor bpp = new BindingServicePropertiesBeanPostProcessor(); @Test void shouldNotConfigureWithoutKafkaBinderConfigurationClass() { @@ -101,7 +101,7 @@ void shouldConfigureWhenOtherSpringMainEnvironmentSpecified() { assertThat(context).hasSingleBean(BindingServiceProperties.class); testBinderSources(context.getBean(BindingServiceProperties.class), "kafka", AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS); - assertEquals("console", readSpringMainPropertiesMap(context.getBean(BindingServiceProperties.class).getBinders().get("kafka").getEnvironment()).get("banner-mode")); + assertEquals("console", bpp.readSpringMainPropertiesMap(context.getBean(BindingServiceProperties.class).getBinders().get("kafka").getEnvironment()).get("banner-mode")); }); } @@ -154,7 +154,7 @@ void shouldAppendOriginalSources() { private void testBinderSources(BindingServiceProperties bindingServiceProperties, String binderName, String binderSources) { assertFalse(bindingServiceProperties.getBinders().isEmpty()); assertNotNull(bindingServiceProperties.getBinders().get(binderName)); - assertEquals(binderSources, readSpringMainPropertiesMap(bindingServiceProperties.getBinders().get(binderName).getEnvironment()).get("sources")); + assertEquals(binderSources, bpp.readSpringMainPropertiesMap(bindingServiceProperties.getBinders().get(binderName).getEnvironment()).get("sources")); } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java new file mode 100644 index 000000000000..39092571220a --- /dev/null +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java @@ -0,0 +1,113 @@ +package com.azure.spring.cloud.autoconfigure.kafka; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.cloud.stream.config.BinderProperties; +import org.springframework.cloud.stream.config.BindingServiceProperties; + +import static com.azure.spring.cloud.autoconfigure.kafka.AzureKafkaSpringCloudStreamConfiguration.AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; + +@SuppressWarnings("unchecked") +class BindingServicePropertiesBeanPostProcessorTest { + + private final BindingServicePropertiesBeanPostProcessor bpp = new BindingServicePropertiesBeanPostProcessor(); + + @Test + void testReadSpringMainPropertiesMapWithoutOriginalValues() { + Map env = new LinkedHashMap<>(); + Map mainPropertiesMap = bpp.readSpringMainPropertiesMap(env); + assertSame(mainPropertiesMap, ((Map) env.get("spring")).get("main")); + } + + @Test + void testReadSpringMainPropertiesMapWithSpringProp() { + Map env = new LinkedHashMap<>(); + Map mainPropertiesMap = buildSpringMainPropertiesMap(env, "profiles", "active", "dev"); + + assertEquals("dev", ((Map>) env.get("spring")).get("profiles").get("active")); + assertSame(mainPropertiesMap, ((Map) env.get("spring")).get("main")); + } + + @Test + void testReadSpringMainPropertiesMapWithMainProp() { + Map env = new LinkedHashMap<>(); + Map mainPropertiesMap = buildSpringMainPropertiesMap(env, "main", "banner-mode", "test"); + + assertEquals("test", ((Map>) env.get("spring")).get("main").get("banner-mode")); + assertSame(mainPropertiesMap, ((Map) env.get("spring")).get("main")); + } + + @Test + void testReadSpringMainPropertiesMapWithSourcesProp() { + Map env = new LinkedHashMap<>(); + Map mainPropertiesMap = buildSpringMainPropertiesMap(env, "main", "sources", "test"); + + assertEquals("test", ((Map>) env.get("spring")).get("main").get("sources")); + assertSame(mainPropertiesMap, ((Map) env.get("spring")).get("main")); + } + + @Test + void testConfigureBinderSources() { + Map env = new LinkedHashMap<>(); + Map mainPropertiesMap = buildSpringMainPropertiesMap(env, "main", "sources", "test"); + bpp.configureBinderSources(mainPropertiesMap); + assertEquals(AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS + ",test", ((Map>) env.get("spring")).get("main").get("sources")); + + env.clear(); + mainPropertiesMap = buildSpringMainPropertiesMap(env, "main", "profiles", "active"); + bpp.configureBinderSources(mainPropertiesMap); + assertEquals(AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS, ((Map>) env.get("spring")).get("main").get("sources")); + } + + @Test + void testBindKafkaByDefault() { + BindingServiceProperties bindingServiceProperties = new BindingServiceProperties(); + bpp.postProcessBeforeInitialization(bindingServiceProperties, null); + Map env = bindingServiceProperties.getBinders().get("kafka") + .getEnvironment(); + assertEquals(AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS, ((Map>) env.get("spring")).get("main").get("sources")); + + } + + @Test + void testBindKafkaByName() { + BinderProperties binderProperties = new BinderProperties(); + Map binders= new HashMap<>() {{ put("kafka", binderProperties); }}; + BindingServiceProperties bindingServiceProperties = new BindingServiceProperties(); + bindingServiceProperties.setBinders(binders); + + bpp.postProcessBeforeInitialization(bindingServiceProperties, null); + Map env = bindingServiceProperties.getBinders().get("kafka") + .getEnvironment(); + assertEquals(AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS, ((Map>) env.get("spring")).get("main").get("sources")); + } + + @Test + void testBindKafkaByType() { + BinderProperties binderProperties = new BinderProperties(); + Map binders= new HashMap<>() {{ put("test", binderProperties); }}; + binderProperties.setType("kafka"); + BindingServiceProperties bindingServiceProperties = new BindingServiceProperties(); + bindingServiceProperties.setBinders(binders); + + bpp.postProcessBeforeInitialization(bindingServiceProperties, null); + Map env = bindingServiceProperties.getBinders().get("test") + .getEnvironment(); + assertEquals(AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS, ((Map>) env.get("spring")).get("main").get("sources")); + } + + private Map buildSpringMainPropertiesMap(Map env, String secondProperty, String thirdProperty, String value) { + Map second = new LinkedHashMap<>(); + second.put(thirdProperty, value); + Map first = new LinkedHashMap() {{ put(secondProperty, second); }}; + env.put("spring", first); + return bpp.readSpringMainPropertiesMap(env); + } + +} From 9b195fc2e512161566cf60c855b5887390ca46df Mon Sep 17 00:00:00 2001 From: yiliu6 Date: Thu, 27 Oct 2022 17:09:45 +0800 Subject: [PATCH 07/11] fix checkstyle --- .../BindingServicePropertiesBeanPostProcessorTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java index 39092571220a..7df074acd9e9 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java @@ -1,3 +1,5 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.spring.cloud.autoconfigure.kafka; import java.util.HashMap; @@ -78,7 +80,7 @@ void testBindKafkaByDefault() { @Test void testBindKafkaByName() { BinderProperties binderProperties = new BinderProperties(); - Map binders= new HashMap<>() {{ put("kafka", binderProperties); }}; + Map binders = new HashMap() {{ put("kafka", binderProperties); }}; BindingServiceProperties bindingServiceProperties = new BindingServiceProperties(); bindingServiceProperties.setBinders(binders); @@ -91,7 +93,7 @@ void testBindKafkaByName() { @Test void testBindKafkaByType() { BinderProperties binderProperties = new BinderProperties(); - Map binders= new HashMap<>() {{ put("test", binderProperties); }}; + Map binders = new HashMap() {{ put("test", binderProperties); }}; binderProperties.setType("kafka"); BindingServiceProperties bindingServiceProperties = new BindingServiceProperties(); bindingServiceProperties.setBinders(binders); From d66f7eba085f8869e3ec441b2c30587062c04c69 Mon Sep 17 00:00:00 2001 From: yiliu6 Date: Thu, 27 Oct 2022 17:23:09 +0800 Subject: [PATCH 08/11] remove duplicated line --- .../kafka/BindingServicePropertiesBeanPostProcessor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java index fd0337e23d1f..544fa15a6a77 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java @@ -41,7 +41,6 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro if (entry.getKey() != null && entry.getValue() != null && (KAKFA_BINDER_TYPE.equalsIgnoreCase(entry.getValue().getType()) || KAKFA_BINDER_DEFAULT_NAME.equalsIgnoreCase(entry.getKey()))) { - readSpringMainPropertiesMap(entry.getValue().getEnvironment()); configureBinderSources(readSpringMainPropertiesMap(entry.getValue().getEnvironment())); } } From 8c2cf93286371923b6d86b3e9715c07c821b27be Mon Sep 17 00:00:00 2001 From: yiliu6 Date: Thu, 27 Oct 2022 22:33:32 +0800 Subject: [PATCH 09/11] supress spotbug error --- .../main/resources/spotbugs/spotbugs-exclude.xml | 6 ++++++ ...tHubsKafkaBinderOAuth2AutoConfigurationTest.java | 4 +++- ...ndingServicePropertiesBeanPostProcessorTest.java | 13 ++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml index 26e5c3ad339b..66025732fbac 100755 --- a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml +++ b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml @@ -2327,6 +2327,12 @@ + + + + + + diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java index 560c0b268692..0cee3fb45b4b 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/AzureEventHubsKafkaBinderOAuth2AutoConfigurationTest.java @@ -92,6 +92,7 @@ void shouldConfigureWhenOtherSpringEnvironmentSpecified() { } @Test + @SuppressWarnings("unchecked") void shouldConfigureWhenOtherSpringMainEnvironmentSpecified() { this.contextRunner .withPropertyValues("spring.cloud.stream.binders.kafka.environment.spring.main.banner-mode=console") @@ -101,7 +102,8 @@ void shouldConfigureWhenOtherSpringMainEnvironmentSpecified() { assertThat(context).hasSingleBean(BindingServiceProperties.class); testBinderSources(context.getBean(BindingServiceProperties.class), "kafka", AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS); - assertEquals("console", bpp.readSpringMainPropertiesMap(context.getBean(BindingServiceProperties.class).getBinders().get("kafka").getEnvironment()).get("banner-mode")); + assertEquals("console", ((Map>) context.getBean(BindingServiceProperties.class).getBinders().get("kafka").getEnvironment().get("spring")) + .get("main").get("banner-mode")); }); } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java index 7df074acd9e9..4d2920409955 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java @@ -10,6 +10,7 @@ import org.springframework.cloud.stream.config.BinderProperties; import org.springframework.cloud.stream.config.BindingServiceProperties; +import org.springframework.util.StringUtils; import static com.azure.spring.cloud.autoconfigure.kafka.AzureKafkaSpringCloudStreamConfiguration.AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -23,7 +24,7 @@ class BindingServicePropertiesBeanPostProcessorTest { @Test void testReadSpringMainPropertiesMapWithoutOriginalValues() { Map env = new LinkedHashMap<>(); - Map mainPropertiesMap = bpp.readSpringMainPropertiesMap(env); + Map mainPropertiesMap = buildSpringMainPropertiesMap(env, null, null, null); assertSame(mainPropertiesMap, ((Map) env.get("spring")).get("main")); } @@ -105,10 +106,12 @@ void testBindKafkaByType() { } private Map buildSpringMainPropertiesMap(Map env, String secondProperty, String thirdProperty, String value) { - Map second = new LinkedHashMap<>(); - second.put(thirdProperty, value); - Map first = new LinkedHashMap() {{ put(secondProperty, second); }}; - env.put("spring", first); + if (StringUtils.hasText(secondProperty)) { + Map second = new LinkedHashMap<>(); + second.put(thirdProperty, value); + Map first = new LinkedHashMap() {{ put(secondProperty, second); }}; + env.put("spring", first); + } return bpp.readSpringMainPropertiesMap(env); } From 4d9a0651844521af92a27604b170d7d37e3933f0 Mon Sep 17 00:00:00 2001 From: yiliu6 Date: Thu, 27 Oct 2022 23:11:20 +0800 Subject: [PATCH 10/11] fix spotbug --- .../src/main/resources/spotbugs/spotbugs-exclude.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml index 66025732fbac..05dd43174e3d 100755 --- a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml +++ b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml @@ -2329,7 +2329,6 @@ - From e868918fb0ed7e67f4db0325131236c97b564bc9 Mon Sep 17 00:00:00 2001 From: yiliu6 Date: Thu, 27 Oct 2022 23:32:05 +0800 Subject: [PATCH 11/11] fix spotbug --- .../src/main/resources/spotbugs/spotbugs-exclude.xml | 5 ----- .../kafka/BindingServicePropertiesBeanPostProcessor.java | 3 ++- .../BindingServicePropertiesBeanPostProcessorTest.java | 9 ++++++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml index 05dd43174e3d..26e5c3ad339b 100755 --- a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml +++ b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml @@ -2327,11 +2327,6 @@ - - - - - diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java index 544fa15a6a77..8229b39f5ccd 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessor.java @@ -70,7 +70,8 @@ Map readSpringMainPropertiesMap(Map map) { } } else { Map main = new LinkedHashMap<>(); - Map spring = new LinkedHashMap() {{ put("main", main); }}; + Map spring = new LinkedHashMap<>(); + spring.put("main", main); map.put("spring", spring); return main; } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java index 4d2920409955..13e2432c584f 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.java @@ -81,7 +81,8 @@ void testBindKafkaByDefault() { @Test void testBindKafkaByName() { BinderProperties binderProperties = new BinderProperties(); - Map binders = new HashMap() {{ put("kafka", binderProperties); }}; + Map binders = new HashMap<>(); + binders.put("kafka", binderProperties); BindingServiceProperties bindingServiceProperties = new BindingServiceProperties(); bindingServiceProperties.setBinders(binders); @@ -94,7 +95,8 @@ void testBindKafkaByName() { @Test void testBindKafkaByType() { BinderProperties binderProperties = new BinderProperties(); - Map binders = new HashMap() {{ put("test", binderProperties); }}; + Map binders = new HashMap<>(); + binders.put("test", binderProperties); binderProperties.setType("kafka"); BindingServiceProperties bindingServiceProperties = new BindingServiceProperties(); bindingServiceProperties.setBinders(binders); @@ -109,7 +111,8 @@ private Map buildSpringMainPropertiesMap(Map env if (StringUtils.hasText(secondProperty)) { Map second = new LinkedHashMap<>(); second.put(thirdProperty, value); - Map first = new LinkedHashMap() {{ put(secondProperty, second); }}; + Map first = new LinkedHashMap<>(); + first.put(secondProperty, second); env.put("spring", first); } return bpp.readSpringMainPropertiesMap(env);