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
100 lines (85 loc) · 4.11 KB
/
ExportRequestTest.java
File metadata and controls
100 lines (85 loc) · 4.11 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
94
95
96
97
98
99
100
package com.meilisearch.sdk;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
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();
String expected = "{\"overrideSettings\":false}";
assertThat(filter.toString(), is(equalTo(expected)));
assertThat(filter.getFilter(), is(nullValue()));
assertThat(filter.isOverrideSettings(), is(false));
}
@Test
void toStringExportIndexFilterWithOverride() {
ExportIndexFilter filter = ExportIndexFilter.builder().overrideSettings(true).build();
String expected = "{\"overrideSettings\":true}";
assertThat(filter.toString(), is(equalTo(expected)));
assertThat(filter.isOverrideSettings(), is(true));
}
@Test
void toStringExportIndexFilterWithFilter() {
ExportIndexFilter filter = ExportIndexFilter.builder().filter("status = 'active'").build();
String expected = "{\"filter\":\"status = 'active'\",\"overrideSettings\":false}";
assertThat(filter.toString(), is(equalTo(expected)));
assertThat(filter.getFilter(), is(equalTo("status = 'active'")));
}
@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.isNull("apiKey"), is(true));
assertThat(json.isNull("indexes"), is(true));
}
@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();
String expected =
"{\"url\":\"http://localhost:7711\",\"payloadSize\":\"123 MiB\",\"indexes\":{\"*\":{\"overrideSettings\":true}}}";
JSONObject expectedJson = new JSONObject(expected);
JSONObject json = new JSONObject(request.toString());
assertThat(expectedJson.toString(), is(json.toString()));
assertThat(json.getString("url"), is(equalTo("http://localhost:7711")));
assertThat(json.getString("payloadSize"), is(equalTo("123 MiB")));
assertThat(json.isNull("apiKey"), is(true));
JSONObject indexesJson = json.getJSONObject("indexes");
JSONObject starIndex = indexesJson.getJSONObject("*");
assertThat(starIndex.isNull("filter"), is(true));
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));
}
}