|
| 1 | +/* |
| 2 | + * Copyright 2024 The Dapr Authors |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * Unless required by applicable law or agreed to in writing, software |
| 8 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | + * See the License for the specific language governing permissions and |
| 11 | +limitations under the License. |
| 12 | +*/ |
| 13 | + |
| 14 | +package io.dapr.spring.boot.autoconfigure.client; |
| 15 | + |
| 16 | +import org.assertj.core.api.SoftAssertions; |
| 17 | +import org.junit.Test; |
| 18 | +import org.junit.jupiter.api.DisplayName; |
| 19 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 20 | +import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
| 21 | + |
| 22 | +public class DaprClientPropertiesTest { |
| 23 | + |
| 24 | + |
| 25 | + private final ApplicationContextRunner runner = new ApplicationContextRunner() |
| 26 | + .withUserConfiguration(EnableDaprClientProperties.class); |
| 27 | + |
| 28 | + @Test |
| 29 | + @DisplayName("Should create DaprClientProperties correctly through constructor") |
| 30 | + public void shouldCreateDaprClientPropertiesCorrectly() { |
| 31 | + |
| 32 | + DaprClientProperties properties = new DaprClientProperties( |
| 33 | + "http://localhost", "localhost", 3500, 50001 |
| 34 | + ); |
| 35 | + |
| 36 | + SoftAssertions.assertSoftly(softAssertions -> { |
| 37 | + softAssertions.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost"); |
| 38 | + softAssertions.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost"); |
| 39 | + softAssertions.assertThat(properties.getHttpPort()).isEqualTo(3500); |
| 40 | + softAssertions.assertThat(properties.getGrpcPort()).isEqualTo(50001); |
| 41 | + }); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + @DisplayName("Should create DaprClientProperties correctly through setters") |
| 46 | + public void shouldSetDaprClientPropertiesCorrectly() { |
| 47 | + |
| 48 | + DaprClientProperties properties = new DaprClientProperties(); |
| 49 | + |
| 50 | + properties.setGrpcEndpoint("localhost"); |
| 51 | + properties.setGrpcPort(50001); |
| 52 | + properties.setHttpEndpoint("http://localhost"); |
| 53 | + properties.setHttpPort(3500); |
| 54 | + |
| 55 | + SoftAssertions.assertSoftly(softAssertions -> { |
| 56 | + softAssertions.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost"); |
| 57 | + softAssertions.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost"); |
| 58 | + softAssertions.assertThat(properties.getHttpPort()).isEqualTo(3500); |
| 59 | + softAssertions.assertThat(properties.getGrpcPort()).isEqualTo(50001); |
| 60 | + }); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + @DisplayName("Should map DaprClient properties correctly") |
| 65 | + public void shouldMapDaprClientProperties() { |
| 66 | + |
| 67 | + runner.withSystemProperties( |
| 68 | + "dapr.client.http-endpoint=http://localhost", |
| 69 | + "dapr.client.http-port=3500", |
| 70 | + "dapr.client.grpc-endpoint=localhost", |
| 71 | + "dapr.client.grpc-port=50001" |
| 72 | + ).run(context -> { |
| 73 | + DaprClientProperties properties = context.getBean(DaprClientProperties.class); |
| 74 | + SoftAssertions.assertSoftly(softAssertions -> { |
| 75 | + softAssertions.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost"); |
| 76 | + softAssertions.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost"); |
| 77 | + softAssertions.assertThat(properties.getHttpPort()).isEqualTo(3500); |
| 78 | + softAssertions.assertThat(properties.getGrpcPort()).isEqualTo(50001); |
| 79 | + }); |
| 80 | + |
| 81 | + }); |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | + @EnableConfigurationProperties(DaprClientProperties.class) |
| 86 | + static class EnableDaprClientProperties { |
| 87 | + |
| 88 | + } |
| 89 | +} |
0 commit comments