Skip to content

Commit 11e881a

Browse files
v1.12.3
- Taxonomy query support - Early Access Feature Support
1 parent b895bc8 commit 11e881a

File tree

1 file changed

+46
-30
lines changed

1 file changed

+46
-30
lines changed

src/test/java/com/contentstack/sdk/TaxonomyTest.java

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.junit.jupiter.api.Assertions;
55
import org.junit.jupiter.api.Test;
66

7-
import java.io.IOException;
7+
import java.util.Arrays;
88
import java.util.HashMap;
99

1010

@@ -32,42 +32,58 @@ public void onFailure(Request request, ResponseBody errorMessage) {
3232
}
3333

3434
@Override
35-
public void onResponse(Request request, ResponseBody response) {
35+
public void onResponse(ResponseBody response) {
3636
System.out.println("Response : "+response.toString());
3737

3838
}
3939
});
4040
}
4141

4242

43-
// @Test
44-
// void testTaxonomyIn() {
45-
// String[] value = {"term_uid1", "term_uid2"}; // ["term_uid1" , "term_uid2" ]
46-
//
47-
// Request request = taxonomy.inOperator("taxonomies.taxonomy_uid", value).find().request();
48-
// taxonomy.find(new Callback<ResponseBody>() {
49-
// @Override
50-
// public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
51-
// call.request().url();
52-
// }
53-
//
54-
// @Override
55-
// public void onFailure(Call<ResponseBody> call, Throwable t) {
56-
//
57-
// }
58-
// });
59-
// Assertions.assertEquals(3, request.headers().size());
60-
// Assertions.assertEquals("GET", request.method().toString(), "test method are being passed though payload");
61-
// Assertions.assertEquals("cdn.contentstack.io", request.url().host());
62-
// Assertions.assertNull(request.url().encodedFragment(), "We do not expect any fragment");
63-
// Assertions.assertEquals("/taxonomies/entries", request.url().encodedPath());
64-
// Assertions.assertEquals(2, Arrays.stream(request.url().encodedPathSegments().stream().toArray()).count());
65-
// Assertions.assertEquals("", request.url().query());
66-
// Assertions.assertEquals("", request.url().encodedQuery());
67-
// Assertions.assertEquals("", request.url().queryParameterNames());
68-
// Assertions.assertEquals("", request.url(), "test url are being passed though payload");
69-
// Assertions.assertEquals("", request.body().contentType().toString(), "test content type are being passed though payload");
70-
// }
43+
@Test
44+
void testUnitInOperator() {
45+
HashMap<String, Object> query = new HashMap<>();
46+
query.put("taxonomies.taxonomy_uid", new HashMap<String, Object>() {{
47+
put("$in", new String[]{"term_uid1", "term_uid2"});
48+
}});
49+
50+
taxonomy.query(query);
51+
Request req = taxonomy.makeRequest().request();
52+
Assertions.assertEquals(3, req.headers().size());
53+
Assertions.assertEquals("GET", req.method().toString(), "test method are being passed though payload");
54+
Assertions.assertEquals("cdn.contentstack.io", req.url().host());
55+
Assertions.assertNull(req.url().encodedFragment(), "We do not expect any fragment");
56+
Assertions.assertEquals("/v3/taxonomies/entries", req.url().encodedPath());
57+
Assertions.assertEquals(3, Arrays.stream(req.url().encodedPathSegments().stream().toArray()).count());
58+
Assertions.assertNotNull( req.url().query());
59+
Assertions.assertNotNull(req.url().encodedQuery());
60+
Assertions.assertEquals("[query]", req.url().queryParameterNames().toString());
61+
}
62+
63+
@Test
64+
void testUnitOrOperator() {
65+
HashMap<String, Object> query = new HashMap<>();
66+
query.put("taxonomies.taxonomy_uid", new HashMap<String, Object>() {{
67+
put("$in", new String[]{"term_uid1", "term_uid2"});
68+
}});
69+
70+
taxonomy.query(query);
71+
Request req = taxonomy.makeRequest().request();
72+
Assertions.assertEquals(3, req.headers().size());
73+
Assertions.assertEquals("GET", req.method().toString(), "test method are being passed though payload");
74+
Assertions.assertEquals("cdn.contentstack.io", req.url().host());
75+
Assertions.assertNull(req.url().encodedFragment(), "We do not expect any fragment");
76+
Assertions.assertEquals("/v3/taxonomies/entries", req.url().encodedPath());
77+
Assertions.assertEquals(3, Arrays.stream(req.url().encodedPathSegments().stream().toArray()).count());
78+
Assertions.assertNotNull( req.url().query());
79+
Assertions.assertNotNull(req.url().encodedQuery());
80+
Assertions.assertEquals("[query]", req.url().queryParameterNames().toString());
81+
}
82+
83+
84+
85+
86+
7187

7288

7389
}

0 commit comments

Comments
 (0)