|
19 | 19 |
|
20 | 20 | package org.elasticsearch.client;
|
21 | 21 |
|
22 |
| -import org.apache.http.entity.ContentType; |
23 |
| -import org.apache.http.entity.StringEntity; |
24 | 22 | import org.elasticsearch.ElasticsearchException;
|
25 | 23 | import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest;
|
26 | 24 | import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse;
|
| 25 | +import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; |
| 26 | +import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; |
| 27 | +import org.elasticsearch.common.xcontent.XContentType; |
| 28 | +import org.elasticsearch.repositories.fs.FsRepository; |
27 | 29 | import org.elasticsearch.rest.RestStatus;
|
28 | 30 |
|
29 | 31 | import java.io.IOException;
|
30 |
| -import java.util.Collections; |
31 | 32 |
|
32 | 33 | import static org.hamcrest.Matchers.equalTo;
|
33 | 34 |
|
34 | 35 | public class SnapshotIT extends ESRestHighLevelClientTestCase {
|
35 | 36 |
|
36 |
| - public void testModulesGetRepositoriesUsingParams() throws IOException { |
37 |
| - String repository = "test"; |
38 |
| - String repositorySettings = "{\"type\":\"fs\", \"settings\":{\"location\": \".\"}}"; |
39 |
| - highLevelClient().getLowLevelClient().performRequest("put", "_snapshot/" + repository, Collections.emptyMap(), |
40 |
| - new StringEntity(repositorySettings, ContentType.APPLICATION_JSON)); |
41 |
| - |
42 |
| - highLevelClient().getLowLevelClient().performRequest("put", "_snapshot/" + repository + "_other", Collections.emptyMap(), |
43 |
| - new StringEntity(repositorySettings, ContentType.APPLICATION_JSON)); |
| 37 | + private PutRepositoryResponse createTestRepository(String repository, String type, String settings) throws IOException { |
| 38 | + PutRepositoryRequest request = new PutRepositoryRequest(repository); |
| 39 | + request.settings(settings, XContentType.JSON); |
| 40 | + request.type(type); |
| 41 | + return execute(request, highLevelClient().snapshot()::createRepository, |
| 42 | + highLevelClient().snapshot()::createRepositoryAsync); |
44 | 43 |
|
45 |
| - { |
46 |
| - GetRepositoriesRequest request = new GetRepositoriesRequest(); |
47 |
| - request.repositories(new String[]{repository}); |
48 |
| - GetRepositoriesResponse response = execute(request, highLevelClient().snapshot()::getRepositories, |
49 |
| - highLevelClient().snapshot()::getRepositoriesAsync); |
50 |
| - assertThat(1, equalTo(response.repositories().size())); |
51 |
| - } |
52 |
| - { |
53 |
| - GetRepositoriesRequest request = new GetRepositoriesRequest(); |
54 |
| - GetRepositoriesResponse response = execute(request, highLevelClient().snapshot()::getRepositories, |
55 |
| - highLevelClient().snapshot()::getRepositoriesAsync); |
56 |
| - assertThat(2, equalTo(response.repositories().size())); |
57 |
| - } |
58 | 44 | }
|
59 | 45 |
|
60 |
| - public void testModulesGetDefaultRepositories() throws IOException { |
61 |
| - String repositorySettings = "{\"type\":\"fs\", \"settings\":{\"location\": \".\"}}"; |
62 |
| - GetRepositoriesRequest request = new GetRepositoriesRequest(); |
| 46 | + public void testCreateRepository() throws IOException { |
| 47 | + PutRepositoryResponse response = createTestRepository("test", FsRepository.TYPE, "{\"location\": \".\"}"); |
| 48 | + assertTrue(response.isAcknowledged()); |
| 49 | + } |
63 | 50 |
|
64 |
| - highLevelClient().getLowLevelClient().performRequest("put", "_snapshot/test", Collections.emptyMap(), |
65 |
| - new StringEntity(repositorySettings, ContentType.APPLICATION_JSON)); |
| 51 | + public void testModulesGetRepositoriesUsingParams() throws IOException { |
| 52 | + String testRepository = "test"; |
| 53 | + assertTrue(createTestRepository(testRepository, FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged()); |
| 54 | + assertTrue(createTestRepository("other", FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged()); |
66 | 55 |
|
| 56 | + GetRepositoriesRequest request = new GetRepositoriesRequest(); |
| 57 | + request.repositories(new String[]{testRepository}); |
67 | 58 | GetRepositoriesResponse response = execute(request, highLevelClient().snapshot()::getRepositories,
|
68 | 59 | highLevelClient().snapshot()::getRepositoriesAsync);
|
69 | 60 | assertThat(1, equalTo(response.repositories().size()));
|
70 | 61 | }
|
71 | 62 |
|
| 63 | + public void testModulesGetDefaultRepositories() throws IOException { |
| 64 | + assertTrue(createTestRepository("other", FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged()); |
| 65 | + assertTrue(createTestRepository("test", FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged()); |
| 66 | + |
| 67 | + GetRepositoriesResponse response = execute(new GetRepositoriesRequest(), highLevelClient().snapshot()::getRepositories, |
| 68 | + highLevelClient().snapshot()::getRepositoriesAsync); |
| 69 | + assertThat(2, equalTo(response.repositories().size())); |
| 70 | + } |
| 71 | + |
72 | 72 | public void testModulesGetRepositoriesNonExistent() throws IOException {
|
73 | 73 | String repository = "doesnotexist";
|
74 | 74 | GetRepositoriesRequest request = new GetRepositoriesRequest(new String[]{repository});
|
|
0 commit comments