@@ -54,11 +54,7 @@ public void testRoutes() {
5454
5555 @ Test
5656 public void testGetGrammar_ReturnsBundle () throws Exception {
57- FakeRestRequest request =
58- new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
59- .withMethod (RestRequest .Method .GET )
60- .withPath ("/_plugins/_ppl/_grammar" )
61- .build ();
57+ FakeRestRequest request = newGrammarGetRequest ();
6258
6359 MockRestChannel channel = new MockRestChannel (request , true );
6460 action .handleRequest (request , channel , client );
@@ -112,19 +108,11 @@ protected GrammarBundle buildBundle() {
112108 }
113109 };
114110
115- FakeRestRequest request1 =
116- new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
117- .withMethod (RestRequest .Method .GET )
118- .withPath ("/_plugins/_ppl/_grammar" )
119- .build ();
111+ FakeRestRequest request1 = newGrammarGetRequest ();
120112 MockRestChannel channel1 = new MockRestChannel (request1 , true );
121113 countingAction .handleRequest (request1 , channel1 , client );
122114
123- FakeRestRequest request2 =
124- new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
125- .withMethod (RestRequest .Method .GET )
126- .withPath ("/_plugins/_ppl/_grammar" )
127- .build ();
115+ FakeRestRequest request2 = newGrammarGetRequest ();
128116 MockRestChannel channel2 = new MockRestChannel (request2 , true );
129117 countingAction .handleRequest (request2 , channel2 , client );
130118
@@ -147,23 +135,15 @@ protected GrammarBundle buildBundle() {
147135 }
148136 };
149137
150- FakeRestRequest request1 =
151- new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
152- .withMethod (RestRequest .Method .GET )
153- .withPath ("/_plugins/_ppl/_grammar" )
154- .build ();
138+ FakeRestRequest request1 = newGrammarGetRequest ();
155139 MockRestChannel channel1 = new MockRestChannel (request1 , true );
156140 countingAction .handleRequest (request1 , channel1 , client );
157141 assertEquals (RestStatus .OK , channel1 .getResponse ().status ());
158142 assertEquals ("Bundle should be built on first request" , 1 , buildCount .get ());
159143
160144 countingAction .invalidateCache ();
161145
162- FakeRestRequest request2 =
163- new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
164- .withMethod (RestRequest .Method .GET )
165- .withPath ("/_plugins/_ppl/_grammar" )
166- .build ();
146+ FakeRestRequest request2 = newGrammarGetRequest ();
167147 MockRestChannel channel2 = new MockRestChannel (request2 , true );
168148 countingAction .handleRequest (request2 , channel2 , client );
169149 assertEquals (RestStatus .OK , channel2 .getResponse ().status ());
@@ -180,11 +160,7 @@ protected GrammarBundle buildBundle() {
180160 }
181161 };
182162
183- FakeRestRequest request =
184- new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
185- .withMethod (RestRequest .Method .GET )
186- .withPath ("/_plugins/_ppl/_grammar" )
187- .build ();
163+ FakeRestRequest request = newGrammarGetRequest ();
188164 MockRestChannel channel = new MockRestChannel (request , true );
189165 failingAction .handleRequest (request , channel , client );
190166
@@ -201,17 +177,20 @@ protected GrammarBundle buildBundle() {
201177 }
202178 };
203179
204- FakeRestRequest request =
205- new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
206- .withMethod (RestRequest .Method .GET )
207- .withPath ("/_plugins/_ppl/_grammar" )
208- .build ();
180+ FakeRestRequest request = newGrammarGetRequest ();
209181 MockRestChannel channel = new MockRestChannel (request , true );
210182 nullBundleAction .handleRequest (request , channel , client );
211183
212184 assertEquals (RestStatus .INTERNAL_SERVER_ERROR , channel .getResponse ().status ());
213185 }
214186
187+ private static FakeRestRequest newGrammarGetRequest () {
188+ return new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
189+ .withMethod (RestRequest .Method .GET )
190+ .withPath ("/_plugins/_ppl/_grammar" )
191+ .build ();
192+ }
193+
215194 /** Mock RestChannel to capture responses */
216195 private static class MockRestChannel implements RestChannel {
217196 private final RestRequest request ;
0 commit comments