|
10 | 10 |
|
11 | 11 | import java.io.IOException;
|
12 | 12 | import java.util.HashMap;
|
| 13 | +import java.util.Map; |
13 | 14 | import java.util.logging.Level;
|
14 | 15 | import java.util.logging.Logger;
|
15 | 16 |
|
@@ -223,4 +224,45 @@ void testLivePreviewDisabled() throws IllegalAccessException, IOException {
|
223 | 224 | "Expected exception message does not match");
|
224 | 225 | }
|
225 | 226 |
|
| 227 | + @Test |
| 228 | + void testTimelinePreview() throws IllegalAccessException, IOException { |
| 229 | + Config config = new Config() |
| 230 | + .enableLivePreview(true) |
| 231 | + .setLivePreviewHost("rest-preview.contentstack.com") |
| 232 | + .setPreviewToken("preview_token"); |
| 233 | + |
| 234 | + Stack stack = Contentstack.stack("stackApiKey", "deliveryToken", "env1", config); |
| 235 | + |
| 236 | + HashMap<String, String> hashMap = new HashMap<>(); |
| 237 | + hashMap.put("live_preview", "hash167673"); |
| 238 | + hashMap.put("content_type_uid", "page"); |
| 239 | + hashMap.put("entry_uid", "entryUid"); |
| 240 | + hashMap.put("release_id", "12345"); |
| 241 | + hashMap.put("preview_timestamp", "2025-09-25 17:45:30.005"); |
| 242 | + |
| 243 | + |
| 244 | + stack.livePreviewQuery(hashMap); |
| 245 | + Entry entry = stack.contentType("page").entry("entry_uid"); |
| 246 | + entry.fetch(null); |
| 247 | + Assertions.assertNotNull(entry); |
| 248 | + } |
| 249 | + |
| 250 | + @Test |
| 251 | + void testLivePreviewQueryWithoutReleaseId() throws Exception { |
| 252 | + Config config = new Config().enableLivePreview(true) |
| 253 | + .setLivePreviewHost("rest-preview.contentstack.com") |
| 254 | + .setPreviewToken("previewToken"); |
| 255 | + Stack stack = Contentstack.stack("api_key", "access_token", "env", config); |
| 256 | + |
| 257 | + Map<String, String> queryParams = new HashMap<>(); |
| 258 | + queryParams.put("content_type_uid", "blog"); |
| 259 | + queryParams.put("entry_uid", "entry_123"); |
| 260 | + queryParams.put("preview_timestamp", "1710800000"); |
| 261 | + |
| 262 | + stack.livePreviewQuery(queryParams); |
| 263 | + |
| 264 | + Assertions.assertNull(config.releaseId); |
| 265 | + Assertions.assertEquals("1710800000", config.previewTimestamp); |
| 266 | + } |
| 267 | + |
226 | 268 | }
|
0 commit comments