1+ /*
2+ * Copyright 2021-2023 the original author or authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+ package org .springframework .data .elasticsearch .client .elc ;
17+
18+ import co .elastic .clients .elasticsearch .indices .RefreshRequest ;
19+ import co .elastic .clients .json .JsonpMapper ;
20+ import co .elastic .clients .transport .ElasticsearchTransport ;
21+ import org .junit .jupiter .api .BeforeEach ;
22+ import org .junit .jupiter .api .Test ;
23+ import org .junit .jupiter .api .extension .ExtendWith ;
24+ import org .mockito .ArgumentCaptor ;
25+ import org .mockito .Captor ;
26+ import org .mockito .Mock ;
27+ import org .mockito .junit .jupiter .MockitoExtension ;
28+ import org .springframework .data .elasticsearch .core .convert .ElasticsearchConverter ;
29+ import org .springframework .data .elasticsearch .core .mapping .IndexCoordinates ;
30+ import reactor .core .publisher .Mono ;
31+ import reactor .test .StepVerifier ;
32+
33+ import java .util .List ;
34+
35+ import static org .junit .jupiter .api .Assertions .assertEquals ;
36+ import static org .mockito .Mockito .*;
37+
38+ /**
39+ * @author Urs Keller
40+ * @since 5.0
41+ */
42+ @ ExtendWith (MockitoExtension .class )
43+ class ReactiveIndicesTemplateTest {
44+ @ Mock private ElasticsearchConverter elasticsearchConverter ;
45+ @ Mock private ReactiveElasticsearchIndicesClient client ;
46+ @ Mock private ElasticsearchTransport transport ;
47+ @ Mock private JsonpMapper jsonpMapper ;
48+ @ Captor ArgumentCaptor <RefreshRequest > refreshRequest ;
49+
50+ @ BeforeEach
51+ void setup () {
52+ doReturn (transport ).when (client )._transport ();
53+ doReturn (jsonpMapper ).when (transport ).jsonpMapper ();
54+ }
55+
56+ /**
57+ * Tests that refresh is called with the indices bound to the template
58+ */
59+ @ Test
60+ void refresh () {
61+ IndexCoordinates indexCoordinate = IndexCoordinates .of ("i1" , "i2" );
62+ ReactiveIndicesTemplate template = new ReactiveIndicesTemplate (client , elasticsearchConverter , indexCoordinate );
63+ doReturn (Mono .empty ()).when (client ).refresh (any (RefreshRequest .class ));
64+
65+ template .refresh ().as (StepVerifier ::create ).verifyComplete ();
66+
67+ verify (client ).refresh (refreshRequest .capture ());
68+ assertEquals (List .of ("i1" , "i2" ), refreshRequest .getValue ().index ());
69+
70+ verifyNoMoreInteractions ( elasticsearchConverter , client , transport , jsonpMapper );
71+ }
72+ }
0 commit comments