Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

@ConfigurationProperties(prefix = "dapr.client")
public class DaprClientProperties {

public static final String DEFAULT_HTTP_ENDPOINT = "http://localhost";
public static final String DEFAULT_GRPC_ENDPOINT = "localhost";
public static final int DEFAULT_HTTP_PORT = 3500;
public static final int DEFAULT_GRPC_PORT = 50001;

private String httpEndpoint;
private String grpcEndpoint;
private Integer httpPort;
Expand Down Expand Up @@ -47,19 +53,19 @@ public DaprClientProperties(String httpEndpoint, String grpcEndpoint, Integer ht
}

public String getHttpEndpoint() {
return httpEndpoint;
return (httpEndpoint != null) ? httpEndpoint : DEFAULT_HTTP_ENDPOINT;
}

public String getGrpcEndpoint() {
return grpcEndpoint;
return (grpcEndpoint != null) ? grpcEndpoint : DEFAULT_GRPC_ENDPOINT;
}

public Integer getHttpPort() {
return httpPort;
return (httpPort != null) ? httpPort : DEFAULT_HTTP_PORT;
}

public Integer getGrpcPort() {
return grpcPort;
return (grpcPort != null) ? grpcPort : DEFAULT_GRPC_PORT;
}

public void setHttpEndpoint(String httpEndpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ public class DaprClientPropertiesTest {
private final ApplicationContextRunner runner = new ApplicationContextRunner()
.withUserConfiguration(EnableDaprClientProperties.class);

@Test
@DisplayName("Should have correct default values when using no-arg constructor")
public void shouldHaveCorrectDefaults() {

DaprClientProperties properties = new DaprClientProperties();

SoftAssertions.assertSoftly(softly -> {
softly.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
softly.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
softly.assertThat(properties.getHttpPort()).isEqualTo(3500);
softly.assertThat(properties.getGrpcPort()).isEqualTo(50001);
softly.assertThat(properties.getApiToken()).isNull();
});
}

@Test
@DisplayName("Should create DaprClientProperties correctly through constructor")
public void shouldCreateDaprClientPropertiesCorrectly() {
Expand All @@ -49,21 +64,36 @@ public void shouldSetDaprClientPropertiesCorrectly() {

DaprClientProperties properties = new DaprClientProperties();

properties.setGrpcEndpoint("localhost");
properties.setGrpcPort(50001);
properties.setHttpEndpoint("http://localhost");
properties.setHttpPort(3500);
properties.setGrpcEndpoint("custom-host");
properties.setGrpcPort(60001);
properties.setHttpEndpoint("http://custom-host");
properties.setHttpPort(4500);
properties.setApiToken("ABC");

SoftAssertions.assertSoftly(softAssertions -> {
softAssertions.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
softAssertions.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
softAssertions.assertThat(properties.getHttpPort()).isEqualTo(3500);
softAssertions.assertThat(properties.getGrpcPort()).isEqualTo(50001);
softAssertions.assertThat(properties.getGrpcEndpoint()).isEqualTo("custom-host");
softAssertions.assertThat(properties.getHttpEndpoint()).isEqualTo("http://custom-host");
softAssertions.assertThat(properties.getHttpPort()).isEqualTo(4500);
softAssertions.assertThat(properties.getGrpcPort()).isEqualTo(60001);
softAssertions.assertThat(properties.getApiToken()).isEqualTo("ABC");
});
}

@Test
@DisplayName("Should have correct defaults when no properties are configured")
public void shouldHaveDefaultsWhenNoPropertiesConfigured() {
runner.run(context -> {
DaprClientProperties properties = context.getBean(DaprClientProperties.class);
SoftAssertions.assertSoftly(softly -> {
softly.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
softly.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
softly.assertThat(properties.getHttpPort()).isEqualTo(3500);
softly.assertThat(properties.getGrpcPort()).isEqualTo(50001);
softly.assertThat(properties.getApiToken()).isNull();
});
});
}

@Test
@DisplayName("Should map DaprClient properties correctly")
public void shouldMapDaprClientProperties() {
Expand Down
Loading