|
19 | 19 |
|
20 | 20 | package org.elasticsearch.action.admin.indices.shrink; |
21 | 21 |
|
22 | | -import org.elasticsearch.action.ActionRequestValidationException; |
23 | 22 | import org.elasticsearch.action.admin.indices.alias.Alias; |
24 | 23 | import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; |
25 | 24 | import org.elasticsearch.action.admin.indices.create.CreateIndexRequestTests; |
|
30 | 29 | import org.elasticsearch.index.RandomCreateIndexGenerator; |
31 | 30 | import org.elasticsearch.test.ESTestCase; |
32 | 31 | import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; |
33 | | -import org.junit.Assert; |
34 | 32 |
|
35 | 33 | import java.io.IOException; |
36 | 34 | import java.util.function.Consumer; |
| 35 | +import java.util.function.Supplier; |
37 | 36 |
|
38 | 37 | import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; |
39 | 38 | import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS; |
40 | | -import static org.hamcrest.Matchers.equalTo; |
41 | | -import static org.hamcrest.Matchers.hasSize; |
| 39 | +import static org.hamcrest.Matchers.containsString; |
| 40 | +import static org.hamcrest.Matchers.hasToString; |
42 | 41 |
|
43 | 42 | public class ResizeRequestTests extends ESTestCase { |
44 | 43 |
|
45 | 44 | public void testCopySettingsValidation() { |
46 | | - runTestCopySettingsValidation(false, e -> { |
47 | | - assertNotNull(e); |
48 | | - assertThat(e.validationErrors(), hasSize(1)); |
49 | | - assertThat(e.validationErrors().get(0), equalTo("[copySettings] can not be explicitly set to [false]")); |
| 45 | + runTestCopySettingsValidation(false, r -> { |
| 46 | + final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, r::get); |
| 47 | + assertThat(e, hasToString(containsString("[copySettings] can not be explicitly set to [false]"))); |
50 | 48 | }); |
51 | 49 |
|
52 | | - runTestCopySettingsValidation(null, Assert::assertNull); |
53 | | - runTestCopySettingsValidation(true, Assert::assertNull); |
| 50 | + runTestCopySettingsValidation(null, r -> assertNull(r.get().getCopySettings())); |
| 51 | + runTestCopySettingsValidation(true, r -> assertTrue(r.get().getCopySettings())); |
54 | 52 | } |
55 | 53 |
|
56 | | - private void runTestCopySettingsValidation(final Boolean copySettings, final Consumer<ActionRequestValidationException> consumer) { |
57 | | - final ResizeRequest request = new ResizeRequest(); |
58 | | - request.setSourceIndex("source"); |
59 | | - request.setTargetIndex(new CreateIndexRequest("target")); |
60 | | - request.setCopySettings(copySettings); |
61 | | - final ActionRequestValidationException e = request.validate(); |
62 | | - consumer.accept(e); |
| 54 | + private void runTestCopySettingsValidation(final Boolean copySettings, final Consumer<Supplier<ResizeRequest>> consumer) { |
| 55 | + consumer.accept(() -> { |
| 56 | + final ResizeRequest request = new ResizeRequest(); |
| 57 | + request.setCopySettings(copySettings); |
| 58 | + return request; |
| 59 | + }); |
63 | 60 | } |
64 | 61 |
|
65 | 62 | public void testToXContent() throws IOException { |
|
0 commit comments