Browse Source

Improve property defaults

See gh-41851
pull/41975/head
Andy Wilkinson 2 years ago
parent
commit
a70ff35dba
  1. 10
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/pulsar/PulsarProperties.java
  2. 9
      spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarPropertiesTests.java

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

@ -311,17 +311,15 @@ public class PulsarProperties { @@ -311,17 +311,15 @@ public class PulsarProperties {
/**
* Default tenant to use when producing or consuming messages against a
* non-fully-qualified topic URL. When not specified Pulsar uses a default
* tenant of 'public'.
* non-fully-qualified topic URL.
*/
private String tenant;
private String tenant = "public";
/**
* Default namespace to use when producing or consuming messages against a
* non-fully-qualified topic URL. When not specified Pulsar uses a default
* namespace of 'default'.
* non-fully-qualified topic URL.
*/
private String namespace;
private String namespace = "default";
public String getTenant() {
return this.tenant;

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

@ -30,6 +30,7 @@ import org.apache.pulsar.client.api.SubscriptionInitialPosition; @@ -30,6 +30,7 @@ import org.apache.pulsar.client.api.SubscriptionInitialPosition;
import org.apache.pulsar.client.api.SubscriptionMode;
import org.apache.pulsar.client.api.SubscriptionType;
import org.apache.pulsar.common.schema.SchemaType;
import org.assertj.core.extractor.Extractors;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
@ -40,6 +41,7 @@ import org.springframework.boot.autoconfigure.pulsar.PulsarProperties.Failover.B @@ -40,6 +41,7 @@ import org.springframework.boot.autoconfigure.pulsar.PulsarProperties.Failover.B
import org.springframework.boot.context.properties.bind.BindException;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
import org.springframework.pulsar.core.PulsarTopicBuilder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@ -247,9 +249,12 @@ class PulsarPropertiesTests { @@ -247,9 +249,12 @@ class PulsarPropertiesTests {
@Test
void bindWhenValuesNotSpecified() {
PulsarTopicBuilder defaultTopicBuilder = new PulsarTopicBuilder();
assertThat(new PulsarProperties().getDefaults().getTopic()).satisfies((defaults) -> {
assertThat(defaults.getTenant()).isNull();
assertThat(defaults.getNamespace()).isNull();
assertThat(defaults.getTenant())
.isEqualTo(Extractors.byName("defaultTenant").apply(defaultTopicBuilder));
assertThat(defaults.getNamespace())
.isEqualTo(Extractors.byName("defaultNamespace").apply(defaultTopicBuilder));
});
}

Loading…
Cancel
Save