|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0 and the Server Side Public License, v 1; you may not use this file except |
| 5 | + * in compliance with, at your election, the Elastic License 2.0 or the Server |
| 6 | + * Side Public License, v 1. |
| 7 | + */ |
| 8 | + |
| 9 | +package org.elasticsearch.script.mustache; |
| 10 | + |
| 11 | +import org.elasticsearch.common.RestApiVersion; |
| 12 | +import org.elasticsearch.common.bytes.BytesArray; |
| 13 | +import org.elasticsearch.common.settings.Settings; |
| 14 | +import org.elasticsearch.common.xcontent.XContentType; |
| 15 | +import org.elasticsearch.rest.RestRequest; |
| 16 | +import org.elasticsearch.test.rest.FakeRestRequest; |
| 17 | +import org.elasticsearch.test.rest.RestActionTestCase; |
| 18 | +import org.junit.Before; |
| 19 | +import org.mockito.Mockito; |
| 20 | + |
| 21 | +import java.nio.charset.StandardCharsets; |
| 22 | +import java.util.Collections; |
| 23 | +import java.util.List; |
| 24 | +import java.util.Map; |
| 25 | + |
| 26 | +public class RestMultiSearchTemplateActionTests extends RestActionTestCase { |
| 27 | + final List<String> contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7)); |
| 28 | + |
| 29 | + @Before |
| 30 | + public void setUpAction() { |
| 31 | + controller().registerHandler(new RestMultiSearchTemplateAction(Settings.EMPTY)); |
| 32 | + //todo how to workaround this? we get AssertionError without this |
| 33 | + verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(MultiSearchTemplateResponse.class)); |
| 34 | + verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(MultiSearchTemplateResponse.class)); |
| 35 | + } |
| 36 | + |
| 37 | + public void testTypeInPath() { |
| 38 | + String content = "{ \"index\": \"some_index\" } \n" + |
| 39 | + "{\"source\": {\"query\" : {\"match_all\" :{}}}} \n"; |
| 40 | + BytesArray bytesContent = new BytesArray(content.getBytes(StandardCharsets.UTF_8)); |
| 41 | + |
| 42 | + RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) |
| 43 | + .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader)) |
| 44 | + .withMethod(RestRequest.Method.GET) |
| 45 | + .withPath("/some_index/some_type/_msearch/template") |
| 46 | + .withContent(bytesContent, null) |
| 47 | + .build(); |
| 48 | + |
| 49 | + dispatchRequest(request); |
| 50 | + assertWarnings(RestMultiSearchTemplateAction.TYPES_DEPRECATION_MESSAGE); |
| 51 | + } |
| 52 | + |
| 53 | + public void testTypeInBody() { |
| 54 | + String content = "{ \"index\": \"some_index\", \"type\": \"some_type\" } \n" + |
| 55 | + "{\"source\": {\"query\" : {\"match_all\" :{}}}} \n"; |
| 56 | + BytesArray bytesContent = new BytesArray(content.getBytes(StandardCharsets.UTF_8)); |
| 57 | + |
| 58 | + RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) |
| 59 | + .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader)) |
| 60 | + .withPath("/some_index/_msearch/template") |
| 61 | + .withContent(bytesContent, null) |
| 62 | + .build(); |
| 63 | + |
| 64 | + dispatchRequest(request); |
| 65 | + assertWarnings(RestMultiSearchTemplateAction.TYPES_DEPRECATION_MESSAGE); |
| 66 | + } |
| 67 | +} |
0 commit comments