9
9
package org .elasticsearch .rest .action .document ;
10
10
11
11
import org .elasticsearch .ResourceNotFoundException ;
12
+ import org .elasticsearch .action .get .GetRequest ;
12
13
import org .elasticsearch .action .get .GetResponse ;
13
14
import org .elasticsearch .common .bytes .BytesArray ;
14
15
import org .elasticsearch .common .bytes .BytesReference ;
16
+ import org .elasticsearch .core .RestApiVersion ;
15
17
import org .elasticsearch .index .get .GetResult ;
16
18
import org .elasticsearch .rest .RestRequest ;
17
19
import org .elasticsearch .rest .RestResponse ;
21
23
import org .elasticsearch .test .rest .RestActionTestCase ;
22
24
import org .junit .AfterClass ;
23
25
import org .junit .Before ;
26
+ import org .mockito .Mockito ;
27
+
28
+ import java .util .Collections ;
29
+ import java .util .HashMap ;
30
+ import java .util .List ;
31
+ import java .util .Map ;
24
32
25
33
import static java .util .Collections .emptyMap ;
26
34
import static org .elasticsearch .index .seqno .SequenceNumbers .UNASSIGNED_SEQ_NO ;
27
35
import static org .elasticsearch .rest .RestStatus .OK ;
28
36
import static org .hamcrest .Matchers .equalTo ;
37
+ import static org .hamcrest .Matchers .instanceOf ;
29
38
30
39
public class RestGetSourceActionTests extends RestActionTestCase {
31
40
32
41
private static RestRequest request = new FakeRestRequest ();
33
42
private static FakeRestChannel channel = new FakeRestChannel (request , true , 0 );
34
43
private static RestGetSourceResponseListener listener = new RestGetSourceResponseListener (channel , request );
44
+ private final List <String > compatibleMediaType = Collections .singletonList (randomCompatibleMediaType (RestApiVersion .V_7 ));
35
45
36
46
@ Before
37
47
public void setUpAction () {
38
48
controller ().registerHandler (new RestGetSourceAction ());
49
+ verifyingClient .setExecuteVerifier ((actionType , request ) -> {
50
+ assertThat (request , instanceOf (GetRequest .class ));
51
+ return Mockito .mock (GetResponse .class );
52
+ });
39
53
}
40
54
41
55
@ AfterClass
@@ -44,6 +58,7 @@ public static void cleanupReferences() {
44
58
channel = null ;
45
59
listener = null ;
46
60
}
61
+
47
62
public void testRestGetSourceAction () throws Exception {
48
63
final BytesReference source = new BytesArray ("{\" foo\" : \" bar\" }" );
49
64
final GetResponse response =
@@ -73,4 +88,57 @@ public void testRestGetSourceActionWithMissingDocumentSource() {
73
88
74
89
assertThat (exception .getMessage (), equalTo ("Source not found [index1]/[1]" ));
75
90
}
91
+
92
+ /**
93
+ * test deprecation is logged if type is used in path
94
+ */
95
+ public void testTypeInGetPath () {
96
+ RestRequest request = new FakeRestRequest .Builder (xContentRegistry ())
97
+ .withHeaders (Map .of ("Accept" , compatibleMediaType ))
98
+ .withMethod (RestRequest .Method .HEAD )
99
+ .withPath ("/some_index/some_type/id/_source" )
100
+ .build ();
101
+ dispatchRequest (request );
102
+ assertWarnings (RestGetSourceAction .TYPES_DEPRECATION_MESSAGE );
103
+ }
104
+
105
+ public void testTypeInHeadPath () {
106
+ RestRequest request = new FakeRestRequest .Builder (xContentRegistry ())
107
+ .withHeaders (Map .of ("Accept" , compatibleMediaType ))
108
+ .withMethod (RestRequest .Method .GET )
109
+ .withPath ("/some_index/some_type/id/_source" )
110
+ .build ();
111
+ dispatchRequest (request );
112
+ assertWarnings (RestGetSourceAction .TYPES_DEPRECATION_MESSAGE );
113
+ }
114
+
115
+ /**
116
+ * test deprecation is logged if type is used as parameter
117
+ */
118
+ public void testTypeParameterAndGet () {
119
+ Map <String , String > params = new HashMap <>();
120
+ params .put ("type" , "some_type" );
121
+ RestRequest request = new FakeRestRequest .Builder (xContentRegistry ())
122
+ .withHeaders (Map .of ("Accept" , compatibleMediaType ))
123
+ .withMethod (RestRequest .Method .GET )
124
+ .withPath ("/some_index/_source/id" )
125
+ .withParams (params )
126
+ .build ();
127
+ dispatchRequest (request );
128
+ assertWarnings (RestGetSourceAction .TYPES_DEPRECATION_MESSAGE );
129
+ }
130
+
131
+ public void testTypeParameterAndHead () {
132
+ Map <String , String > params = new HashMap <>();
133
+ params .put ("type" , "some_type" );
134
+ RestRequest request = new FakeRestRequest .Builder (xContentRegistry ())
135
+ .withHeaders (Map .of ("Accept" , compatibleMediaType ))
136
+ .withMethod (RestRequest .Method .HEAD )
137
+ .withPath ("/some_index/_source/id" )
138
+ .withParams (params )
139
+ .build ();
140
+ dispatchRequest (request );
141
+ assertWarnings (RestGetSourceAction .TYPES_DEPRECATION_MESSAGE );
142
+ }
143
+
76
144
}
0 commit comments