forked from meilisearch/meilisearch-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwapIndexRenameTest.java
More file actions
59 lines (44 loc) · 1.8 KB
/
SwapIndexRenameTest.java
File metadata and controls
59 lines (44 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.meilisearch.sdk;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import com.meilisearch.sdk.model.SwapIndexesParams;
import com.meilisearch.sdk.model.TaskInfo;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class SwapIndexRenameTest {
private MockWebServer server;
private Client client;
@BeforeEach
void setup() throws Exception {
server = new MockWebServer();
server.start();
client = new Client(new Config(server.url("/").toString(), "masterKey"));
}
@AfterEach
void teardown() throws Exception {
server.shutdown();
}
@Test
void testSwapIndexesWithRename() throws Exception {
String jsonResponse = "{ \"taskUid\": 555 }";
server.enqueue(new MockResponse().setBody(jsonResponse).setResponseCode(202));
SwapIndexesParams params =
new SwapIndexesParams()
.setIndexes(new String[] {"indexA", "indexB"})
.setRename(true);
TaskInfo task = client.swapIndexes(new SwapIndexesParams[] {params});
assertThat(task, notNullValue());
assertThat(task.getTaskUid(), equalTo(555));
RecordedRequest req = server.takeRequest();
assertThat(req.getMethod(), equalTo("POST"));
// FIX: Actual path contains double slash
assertThat(req.getPath(), equalTo("//swap-indexes"));
String body = req.getBody().readUtf8();
assertThat(body, containsString("\"indexes\":[\"indexA\",\"indexB\"]"));
assertThat(body, containsString("\"rename\":true"));
}
}