forked from meilisearch/meilisearch-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportRequestTest.java
More file actions
93 lines (79 loc) · 3.69 KB
/
ExportRequestTest.java
File metadata and controls
93 lines (79 loc) · 3.69 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.meilisearch.sdk;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
public class ExportRequestTest {
@Test
void toStringSimpleExportIndexFilter() {
ExportIndexFilter filter = ExportIndexFilter.builder().build();
JSONObject json = new JSONObject(filter.toString());
assertThat(json.has("overrideSettings"), is(false));
assertThat(json.has("filter"), is(false));
}
@Test
void toStringExportIndexFilterWithOverride() {
ExportIndexFilter filter = ExportIndexFilter.builder().overrideSettings(true).build();
JSONObject json = new JSONObject(filter.toString());
assertThat(json.getBoolean("overrideSettings"), is(true));
assertThat(json.has("filter"), is(false));
}
@Test
void toStringExportIndexFilterWithFilter() {
ExportIndexFilter filter = ExportIndexFilter.builder().filter("status = 'active'").build();
JSONObject json = new JSONObject(filter.toString());
assertThat(json.getString("filter"), is(equalTo("status = 'active'")));
assertThat(json.has("overrideSettings"), is(false));
}
@Test
void toStringSimpleExportRequest() {
ExportRequest request =
ExportRequest.builder().url("http://localhost:7711").payloadSize("123 MiB").build();
JSONObject json = new JSONObject(request.toString());
assertThat(json.getString("url"), is(equalTo("http://localhost:7711")));
assertThat(json.getString("payloadSize"), is(equalTo("123 MiB")));
assertThat(json.has("apiKey"), is(false));
assertThat(json.has("indexes"), is(false));
}
@Test
void toStringExportRequestWithIndexes() {
Map<String, ExportIndexFilter> indexes = new HashMap<>();
indexes.put("*", ExportIndexFilter.builder().overrideSettings(true).build());
ExportRequest request =
ExportRequest.builder()
.url("http://localhost:7711")
.payloadSize("123 MiB")
.indexes(indexes)
.build();
JSONObject json = new JSONObject(request.toString());
assertThat(json.getString("url"), is(equalTo("http://localhost:7711")));
assertThat(json.getString("payloadSize"), is(equalTo("123 MiB")));
assertThat(json.has("apiKey"), is(false));
JSONObject indexesJson = json.getJSONObject("indexes");
JSONObject starIndex = indexesJson.getJSONObject("*");
assertThat(starIndex.has("filter"), is(false));
assertThat(starIndex.getBoolean("overrideSettings"), is(true));
}
@Test
void gettersExportRequest() {
Map<String, ExportIndexFilter> indexes = new HashMap<>();
indexes.put(
"myindex",
ExportIndexFilter.builder().filter("id > 10").overrideSettings(false).build());
ExportRequest request =
ExportRequest.builder()
.url("http://localhost:7711")
.apiKey("mykey")
.payloadSize("50 MiB")
.indexes(indexes)
.build();
assertThat(request.getUrl(), is(equalTo("http://localhost:7711")));
assertThat(request.getApiKey(), is(equalTo("mykey")));
assertThat(request.getPayloadSize(), is(equalTo("50 MiB")));
assertThat(request.getIndexes().get("myindex").getFilter(), is(equalTo("id > 10")));
assertThat(request.getIndexes().get("myindex").isOverrideSettings(), is(false));
}
}