Skip to content

Commit fc08d6a

Browse files
committed
Add tests for Asset and ContentType as POJOs and enhance type safety checks in Entry
1 parent 482f607 commit fc08d6a

File tree

3 files changed

+113
-3
lines changed

3 files changed

+113
-3
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,42 @@ void testAssetIncludeOwner() {
189189
Assertions.assertTrue(asset.urlQueries.has("include_metadata"));
190190
}
191191

192+
@Test
193+
void testAssetAsPOJO() {
194+
Asset asset = stack.asset(assetUid);
195+
asset.fetch(new FetchResultCallback() {
196+
@Override
197+
public void onCompletion(ResponseType responseType, Error error) {
198+
if (error == null) {
199+
Assertions.assertNotNull(asset.getAssetUid());
200+
Assertions.assertNotNull(asset.getFileType());
201+
Assertions.assertNotNull(asset.getFileSize());
202+
Assertions.assertNotNull(asset.getFileName());
203+
Assertions.assertNotNull(asset.getUrl());
204+
Assertions.assertNotNull(asset.getTags());
205+
Assertions.assertNotNull(asset.toJSON());
206+
}
207+
}
208+
});
209+
}
210+
211+
@Test
212+
void testAssetTypeSafety() {
213+
Asset asset = stack.asset(assetUid);
214+
asset.fetch(new FetchResultCallback() {
215+
@Override
216+
public void onCompletion(ResponseType responseType, Error error) {
217+
if (error == null) {
218+
Assertions.assertNotNull(asset.getAssetUid());
219+
Assertions.assertNotNull(asset.getFileType());
220+
Assertions.assertNotNull(asset.getFileSize());
221+
Assertions.assertNotNull(asset.getFileName());
222+
Assertions.assertNotNull(asset.getUrl());
223+
Assertions.assertNotNull(asset.getTags());
224+
225+
}
226+
}
227+
});
228+
}
229+
192230
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,35 @@ public void onCompletion(ContentTypesModel model, Error error) {
9797
});
9898
}
9999

100+
@Test
101+
void testContentTypeAsPOJO() {
102+
ContentType contentType = stack.contentType("product");
103+
Assertions.assertNotNull(contentType.contentTypeUid);
104+
Assertions.assertNotNull(contentType);
105+
106+
Entry entry = contentType.entry("test-entry-uid");
107+
Query query = contentType.query();
108+
Assertions.assertNotNull(entry);
109+
Assertions.assertNotNull(query);
110+
Assertions.assertEquals("product", entry.getContentType());
111+
Assertions.assertEquals("product", query.getContentType());
112+
}
113+
114+
@Test
115+
void testContentTypePOJODataAccess() throws IllegalAccessException {
116+
ContentType contentType = stack.contentType("product");
117+
JSONObject paramObj = new JSONObject();
118+
paramObj.put("include_schema", "true");
119+
contentType.fetch(paramObj, new ContentTypesCallback() {
120+
@Override
121+
public void onCompletion(ContentTypesModel model, Error error) {
122+
if (error == null) {
123+
Assertions.assertNotNull(contentType.contentTypeUid);
124+
Assertions.assertNotNull(contentType);
125+
}
126+
}
127+
});
128+
}
129+
100130

101131
}

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

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
import java.util.List;
77
import java.util.logging.Logger;
88
import org.junit.jupiter.api.*;
9-
10-
import static org.junit.Assert.assertNull;
11-
import static org.junit.jupiter.api.Assertions.assertTrue;
9+
import static org.junit.jupiter.api.Assertions.*;
1210

1311
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1412
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@@ -551,4 +549,48 @@ public void onCompletion(ResponseType responseType, Error error) {
551549
logger.info("passed...");
552550
}
553551

552+
@Test
553+
@Order(60)
554+
void testEntryAsPOJO() {
555+
Entry entry1 = stack.contentType("product").entry(entryUid);
556+
557+
entry1.fetch(new EntryResultCallBack() {
558+
@Override
559+
public void onCompletion(ResponseType responseType, Error error) {
560+
if (error == null) {
561+
System.out.println("entry fetched successfully");
562+
}
563+
}
564+
});
565+
566+
Assertions.assertNotNull(entry1.getTitle());
567+
Assertions.assertNotNull(entry1.getUid());
568+
Assertions.assertNotNull(entry1.getContentType());
569+
Assertions.assertNotNull(entry1.getLocale());
570+
}
571+
572+
@Test
573+
@Order(61)
574+
void testEntryTypeSafety() {
575+
Entry entry = stack.contentType(CONTENT_TYPE).entry(entryUid);
576+
entry.fetch(new EntryResultCallBack() {
577+
@Override
578+
public void onCompletion(ResponseType responseType, Error error) {
579+
if (error == null) {
580+
Assertions.assertEquals(entryUid, entry.getUid());
581+
}
582+
}
583+
});
584+
585+
String title = entry.getTitle();
586+
String uid = entry.getUid();
587+
String contentType = entry.getContentType();
588+
String locale = entry.getLocale();
589+
590+
Assertions.assertTrue(title instanceof String);
591+
Assertions.assertTrue(uid instanceof String);
592+
Assertions.assertTrue(contentType instanceof String);
593+
Assertions.assertTrue(locale instanceof String);
594+
595+
}
554596
}

0 commit comments

Comments
 (0)