|
19 | 19 |
|
20 | 20 | package org.elasticsearch.search.scroll; |
21 | 21 |
|
| 22 | +import org.elasticsearch.action.ActionListener; |
22 | 23 | import org.elasticsearch.action.search.ClearScrollRequest; |
| 24 | +import org.elasticsearch.client.node.NodeClient; |
23 | 25 | import org.elasticsearch.common.bytes.BytesArray; |
24 | 26 | import org.elasticsearch.common.settings.Settings; |
| 27 | +import org.elasticsearch.common.xcontent.NamedXContentRegistry; |
25 | 28 | import org.elasticsearch.common.xcontent.XContentFactory; |
26 | 29 | import org.elasticsearch.common.xcontent.XContentParser; |
27 | 30 | import org.elasticsearch.common.xcontent.XContentType; |
| 31 | +import org.elasticsearch.rest.RestChannel; |
28 | 32 | import org.elasticsearch.rest.RestController; |
29 | 33 | import org.elasticsearch.rest.RestRequest; |
30 | 34 | import org.elasticsearch.rest.action.search.RestClearScrollAction; |
31 | 35 | import org.elasticsearch.test.ESTestCase; |
32 | 36 | import org.elasticsearch.test.rest.FakeRestRequest; |
| 37 | +import org.mockito.ArgumentCaptor; |
33 | 38 |
|
| 39 | +import java.util.Arrays; |
| 40 | +import java.util.Collections; |
| 41 | +import java.util.List; |
| 42 | +import java.util.stream.Collectors; |
| 43 | + |
| 44 | +import static org.elasticsearch.mock.orig.Mockito.verify; |
34 | 45 | import static org.hamcrest.Matchers.contains; |
35 | 46 | import static org.hamcrest.Matchers.equalTo; |
36 | 47 | import static org.hamcrest.Matchers.startsWith; |
| 48 | +import static org.mockito.Matchers.any; |
37 | 49 | import static org.mockito.Mockito.mock; |
38 | 50 |
|
39 | 51 | public class RestClearScrollActionTests extends ESTestCase { |
@@ -68,4 +80,19 @@ public void testParseClearScrollRequestWithUnknownParamThrowsException() throws |
68 | 80 | assertThat(e.getMessage(), startsWith("Unknown parameter [unknown]")); |
69 | 81 | } |
70 | 82 |
|
| 83 | + public void testParseClearScrollPlaintext() throws Exception { |
| 84 | + RestClearScrollAction action = new RestClearScrollAction(Settings.EMPTY, mock(RestController.class)); |
| 85 | + NodeClient mockNodeClient = mock(NodeClient.class); |
| 86 | + final List<String> scrollIds = Arrays.asList(generateRandomStringArray(4, 30, false, false)); |
| 87 | + final String content = scrollIds.stream().collect(Collectors.joining(",")); |
| 88 | + FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) |
| 89 | + .withContent(new BytesArray(content), null) |
| 90 | + .withHeaders(Collections.singletonMap("Content-Type", Collections.singletonList("text/plain"))) |
| 91 | + .build(); |
| 92 | + action.handleRequest(fakeRestRequest, mock(RestChannel.class), mockNodeClient); |
| 93 | + ArgumentCaptor<ClearScrollRequest> captor = ArgumentCaptor.forClass(ClearScrollRequest.class); |
| 94 | + verify(mockNodeClient).clearScroll(captor.capture(), any(ActionListener.class)); |
| 95 | + |
| 96 | + assertEquals(scrollIds, captor.getValue().getScrollIds()); |
| 97 | + } |
71 | 98 | } |
0 commit comments