Skip to content

Commit a70ff35

Browse files
committed
Improve property defaults
See gh-41851
1 parent df89351 commit a70ff35

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/pulsar/PulsarProperties.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -311,17 +311,15 @@ public static class Topic {
311311

312312
/**
313313
* Default tenant to use when producing or consuming messages against a
314-
* non-fully-qualified topic URL. When not specified Pulsar uses a default
315-
* tenant of 'public'.
314+
* non-fully-qualified topic URL.
316315
*/
317-
private String tenant;
316+
private String tenant = "public";
318317

319318
/**
320319
* Default namespace to use when producing or consuming messages against a
321-
* non-fully-qualified topic URL. When not specified Pulsar uses a default
322-
* namespace of 'default'.
320+
* non-fully-qualified topic URL.
323321
*/
324-
private String namespace;
322+
private String namespace = "default";
325323

326324
public String getTenant() {
327325
return this.tenant;

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarPropertiesTests.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.pulsar.client.api.SubscriptionMode;
3131
import org.apache.pulsar.client.api.SubscriptionType;
3232
import org.apache.pulsar.common.schema.SchemaType;
33+
import org.assertj.core.extractor.Extractors;
3334
import org.junit.jupiter.api.Nested;
3435
import org.junit.jupiter.api.Test;
3536

@@ -40,6 +41,7 @@
4041
import org.springframework.boot.context.properties.bind.BindException;
4142
import org.springframework.boot.context.properties.bind.Binder;
4243
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
44+
import org.springframework.pulsar.core.PulsarTopicBuilder;
4345

4446
import static org.assertj.core.api.Assertions.assertThat;
4547
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -247,9 +249,12 @@ class DefaultsTenantNamespaceProperties {
247249

248250
@Test
249251
void bindWhenValuesNotSpecified() {
252+
PulsarTopicBuilder defaultTopicBuilder = new PulsarTopicBuilder();
250253
assertThat(new PulsarProperties().getDefaults().getTopic()).satisfies((defaults) -> {
251-
assertThat(defaults.getTenant()).isNull();
252-
assertThat(defaults.getNamespace()).isNull();
254+
assertThat(defaults.getTenant())
255+
.isEqualTo(Extractors.byName("defaultTenant").apply(defaultTopicBuilder));
256+
assertThat(defaults.getNamespace())
257+
.isEqualTo(Extractors.byName("defaultNamespace").apply(defaultTopicBuilder));
253258
});
254259
}
255260

0 commit comments

Comments
 (0)