99package org .elasticsearch .rest .action .document ;
1010
1111import org .elasticsearch .ResourceNotFoundException ;
12+ import org .elasticsearch .action .get .GetRequest ;
1213import org .elasticsearch .action .get .GetResponse ;
1314import org .elasticsearch .common .bytes .BytesArray ;
1415import org .elasticsearch .common .bytes .BytesReference ;
16+ import org .elasticsearch .core .RestApiVersion ;
1517import org .elasticsearch .index .get .GetResult ;
1618import org .elasticsearch .rest .RestRequest ;
1719import org .elasticsearch .rest .RestResponse ;
2123import org .elasticsearch .test .rest .RestActionTestCase ;
2224import org .junit .AfterClass ;
2325import 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 ;
2432
2533import static java .util .Collections .emptyMap ;
2634import static org .elasticsearch .index .seqno .SequenceNumbers .UNASSIGNED_SEQ_NO ;
2735import static org .elasticsearch .rest .RestStatus .OK ;
2836import static org .hamcrest .Matchers .equalTo ;
37+ import static org .hamcrest .Matchers .instanceOf ;
2938
3039public class RestGetSourceActionTests extends RestActionTestCase {
3140
3241 private static RestRequest request = new FakeRestRequest ();
3342 private static FakeRestChannel channel = new FakeRestChannel (request , true , 0 );
3443 private static RestGetSourceResponseListener listener = new RestGetSourceResponseListener (channel , request );
44+ private final List <String > compatibleMediaType = Collections .singletonList (randomCompatibleMediaType (RestApiVersion .V_7 ));
3545
3646 @ Before
3747 public void setUpAction () {
3848 controller ().registerHandler (new RestGetSourceAction ());
49+ verifyingClient .setExecuteVerifier ((actionType , request ) -> {
50+ assertThat (request , instanceOf (GetRequest .class ));
51+ return Mockito .mock (GetResponse .class );
52+ });
3953 }
4054
4155 @ AfterClass
@@ -44,6 +58,7 @@ public static void cleanupReferences() {
4458 channel = null ;
4559 listener = null ;
4660 }
61+
4762 public void testRestGetSourceAction () throws Exception {
4863 final BytesReference source = new BytesArray ("{\" foo\" : \" bar\" }" );
4964 final GetResponse response =
@@ -73,4 +88,57 @@ public void testRestGetSourceActionWithMissingDocumentSource() {
7388
7489 assertThat (exception .getMessage (), equalTo ("Source not found [index1]/[1]" ));
7590 }
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+
76144}
0 commit comments