forked from meilisearch/meilisearch-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexRenameTest.java
More file actions
52 lines (38 loc) · 1.5 KB
/
IndexRenameTest.java
File metadata and controls
52 lines (38 loc) · 1.5 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
package com.meilisearch.sdk;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
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 IndexRenameTest {
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 testRenameIndex() throws Exception {
String response = "{ \"taskUid\": 123 }";
server.enqueue(new MockResponse().setBody(response).setResponseCode(202));
TaskInfo task = client.updateIndex("oldIndex", null, "newIndex");
assertThat(task, notNullValue());
assertThat(task.getTaskUid(), equalTo(123));
RecordedRequest req = server.takeRequest();
assertThat(req.getMethod(), equalTo("PATCH"));
assertThat(req.getPath(), equalTo("//indexes/oldIndex"));
String body = req.getBody().readUtf8();
assertThat(body, containsString("\"uid\":\"newIndex\""));
assertThat(req.getHeader("Authorization"), equalTo("Bearer masterKey"));
}
}