|
11 | 11 | class SimilarDocumentRequestTest { |
12 | 12 |
|
13 | 13 | @Test |
14 | | - void toStringSimpleRequest() { |
15 | | - SimilarDocumentRequest classToTest = new SimilarDocumentRequest().setId("123"); |
16 | | - |
17 | | - JSONObject jsonObject = new JSONObject(classToTest.toString()); |
18 | | - assertThat(jsonObject.getString("id"), is(equalTo("123"))); |
19 | | - } |
20 | | - |
21 | | - @Test |
22 | | - void toStringWithEmbedder() { |
23 | | - SimilarDocumentRequest classToTest = |
24 | | - new SimilarDocumentRequest().setId("123").setEmbedder("custom"); |
25 | | - |
26 | | - JSONObject jsonObject = new JSONObject(classToTest.toString()); |
27 | | - assertThat(jsonObject.getString("id"), is(equalTo("123"))); |
28 | | - assertThat(jsonObject.getString("embedder"), is(equalTo("custom"))); |
29 | | - } |
30 | | - |
31 | | - @Test |
32 | | - void toStringWithAttributesToRetrieve() { |
33 | | - SimilarDocumentRequest classToTest = |
34 | | - new SimilarDocumentRequest() |
35 | | - .setId("123") |
36 | | - .setAttributesToRetrieve(new String[] {"title", "description"}); |
37 | | - |
38 | | - JSONObject jsonObject = new JSONObject(classToTest.toString()); |
39 | | - assertThat(jsonObject.getString("id"), is(equalTo("123"))); |
40 | | - assertThat( |
41 | | - jsonObject.getJSONArray("attributesToRetrieve").getString(0), is(equalTo("title"))); |
42 | | - assertThat( |
43 | | - jsonObject.getJSONArray("attributesToRetrieve").getString(1), |
44 | | - is(equalTo("description"))); |
45 | | - } |
46 | | - |
47 | | - @Test |
48 | | - void toStringWithOffsetAndLimit() { |
49 | | - SimilarDocumentRequest classToTest = |
50 | | - new SimilarDocumentRequest().setId("123").setOffset(10).setLimit(20); |
51 | | - |
52 | | - JSONObject jsonObject = new JSONObject(classToTest.toString()); |
53 | | - assertThat(jsonObject.getString("id"), is(equalTo("123"))); |
54 | | - assertThat(jsonObject.getInt("offset"), is(equalTo(10))); |
55 | | - assertThat(jsonObject.getInt("limit"), is(equalTo(20))); |
56 | | - } |
57 | | - |
58 | | - @Test |
59 | | - void toStringWithFilter() { |
60 | | - SimilarDocumentRequest classToTest = |
61 | | - new SimilarDocumentRequest().setId("123").setFilter("genre = 'action'"); |
62 | | - |
63 | | - JSONObject jsonObject = new JSONObject(classToTest.toString()); |
64 | | - assertThat(jsonObject.getString("id"), is(equalTo("123"))); |
65 | | - assertThat(jsonObject.getString("filter"), is(equalTo("genre = 'action'"))); |
| 14 | + void toStringDefaultValues() { |
| 15 | + SimilarDocumentRequest request = new SimilarDocumentRequest(); |
| 16 | + JSONObject json = new JSONObject(request.toString()); |
| 17 | + |
| 18 | + // only id and embedder should be absent (null) by default |
| 19 | + assertThat(json.has("id"), is(false)); |
| 20 | + assertThat(json.has("embedder"), is(false)); |
| 21 | + assertThat(json.has("attributesToRetrieve"), is(false)); |
| 22 | + assertThat(json.has("offset"), is(false)); |
| 23 | + assertThat(json.has("limit"), is(false)); |
| 24 | + assertThat(json.has("filter"), is(false)); |
| 25 | + assertThat(json.has("showRankingScore"), is(false)); |
| 26 | + assertThat(json.has("showRankingScoreDetails"), is(false)); |
| 27 | + assertThat(json.has("rankingScoreThreshold"), is(false)); |
| 28 | + assertThat(json.has("retrieveVectors"), is(false)); |
66 | 29 | } |
67 | 30 |
|
68 | 31 | @Test |
69 | | - void toStringWithShowRankingScore() { |
70 | | - SimilarDocumentRequest classToTest = |
71 | | - new SimilarDocumentRequest().setId("123").setShowRankingScore(true); |
72 | | - |
73 | | - JSONObject jsonObject = new JSONObject(classToTest.toString()); |
74 | | - assertThat(jsonObject.getString("id"), is(equalTo("123"))); |
75 | | - assertThat(jsonObject.getBoolean("showRankingScore"), is(equalTo(true))); |
76 | | - } |
77 | | - |
78 | | - @Test |
79 | | - void toStringWithShowRankingScoreDetails() { |
80 | | - SimilarDocumentRequest classToTest = |
81 | | - new SimilarDocumentRequest().setId("123").setShowRankingScoreDetails(true); |
82 | | - |
83 | | - JSONObject jsonObject = new JSONObject(classToTest.toString()); |
84 | | - assertThat(jsonObject.getString("id"), is(equalTo("123"))); |
85 | | - assertThat(jsonObject.getBoolean("showRankingScoreDetails"), is(equalTo(true))); |
86 | | - } |
87 | | - |
88 | | - @Test |
89 | | - void toStringWithRankingScoreThreshold() { |
90 | | - SimilarDocumentRequest classToTest = |
91 | | - new SimilarDocumentRequest().setId("123").setRankingScoreThreshold(0.5); |
92 | | - |
93 | | - JSONObject jsonObject = new JSONObject(classToTest.toString()); |
94 | | - assertThat(jsonObject.getString("id"), is(equalTo("123"))); |
95 | | - assertThat(jsonObject.getDouble("rankingScoreThreshold"), is(equalTo(0.5))); |
96 | | - } |
97 | | - |
98 | | - @Test |
99 | | - void toStringWithRetrieveVectors() { |
100 | | - SimilarDocumentRequest classToTest = |
101 | | - new SimilarDocumentRequest().setId("123").setRetrieveVectors(true); |
102 | | - |
103 | | - JSONObject jsonObject = new JSONObject(classToTest.toString()); |
104 | | - assertThat(jsonObject.getString("id"), is(equalTo("123"))); |
105 | | - assertThat(jsonObject.getBoolean("retrieveVectors"), is(equalTo(true))); |
106 | | - } |
107 | | - |
108 | | - @Test |
109 | | - void toStringWithAllParameters() { |
110 | | - SimilarDocumentRequest classToTest = |
111 | | - new SimilarDocumentRequest() |
112 | | - .setId("123") |
113 | | - .setEmbedder("custom") |
114 | | - .setAttributesToRetrieve(new String[] {"title", "description"}) |
115 | | - .setOffset(10) |
116 | | - .setLimit(20) |
117 | | - .setFilter("genre = 'action'") |
118 | | - .setShowRankingScore(true) |
119 | | - .setShowRankingScoreDetails(true) |
120 | | - .setRankingScoreThreshold(0.5) |
121 | | - .setRetrieveVectors(true); |
122 | | - |
123 | | - JSONObject jsonObject = new JSONObject(classToTest.toString()); |
124 | | - assertThat(jsonObject.getString("id"), is(equalTo("123"))); |
125 | | - assertThat(jsonObject.getString("embedder"), is(equalTo("custom"))); |
126 | | - assertThat( |
127 | | - jsonObject.getJSONArray("attributesToRetrieve").getString(0), is(equalTo("title"))); |
128 | | - assertThat( |
129 | | - jsonObject.getJSONArray("attributesToRetrieve").getString(1), |
130 | | - is(equalTo("description"))); |
131 | | - assertThat(jsonObject.getInt("offset"), is(equalTo(10))); |
132 | | - assertThat(jsonObject.getInt("limit"), is(equalTo(20))); |
133 | | - assertThat(jsonObject.getString("filter"), is(equalTo("genre = 'action'"))); |
134 | | - assertThat(jsonObject.getBoolean("showRankingScore"), is(equalTo(true))); |
135 | | - assertThat(jsonObject.getBoolean("showRankingScoreDetails"), is(equalTo(true))); |
136 | | - assertThat(jsonObject.getDouble("rankingScoreThreshold"), is(equalTo(0.5))); |
137 | | - assertThat(jsonObject.getBoolean("retrieveVectors"), is(equalTo(true))); |
| 32 | + void toStringAllParameters() { |
| 33 | + SimilarDocumentRequest request = new SimilarDocumentRequest() |
| 34 | + .setId("123") |
| 35 | + .setEmbedder("custom") |
| 36 | + .setAttributesToRetrieve(new String[]{"title", "description"}) |
| 37 | + .setOffset(10) |
| 38 | + .setLimit(20) |
| 39 | + .setFilter("genre = 'action'") |
| 40 | + .setShowRankingScore(true) |
| 41 | + .setShowRankingScoreDetails(true) |
| 42 | + .setRankingScoreThreshold(0.5) |
| 43 | + .setRetrieveVectors(true); |
| 44 | + |
| 45 | + JSONObject json = new JSONObject(request.toString()); |
| 46 | + assertThat(json.getString("id"), is(equalTo("123"))); |
| 47 | + assertThat(json.getString("embedder"), is(equalTo("custom"))); |
| 48 | + assertThat(json.getJSONArray("attributesToRetrieve").getString(0), is(equalTo("title"))); |
| 49 | + assertThat(json.getJSONArray("attributesToRetrieve").getString(1), is(equalTo("description"))); |
| 50 | + assertThat(json.getInt("offset"), is(equalTo(10))); |
| 51 | + assertThat(json.getInt("limit"), is(equalTo(20))); |
| 52 | + assertThat(json.getString("filter"), is(equalTo("genre = 'action'"))); |
| 53 | + assertThat(json.getBoolean("showRankingScore"), is(equalTo(true))); |
| 54 | + assertThat(json.getBoolean("showRankingScoreDetails"), is(equalTo(true))); |
| 55 | + assertThat(json.getDouble("rankingScoreThreshold"), is(equalTo(0.5))); |
| 56 | + assertThat(json.getBoolean("retrieveVectors"), is(equalTo(true))); |
138 | 57 | } |
139 | 58 |
|
140 | 59 | @Test |
141 | 60 | void gettersAndSetters() { |
142 | | - SimilarDocumentRequest classToTest = |
143 | | - new SimilarDocumentRequest() |
144 | | - .setId("123") |
145 | | - .setEmbedder("custom") |
146 | | - .setAttributesToRetrieve(new String[] {"title", "description"}) |
147 | | - .setOffset(10) |
148 | | - .setLimit(20) |
149 | | - .setFilter("genre = 'action'") |
150 | | - .setShowRankingScore(true) |
151 | | - .setShowRankingScoreDetails(true) |
152 | | - .setRankingScoreThreshold(0.5) |
153 | | - .setRetrieveVectors(true); |
154 | | - |
155 | | - assertThat(classToTest.getId(), is(equalTo("123"))); |
156 | | - assertThat(classToTest.getEmbedder(), is(equalTo("custom"))); |
157 | | - assertThat( |
158 | | - classToTest.getAttributesToRetrieve(), |
159 | | - is(equalTo(new String[] {"title", "description"}))); |
160 | | - assertThat(classToTest.getOffset(), is(equalTo(10))); |
161 | | - assertThat(classToTest.getLimit(), is(equalTo(20))); |
162 | | - assertThat(classToTest.getFilter(), is(equalTo("genre = 'action'"))); |
163 | | - assertThat(classToTest.getShowRankingScore(), is(equalTo(true))); |
164 | | - assertThat(classToTest.getShowRankingScoreDetails(), is(equalTo(true))); |
165 | | - assertThat(classToTest.getRankingScoreThreshold(), is(equalTo(0.5))); |
166 | | - assertThat(classToTest.getRetrieveVectors(), is(equalTo(true))); |
167 | | - } |
168 | | - |
169 | | - @Test |
170 | | - void defaultValues() { |
171 | | - SimilarDocumentRequest classToTest = new SimilarDocumentRequest(); |
172 | | - |
173 | | - assertThat(classToTest.getId(), is(nullValue())); |
174 | | - assertThat(classToTest.getEmbedder(), is(nullValue())); |
175 | | - assertThat(classToTest.getAttributesToRetrieve(), is(nullValue())); |
176 | | - assertThat(classToTest.getOffset(), is(nullValue())); |
177 | | - assertThat(classToTest.getLimit(), is(nullValue())); |
178 | | - assertThat(classToTest.getFilter(), is(nullValue())); |
179 | | - assertThat(classToTest.getShowRankingScore(), is(nullValue())); |
180 | | - assertThat(classToTest.getShowRankingScoreDetails(), is(nullValue())); |
181 | | - assertThat(classToTest.getRankingScoreThreshold(), is(nullValue())); |
182 | | - assertThat(classToTest.getRetrieveVectors(), is(nullValue())); |
| 61 | + SimilarDocumentRequest request = SimilarDocumentRequest.builder() |
| 62 | + .id("123") |
| 63 | + .embedder("custom") |
| 64 | + .attributesToRetrieve(new String[]{"title", "description"}) |
| 65 | + .offset(10) |
| 66 | + .limit(20) |
| 67 | + .filter("genre = 'action'") |
| 68 | + .showRankingScore(true) |
| 69 | + .showRankingScoreDetails(true) |
| 70 | + .rankingScoreThreshold(0.5) |
| 71 | + .retrieveVectors(true) |
| 72 | + .build(); |
| 73 | + |
| 74 | + assertThat(request.getId(), is(equalTo("123"))); |
| 75 | + assertThat(request.getEmbedder(), is(equalTo("custom"))); |
| 76 | + assertThat(request.getAttributesToRetrieve(), is(equalTo(new String[]{"title", "description"}))); |
| 77 | + assertThat(request.getOffset(), is(equalTo(10))); |
| 78 | + assertThat(request.getLimit(), is(equalTo(20))); |
| 79 | + assertThat(request.getFilter(), is(equalTo("genre = 'action'"))); |
| 80 | + assertThat(request.getShowRankingScore(), is(equalTo(true))); |
| 81 | + assertThat(request.getShowRankingScoreDetails(), is(equalTo(true))); |
| 82 | + assertThat(request.getRankingScoreThreshold(), is(equalTo(0.5))); |
| 83 | + assertThat(request.getRetrieveVectors(), is(equalTo(true))); |
183 | 84 | } |
184 | 85 | } |
0 commit comments