|
49 | 49 | import org.springframework.data.elasticsearch.annotations.Field;
|
50 | 50 | import org.springframework.data.elasticsearch.annotations.FieldType;
|
51 | 51 | import org.springframework.data.elasticsearch.annotations.GeoPointField;
|
| 52 | +import org.springframework.data.elasticsearch.annotations.ScriptedField; |
52 | 53 | import org.springframework.data.elasticsearch.annotations.ValueConverter;
|
53 | 54 | import org.springframework.data.elasticsearch.core.document.Document;
|
| 55 | +import org.springframework.data.elasticsearch.core.document.SearchDocumentAdapter; |
54 | 56 | import org.springframework.data.elasticsearch.core.geo.GeoJsonEntity;
|
55 | 57 | import org.springframework.data.elasticsearch.core.geo.GeoJsonGeometryCollection;
|
56 | 58 | import org.springframework.data.elasticsearch.core.geo.GeoJsonLineString;
|
|
83 | 85 | * @author Konrad Kurdej
|
84 | 86 | * @author Roman Puchkovskiy
|
85 | 87 | * @author Sascha Woo
|
| 88 | + * @author llosimura |
86 | 89 | */
|
87 | 90 | public class MappingElasticsearchConverterUnitTests {
|
88 | 91 |
|
@@ -1800,6 +1803,68 @@ void shouldReadASingleStringIntoAListPropertyImmutable() {
|
1800 | 1803 | assertThat(entity.getStringList()).containsExactly("foo");
|
1801 | 1804 | }
|
1802 | 1805 |
|
| 1806 | + @Test |
| 1807 | + void shouldPopulateScriptedFields() { |
| 1808 | + SearchDocumentAdapter document = new SearchDocumentAdapter(Document.create(), |
| 1809 | + 0.0f, |
| 1810 | + new Object[]{}, |
| 1811 | + Map.of( |
| 1812 | + "scriptedField" , List.of("scriptedField"), |
| 1813 | + "custom-name-scripted-field" , List.of("custom-name-scripted-field") |
| 1814 | + ), |
| 1815 | + emptyMap(), |
| 1816 | + emptyMap(), |
| 1817 | + null, |
| 1818 | + null, |
| 1819 | + null, |
| 1820 | + null |
| 1821 | + ); |
| 1822 | + // Create a SearchDocument instance |
| 1823 | + var entity = mappingElasticsearchConverter.read(ScriptedEntity.class, document); |
| 1824 | + assertThat(entity.customScriptedField).isEqualTo("custom-name-scripted-field"); |
| 1825 | + assertThat(entity.scriptedField).isEqualTo("scriptedField"); |
| 1826 | + } |
| 1827 | + |
| 1828 | + static class ScriptedEntity { |
| 1829 | + @ScriptedField |
| 1830 | + private String scriptedField; |
| 1831 | + @ScriptedField(name = "custom-name-scripted-field") String customScriptedField; |
| 1832 | + |
| 1833 | + ScriptedEntity() { |
| 1834 | + customScriptedField = ""; |
| 1835 | + scriptedField = ""; |
| 1836 | + } |
| 1837 | + |
| 1838 | + public String getScriptedField() { |
| 1839 | + return scriptedField; |
| 1840 | + } |
| 1841 | + |
| 1842 | + public void setScriptedField(String scriptedField) { |
| 1843 | + this.scriptedField = scriptedField; |
| 1844 | + } |
| 1845 | + |
| 1846 | + public String getCustomScriptedField() { |
| 1847 | + return customScriptedField; |
| 1848 | + } |
| 1849 | + |
| 1850 | + public void setCustomScriptedField(String customScriptedField) { |
| 1851 | + this.customScriptedField = customScriptedField; |
| 1852 | + } |
| 1853 | + |
| 1854 | + @Override |
| 1855 | + public boolean equals(Object o) { |
| 1856 | + if (o == null || getClass() != o.getClass()) return false; |
| 1857 | + ScriptedEntity that = (ScriptedEntity) o; |
| 1858 | + return Objects.equals(scriptedField, that.scriptedField) && Objects.equals(customScriptedField, that.customScriptedField); |
| 1859 | + } |
| 1860 | + |
| 1861 | + @Override |
| 1862 | + public int hashCode() { |
| 1863 | + return Objects.hash(scriptedField, customScriptedField); |
| 1864 | + } |
| 1865 | + } |
| 1866 | + |
| 1867 | + |
1803 | 1868 | @Test // #2280
|
1804 | 1869 | @DisplayName("should read a String array into a List property immutable")
|
1805 | 1870 | void shouldReadAStringArrayIntoAListPropertyImmutable() {
|
|
0 commit comments