mirror of https://github.com/dapr/java-sdk.git
Add coverage for some properties (#1297)
This commit is contained in:
parent
ed9a3fb77b
commit
9b635dae6d
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2024 The Dapr Authors
|
||||
* Copyright 2025 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
@ -14,8 +14,9 @@ limitations under the License.
|
|||
package io.dapr.spring.boot.autoconfigure.client;
|
||||
|
||||
import org.assertj.core.api.SoftAssertions;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
|
||||
|
@ -33,11 +34,11 @@ public class DaprClientPropertiesTest {
|
|||
"http://localhost", "localhost", 3500, 50001
|
||||
);
|
||||
|
||||
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.assertSoftly(softly -> {
|
||||
softly.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
|
||||
softly.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
|
||||
softly.assertThat(properties.getHttpPort()).isEqualTo(3500);
|
||||
softly.assertThat(properties.getGrpcPort()).isEqualTo(50001);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -71,11 +72,11 @@ public class DaprClientPropertiesTest {
|
|||
"dapr.client.grpc-port=50001"
|
||||
).run(context -> {
|
||||
DaprClientProperties properties = context.getBean(DaprClientProperties.class);
|
||||
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.assertSoftly(softly -> {
|
||||
softly.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
|
||||
softly.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
|
||||
softly.assertThat(properties.getHttpPort()).isEqualTo(3500);
|
||||
softly.assertThat(properties.getGrpcPort()).isEqualTo(50001);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright 2025 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package io.dapr.spring.boot.autoconfigure.pubsub;
|
||||
|
||||
import org.assertj.core.api.SoftAssertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
|
||||
public class DaprPubSubPropertiesTest {
|
||||
|
||||
final ApplicationContextRunner runner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(EnableDaprPubSubProperties.class);
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("Should configure properties with setters")
|
||||
void shouldSetProperties() {
|
||||
DaprPubSubProperties properties = new DaprPubSubProperties();
|
||||
properties.setName("pubsub");
|
||||
properties.setObservationEnabled(false);
|
||||
|
||||
SoftAssertions.assertSoftly(softAssertions -> {
|
||||
softAssertions.assertThat(properties.getName()).isEqualTo("pubsub");
|
||||
softAssertions.assertThat(properties.isObservationEnabled()).isEqualTo(false);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should map DaprPubSubProperties correctly")
|
||||
void shouldMapDaprPubSubPropertiesCorrectly() {
|
||||
runner.withPropertyValues(
|
||||
"dapr.pubsub.name=pubsub",
|
||||
"dapr.pubsub.observation-enabled=true"
|
||||
).run(context -> {
|
||||
DaprPubSubProperties properties = context.getBean(DaprPubSubProperties.class);
|
||||
|
||||
SoftAssertions.assertSoftly(softAssertions -> {
|
||||
softAssertions.assertThat(properties.getName()).isEqualTo("pubsub");
|
||||
softAssertions.assertThat(properties.isObservationEnabled()).isEqualTo(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@EnableConfigurationProperties(DaprPubSubProperties.class)
|
||||
static class EnableDaprPubSubProperties {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright 2021 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package io.dapr.spring.boot.autoconfigure.statestore;
|
||||
|
||||
import org.assertj.core.api.SoftAssertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
|
||||
public class DaprStateStorePropertiesTest {
|
||||
|
||||
|
||||
final ApplicationContextRunner runner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(EnableDaprStateStoreProperties.class);
|
||||
|
||||
@Test
|
||||
@DisplayName("Should create DaprStateStoreProperties via constructor")
|
||||
void shouldSetDaprStateStorePropertiesCorrectly() {
|
||||
DaprStateStoreProperties properties = new DaprStateStoreProperties();
|
||||
properties.setBinding("binding");
|
||||
properties.setName("name");
|
||||
|
||||
SoftAssertions.assertSoftly(softAssertions -> {
|
||||
softAssertions.assertThat(properties.getName()).isEqualTo("name");
|
||||
softAssertions.assertThat(properties.getBinding()).isEqualTo("binding");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should map Dapr state store properties correctly")
|
||||
void shouldMapDaprStateStoreProperties() {
|
||||
runner.withPropertyValues(
|
||||
"dapr.statestore.name=name",
|
||||
"dapr.statestore.binding=binding"
|
||||
).run(context -> {
|
||||
DaprStateStoreProperties properties = context.getBean(DaprStateStoreProperties.class);
|
||||
|
||||
SoftAssertions.assertSoftly(softly -> {
|
||||
softly.assertThat(properties.getBinding()).isEqualTo("binding");
|
||||
softly.assertThat(properties.getName()).isEqualTo("name");
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@EnableConfigurationProperties(DaprStateStoreProperties.class)
|
||||
static class EnableDaprStateStoreProperties {
|
||||
|
||||
}
|
||||
|
||||
}
|
1
pom.xml
1
pom.xml
|
@ -50,6 +50,7 @@
|
|||
<testcontainers.version>1.20.5</testcontainers.version>
|
||||
<springboot.version>3.4.3</springboot.version>
|
||||
<nexus-staging-maven-plugin.version>1.7.0</nexus-staging-maven-plugin.version>
|
||||
<assertj.version>3.27.3</assertj.version>
|
||||
</properties>
|
||||
|
||||
<distributionManagement>
|
||||
|
|
|
@ -127,6 +127,11 @@
|
|||
<version>${jackson.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright 2025 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package io.dapr.client.domain;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class BulkPublishEntryTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should create an empty metadata when metadata argument is null")
|
||||
public void shouldCreateWithEmptyMetadataWhenMetadataIsNull() {
|
||||
BulkPublishEntry<String> entry = new BulkPublishEntry<>(
|
||||
"entryId", "event", "contentType", null
|
||||
);
|
||||
assertThat(entry.getMetadata()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should create with non null metadata")
|
||||
public void shouldCreateWithMetadata() {
|
||||
BulkPublishEntry<String> entry = new BulkPublishEntry<>(
|
||||
"entryId", "event", "application/json", Map.of(
|
||||
"repo", "dapr/java-sdk"
|
||||
));
|
||||
assertThat(entry.getMetadata()).hasSize(1);
|
||||
}
|
||||
|
||||
}
|
|
@ -10,16 +10,17 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package io.dapr.client.domain;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class BulkPublishRequestTest {
|
||||
|
@ -36,6 +37,15 @@ public class BulkPublishRequestTest {
|
|||
request.setMetadata(metadata);
|
||||
Map<String, String> initial = request.getMetadata();
|
||||
request.setMetadata(metadata);
|
||||
Assertions.assertNotSame( request.getMetadata(), initial, "Should not be same map");
|
||||
|
||||
assertThat(request.getMetadata()).isNotSameAs(initial);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should create a BulkPublishRequest with empty list when entries is null")
|
||||
public void shouldCreateWithEmptyListWhenEntriesIsNull() {
|
||||
BulkPublishRequest<String> request = new BulkPublishRequest<>("testPubsub", "testTopic", null);
|
||||
List<BulkPublishEntry<String>> entries = request.getEntries();
|
||||
assertThat(entries).isNotNull();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2025 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package io.dapr.client.domain;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
class ConfigurationItemTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should create ConfigurationItem correctly")
|
||||
void shouldCreateConfigurationItemCorrectly() {
|
||||
ConfigurationItem item = new ConfigurationItem("application", "java-sdk", "0.0.1", Map.of(
|
||||
"creator", "devs"
|
||||
));
|
||||
|
||||
assertThat(item.getKey()).isEqualTo("application");
|
||||
assertThat(item.getValue()).isEqualTo("java-sdk");
|
||||
assertThat(item.getVersion()).isEqualTo("0.0.1");
|
||||
assertThat(item.getMetadata()).hasSize(1);
|
||||
assertThat(item.getMetadata()).hasEntrySatisfying("creator", value -> {
|
||||
assertThat(value).isEqualTo("devs");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should create with immutable metadata")
|
||||
void shouldCreateWithImmutableMetadata() {
|
||||
ConfigurationItem item = new ConfigurationItem("application", "java-sdk", "0.0.1", Map.of(
|
||||
"creator", "devs"
|
||||
));
|
||||
assertThatThrownBy(() -> item.getMetadata().put("language", "javascript"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright 2025 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package io.dapr.client.domain;
|
||||
|
||||
import io.dapr.client.DaprHttp;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class HttpExtensionTest {
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("Should encode query params correctly")
|
||||
void shouldEncodeQueryParamsCorrectly() {
|
||||
HttpExtension httpExtension = new HttpExtension(DaprHttp.HttpMethods.GET,
|
||||
Map.of("traceparent", List.of("00-4bf92f3577b34da6a3ce929d0e0e4733-00f067aa0ba902b7-01")), Map.of());
|
||||
|
||||
String encoded = httpExtension.encodeQueryString();
|
||||
|
||||
Assertions.assertEquals("traceparent=00-4bf92f3577b34da6a3ce929d0e0e4733-00f067aa0ba902b7-01", encoded);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should encode multiple values for same query param key")
|
||||
void shouldEncodeMultipleValuesForSameQueryParamKey() {
|
||||
HttpExtension httpExtension = new HttpExtension(DaprHttp.HttpMethods.GET,
|
||||
Map.of("category", List.of("books", "electronics")), Map.of());
|
||||
|
||||
String encoded = httpExtension.encodeQueryString();
|
||||
|
||||
Assertions.assertEquals("category=books&category=electronics", encoded);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should encode query param with spaces, accents, and special characters")
|
||||
void shouldEncodeQueryParamWithSpacesAndSpecialCharacters() {
|
||||
HttpExtension httpExtension = new HttpExtension(DaprHttp.HttpMethods.GET,
|
||||
Map.of("user name", List.of("John Doë & Co.")), Map.of());
|
||||
|
||||
String encoded = httpExtension.encodeQueryString();
|
||||
|
||||
Assertions.assertEquals("user+name=John+Do%C3%AB+%26+Co.", encoded);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,24 @@
|
|||
/*
|
||||
* Copyright 2025 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package io.dapr.client.domain;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
@ -31,4 +45,15 @@ public class SaveStateRequestTest {
|
|||
assertEquals("test var args 1", request.getStates().get(0).getKey(), "Value incorrectly set");
|
||||
assertEquals("test var args 2", request.getStates().get(1).getKey(), "Value incorrectly set");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should set states as null when the argument is null")
|
||||
void testSetStateWithNullParameter() {
|
||||
|
||||
SaveStateRequest request = new SaveStateRequest(STORE_NAME);
|
||||
request.setStates((List<State<?>>) null);
|
||||
List<State<?>> states = request.getStates();
|
||||
|
||||
assertThat(states).isNull();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package io.dapr.client.domain;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
@ -106,4 +108,16 @@ public class StateTest {
|
|||
assertNotEquals(state1.hashCode(), state4.hashCode());
|
||||
assertNotEquals(state1, state4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should hashCode and equals method work with null metadata")
|
||||
public void testEqualsAndHashcodeWithNullValues() {
|
||||
State<String> state1 = new State<>(KEY, "value", ETAG, null, OPTIONS);
|
||||
State<String> state2 = new State<>(KEY, "value", ETAG, null, OPTIONS);
|
||||
|
||||
assertThat(state1.toString()).isEqualTo(state2.toString());
|
||||
assertThat(state1.hashCode()).isEqualTo(state1.hashCode());
|
||||
assertThat(state1).isEqualTo(state2);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright 2025 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package io.dapr.client.domain;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class TransactionalStateRequestTest {
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("Should create with non empty collections")
|
||||
void shouldCreateCorrectlyWithNonEmptyCollections() {
|
||||
|
||||
State<String> users = new State<>("users");
|
||||
TransactionalStateOperation<String> operation =
|
||||
new TransactionalStateOperation<>(TransactionalStateOperation.OperationType.DELETE, users);
|
||||
|
||||
TransactionalStateRequest<String> request = new TransactionalStateRequest<>(
|
||||
List.of(operation), Map.of("application", "java-sdk")
|
||||
);
|
||||
|
||||
assertThat(request.getMetadata()).hasSize(1);
|
||||
assertThat(request.getOperations()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should create correctly with empty collections")
|
||||
void shouldCreateCorrectlyWithEmptyCollections() {
|
||||
TransactionalStateRequest<String> request = new TransactionalStateRequest<>(
|
||||
List.of(), Map.of()
|
||||
);
|
||||
assertThat(request.getMetadata()).isEmpty();
|
||||
assertThat(request.getOperations()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should create correctly with null value")
|
||||
void shouldCreateWhenArgumentIsNull() {
|
||||
TransactionalStateRequest<String> request = new TransactionalStateRequest<>(
|
||||
null, null
|
||||
);
|
||||
assertThat(request.getMetadata()).isNull();
|
||||
assertThat(request.getOperations()).isNull();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2025 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package io.dapr.config;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
public class IntegerPropertyTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should create IntegerProperty correctly")
|
||||
void shouldCreateIntegerPropertyCorrectly() {
|
||||
IntegerProperty property = new IntegerProperty("int", "INT", 0);
|
||||
Integer twoHundreds = property.parse("200");
|
||||
assertThat(twoHundreds).isEqualTo(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should throws NumberFormatException when parsing non number")
|
||||
void shouldThrowsExceptionWhenParsingNonNumber() {
|
||||
IntegerProperty property = new IntegerProperty("int", "INT", 0);
|
||||
assertThatThrownBy(() -> property.parse("TWO_THOUSANDS"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue