Skip to content

Commit a4832c5

Browse files
committed
Add unit tests.
Signed-off-by: Youssef Aouichaoui <[email protected]>
1 parent 869ffcd commit a4832c5

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderUnitTests.java

+33
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,33 @@ void shouldUseCustomMappedNameMultiField() throws JSONException {
12961296
assertEquals(expected, mapping, true);
12971297
}
12981298

1299+
@Test // #2952
1300+
void shouldMapNullityParameters() throws JSONException {
1301+
// Given
1302+
String expected = """
1303+
{
1304+
"properties" : {
1305+
"_class" : {
1306+
"type" : "keyword",
1307+
"index" : false,
1308+
"doc_values" : false
1309+
},
1310+
"empty-field" : {
1311+
"type" : "keyword",
1312+
"null_value" : "EMPTY",
1313+
"fields" : { }
1314+
}
1315+
}
1316+
}
1317+
""";
1318+
1319+
// When
1320+
String result = getMappingBuilder().buildPropertyMapping(MultiFieldWithNullEmptyParameters.class);
1321+
1322+
// Then
1323+
assertEquals(expected, result, true);
1324+
}
1325+
12991326
// region entities
13001327

13011328
@Document(indexName = "ignore-above-index")
@@ -2570,5 +2597,11 @@ private static class MultiFieldMappedNameEntity {
25702597
@MultiField(mainField = @Field(type = FieldType.Text, mappedTypeName = "match_only_text"), otherFields = { @InnerField(suffix = "lower_case",
25712598
type = FieldType.Keyword, normalizer = "lower_case_normalizer", mappedTypeName = "constant_keyword") }) private String description;
25722599
}
2600+
2601+
private static class MultiFieldWithNullEmptyParameters {
2602+
@Nullable
2603+
@MultiField(mainField = @Field(name = "empty-field", type = FieldType.Keyword, nullValue = "EMPTY",
2604+
storeNullValue = true, storeEmptyValue = false)) private List<String> emptyField;
2605+
}
25732606
// endregion
25742607
}

src/test/java/org/springframework/data/elasticsearch/core/index/ReactiveMappingBuilderUnitTests.java

+38
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
import static org.skyscreamer.jsonassert.JSONAssert.*;
1919
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
2020

21+
import org.springframework.data.elasticsearch.annotations.FieldType;
22+
import org.springframework.data.elasticsearch.annotations.MultiField;
2123
import reactor.core.publisher.Mono;
2224
import reactor.core.scheduler.Schedulers;
2325

2426
import java.time.Instant;
27+
import java.util.List;
2528

2629
import org.json.JSONException;
2730
import org.junit.jupiter.api.DisplayName;
@@ -78,6 +81,35 @@ void shouldWriteRuntimeFields() throws JSONException {
7881

7982
assertEquals(expected, mapping, true);
8083
}
84+
85+
@Test // #2952
86+
void shouldMapNullityParameters() throws JSONException {
87+
// Given
88+
ReactiveMappingBuilder mappingBuilder = getReactiveMappingBuilder();
89+
String expected = """
90+
{
91+
"properties" : {
92+
"_class" : {
93+
"type" : "keyword",
94+
"index" : false,
95+
"doc_values" : false
96+
},
97+
"empty-field" : {
98+
"type" : "keyword",
99+
"null_value" : "EMPTY",
100+
"fields" : { }
101+
}
102+
}
103+
}
104+
""";
105+
106+
// When
107+
String result = Mono.defer(() -> mappingBuilder.buildReactivePropertyMapping(MultiFieldWithNullEmptyParameters.class))
108+
.subscribeOn(Schedulers.parallel()).block();
109+
110+
// Then
111+
assertEquals(expected, result, true);
112+
}
81113

82114
// region entities
83115
@Document(indexName = "runtime-fields")
@@ -88,5 +120,11 @@ private static class RuntimeFieldEntity {
88120
@Field(type = Date, format = DateFormat.epoch_millis, name = "@timestamp")
89121
@Nullable private Instant timestamp;
90122
}
123+
124+
private static class MultiFieldWithNullEmptyParameters {
125+
@Nullable
126+
@MultiField(mainField = @Field(name = "empty-field", type = FieldType.Keyword, nullValue = "EMPTY",
127+
storeNullValue = true, storeEmptyValue = false)) private List<String> emptyField;
128+
}
91129
// endregion
92130
}

0 commit comments

Comments
 (0)