22
22
23
23
import org .junit .jupiter .api .AfterEach ;
24
24
import org .junit .jupiter .api .BeforeEach ;
25
+ import org .junit .jupiter .api .DisplayName ;
25
26
import org .junit .jupiter .api .Test ;
26
27
import org .springframework .beans .factory .annotation .Autowired ;
27
28
import org .springframework .context .annotation .Configuration ;
28
29
import org .springframework .context .annotation .Import ;
29
30
import org .springframework .data .annotation .Id ;
31
+ import org .springframework .data .annotation .ReadOnlyProperty ;
30
32
import org .springframework .data .elasticsearch .annotations .Document ;
31
33
import org .springframework .data .elasticsearch .core .ElasticsearchOperations ;
32
34
import org .springframework .data .elasticsearch .core .IndexOperations ;
35
37
import org .springframework .data .elasticsearch .junit .jupiter .ElasticsearchRestTemplateConfiguration ;
36
38
import org .springframework .data .elasticsearch .junit .jupiter .ReactiveElasticsearchRestTemplateConfiguration ;
37
39
import org .springframework .data .elasticsearch .junit .jupiter .SpringIntegrationTest ;
40
+ import org .springframework .lang .Nullable ;
38
41
import org .springframework .stereotype .Component ;
39
42
import org .springframework .test .context .ContextConfiguration ;
40
43
@@ -49,6 +52,7 @@ public class ReactiveElasticsearchOperationsCallbackTest {
49
52
@ Configuration
50
53
@ Import ({ ReactiveElasticsearchRestTemplateConfiguration .class , ElasticsearchRestTemplateConfiguration .class })
51
54
static class Config {
55
+
52
56
@ Component
53
57
static class SampleEntityBeforeConvertCallback implements ReactiveBeforeConvertCallback <SampleEntity > {
54
58
@ Override
@@ -58,6 +62,20 @@ public Mono<SampleEntity> onBeforeConvert(SampleEntity entity, IndexCoordinates
58
62
}
59
63
}
60
64
65
+ @ Component
66
+ static class SampleEntityAfterLoadCallback
67
+ implements ReactiveAfterLoadCallback <ElasticsearchOperationsCallbackIntegrationTests .SampleEntity > {
68
+
69
+ @ Override
70
+ public Mono <org .springframework .data .elasticsearch .core .document .Document > onAfterLoad (
71
+ org .springframework .data .elasticsearch .core .document .Document document ,
72
+ Class <ElasticsearchOperationsCallbackIntegrationTests .SampleEntity > type , IndexCoordinates indexCoordinates ) {
73
+
74
+ document .put ("className" , document .get ("_class" ));
75
+ return Mono .just (document );
76
+ }
77
+ }
78
+
61
79
}
62
80
63
81
@ Autowired private ReactiveElasticsearchOperations operations ;
@@ -88,11 +106,29 @@ void shouldCallCallbackOnSave() {
88
106
.verifyComplete ();
89
107
}
90
108
109
+ @ Test // #2009
110
+ @ DisplayName ("should invoke after load callback" )
111
+ void shouldInvokeAfterLoadCallback () {
112
+
113
+ SampleEntity entity = new SampleEntity ("1" , "test" );
114
+
115
+ operations .save (entity ) //
116
+ .then (operations .get (entity .getId (), SampleEntity .class )) //
117
+ .as (StepVerifier ::create ) //
118
+ .consumeNextWith (loaded -> { //
119
+ assertThat (loaded ).isNotNull (); //
120
+ assertThat (loaded .className ).isEqualTo (SampleEntity .class .getName ()); //
121
+ }).verifyComplete (); //
122
+ }
123
+
91
124
@ Document (indexName = "test-operations-reactive-callback" )
92
125
static class SampleEntity {
93
126
@ Id private String id ;
94
127
private String text ;
95
128
129
+ @ ReadOnlyProperty
130
+ @ Nullable private String className ;
131
+
96
132
public SampleEntity (String id , String text ) {
97
133
this .id = id ;
98
134
this .text = text ;
0 commit comments