@@ -55,6 +55,8 @@ public void testRecordDataKeyValidation() throws Exception {
55
55
assertFalse (RecordSerializer .isValidKey ("" ));
56
56
assertFalse (RecordSerializer .isValidKey ("_id" ));
57
57
assertFalse (RecordSerializer .isValidKey ("_type" ));
58
+ assertFalse (RecordSerializer .isValidKey ("_recordType" ));
59
+ assertFalse (RecordSerializer .isValidKey ("_recordID" ));
58
60
assertFalse (RecordSerializer .isValidKey ("_created_at" ));
59
61
assertFalse (RecordSerializer .isValidKey ("_updated_at" ));
60
62
assertFalse (RecordSerializer .isValidKey ("_ownerID" ));
@@ -155,6 +157,8 @@ public void testRecordSerializationNormalFlow() throws Exception {
155
157
156
158
assertNotNull (jsonObject );
157
159
assertEquals ("Note/" + aNote .getId (), jsonObject .getString ("_id" ));
160
+ assertEquals ("Note" , jsonObject .getString ("_recordType" ));
161
+ assertEquals (aNote .getId (), jsonObject .getString ("_recordID" ));
158
162
assertEquals ("user123" , jsonObject .getString ("_ownerID" ));
159
163
assertEquals ("user123" , jsonObject .getString ("_created_by" ));
160
164
assertEquals ("user456" , jsonObject .getString ("_updated_by" ));
@@ -170,8 +174,10 @@ public void testRecordSerializationNormalFlow() throws Exception {
170
174
assertEquals ("2016-06-15T07:55:34.342Z" , publishDateObject .getString ("$date" ));
171
175
172
176
JSONObject commentObject = jsonObject .getJSONObject ("comment" );
173
- assertEquals ("Comment/" + aComment .getId (), commentObject .getString ("$id" ));
174
177
assertEquals ("ref" , commentObject .getString ("$type" ));
178
+ assertEquals ("Comment/" + aComment .getId (), commentObject .getString ("$id" ));
179
+ assertEquals ("Comment" , commentObject .getString ("$recordType" ));
180
+ assertEquals (aComment .getId (), commentObject .getString ("$recordID" ));
175
181
176
182
JSONObject locationObject = jsonObject .getJSONObject ("loc" );
177
183
assertEquals ("geo" , locationObject .getString ("$type" ));
@@ -204,6 +210,8 @@ public void testRecordSerializationNormalFlow() throws Exception {
204
210
205
211
JSONObject commentTransient = transientObject .getJSONObject ("comment" );
206
212
assertEquals ("Comment/" + aComment .getId (), commentTransient .getString ("_id" ));
213
+ assertEquals ("Comment" , commentTransient .getString ("_recordType" ));
214
+ assertEquals (aComment .getId (), commentTransient .getString ("_recordID" ));
207
215
assertEquals ("google" , commentTransient .getString ("okay" ));
208
216
assertEquals ("siri" , commentTransient .getString ("hey" ));
209
217
}
@@ -274,13 +282,15 @@ public void testRecordDeserializationNormalFlow() throws Exception {
274
282
// prepare reference record data
275
283
String referenceRecordId = "7a7873dc-e14b-4b8f-9c51-948da68e924e" ;
276
284
JSONObject referenceRecordData = new JSONObject ();
277
- referenceRecordData .put ("_id" , "Comment/" + referenceRecordId );
285
+ referenceRecordData .put ("_recordType" , "Comment" );
286
+ referenceRecordData .put ("_recordID" , referenceRecordId );
278
287
referenceRecordData .put ("okay" , "google" );
279
288
referenceRecordData .put ("hey" , "siri" );
280
289
281
290
// prepare record data
282
291
JSONObject jsonObject = new JSONObject ();
283
- jsonObject .put ("_id" , "Note/48092492-0791-4120-B314-022202AD3971" );
292
+ jsonObject .put ("_recordType" , "Note" );
293
+ jsonObject .put ("_recordID" , "48092492-0791-4120-B314-022202AD3971" );
284
294
jsonObject .put ("_created_at" , "2016-06-15T07:55:32.342Z" );
285
295
jsonObject .put ("_created_by" , "5a497b0b-cf93-4720-bea4-14637478cfc0" );
286
296
jsonObject .put ("_ownerID" , "5a497b0b-cf93-4720-bea4-14637478cfc1" );
@@ -312,7 +322,8 @@ public void testRecordDeserializationNormalFlow() throws Exception {
312
322
313
323
JSONObject commentReferenceObject = new JSONObject ();
314
324
commentReferenceObject .put ("$type" , "ref" );
315
- commentReferenceObject .put ("$id" , "Comment/" + referenceRecordId );
325
+ commentReferenceObject .put ("$recordType" , "Comment" );
326
+ commentReferenceObject .put ("$recordID" , referenceRecordId );
316
327
jsonObject .put ("comment" , commentReferenceObject );
317
328
318
329
JSONObject unknownValueObject = new JSONObject ();
@@ -390,10 +401,49 @@ public void testRecordDeserializationNormalFlow() throws Exception {
390
401
assertEquals ("siri" , commentTransient .get ("hey" ));
391
402
}
392
403
393
- @ Test (expected = InvalidParameterException .class )
404
+ @ Test
405
+ public void testRecordDeserializationDeprecatedFlow () throws Exception {
406
+ JSONObject jsonObject = new JSONObject ();
407
+ jsonObject .put ("_id" , "Note/48092492-0791-4120-B314-022202AD3971" );
408
+ jsonObject .put ("_created_at" , "2016-06-15T07:55:32.342Z" );
409
+ jsonObject .put ("_created_by" , "5a497b0b-cf93-4720-bea4-14637478cfc0" );
410
+ jsonObject .put ("_ownerID" , "5a497b0b-cf93-4720-bea4-14637478cfc1" );
411
+ jsonObject .put ("_updated_at" , "2016-06-15T07:55:33.342Z" );
412
+ jsonObject .put ("_updated_by" , "5a497b0b-cf93-4720-bea4-14637478cfc2" );
413
+ jsonObject .put ("_access" , new JSONArray ("[{\" public\" :true,\" level\" :\" write\" }]" ));
414
+
415
+ jsonObject .put ("hello" , "world" );
416
+ jsonObject .put ("foobar" , 3 );
417
+ jsonObject .put ("abc" , 12.345 );
418
+
419
+ Record record = RecordSerializer .deserialize (jsonObject );
420
+
421
+ assertEquals ("Note" , record .getType ());
422
+ assertEquals ("48092492-0791-4120-B314-022202AD3971" , record .getId ());
423
+ assertEquals ("5a497b0b-cf93-4720-bea4-14637478cfc0" , record .getCreatorId ());
424
+ assertEquals ("5a497b0b-cf93-4720-bea4-14637478cfc1" , record .getOwnerId ());
425
+ assertEquals ("5a497b0b-cf93-4720-bea4-14637478cfc2" , record .getUpdaterId ());
426
+
427
+ assertEquals (
428
+ new DateTime (2016 , 6 , 15 , 7 , 55 , 32 , 342 , DateTimeZone .UTC ).toDate (),
429
+ record .getCreatedAt ()
430
+ );
431
+ assertEquals (
432
+ new DateTime (2016 , 6 , 15 , 7 , 55 , 33 , 342 , DateTimeZone .UTC ).toDate (),
433
+ record .getUpdatedAt ()
434
+ );
435
+
436
+ assertEquals ("world" , record .get ("hello" ));
437
+ assertEquals (3 , record .get ("foobar" ));
438
+ assertEquals (12.345 , record .get ("abc" ));
439
+
440
+ assertTrue (record .isPublicWritable ());
441
+ }
442
+
443
+ @ Test (expected = JSONException .class )
394
444
public void testRecordDeserializationNotAllowNoId () throws Exception {
395
445
JSONObject jsonObject = new JSONObject ();
396
- jsonObject .put ("_id " , "Note" );
446
+ jsonObject .put ("_recordType " , "Note" );
397
447
jsonObject .put ("hello" , "world" );
398
448
jsonObject .put ("foobar" , 3 );
399
449
jsonObject .put ("abc" , 12.345 );
@@ -405,7 +455,8 @@ public void testRecordDeserializationNotAllowNoId() throws Exception {
405
455
/* Regression: https://github.com/SkygearIO/skygear-SDK-Android/issues/23 */
406
456
public void testRecordDeserializeJsonObject () throws Exception {
407
457
JSONObject jsonObject = new JSONObject ();
408
- jsonObject .put ("_id" , "Note/48092492-0791-4120-B314-022202AD3971" );
458
+ jsonObject .put ("_recordType" , "Note" );
459
+ jsonObject .put ("_recordID" , "48092492-0791-4120-B314-022202AD3971" );
409
460
jsonObject .put ("_created_at" , "2016-06-15T07:55:32.342Z" );
410
461
jsonObject .put ("_created_by" , "5a497b0b-cf93-4720-bea4-14637478cfc0" );
411
462
jsonObject .put ("_ownerID" , "5a497b0b-cf93-4720-bea4-14637478cfc1" );
@@ -423,7 +474,8 @@ public void testRecordDeserializeJsonObject() throws Exception {
423
474
/* Regression: https://github.com/SkygearIO/skygear-SDK-Android/issues/23 */
424
475
public void testRecordDeserializeArray () throws Exception {
425
476
JSONObject jsonObject = new JSONObject ();
426
- jsonObject .put ("_id" , "Note/48092492-0791-4120-B314-022202AD3971" );
477
+ jsonObject .put ("_recordType" , "Note" );
478
+ jsonObject .put ("_recordID" , "48092492-0791-4120-B314-022202AD3971" );
427
479
jsonObject .put ("_created_at" , "2016-06-15T07:55:32.342Z" );
428
480
jsonObject .put ("_created_by" , "5a497b0b-cf93-4720-bea4-14637478cfc0" );
429
481
jsonObject .put ("_ownerID" , "5a497b0b-cf93-4720-bea4-14637478cfc1" );
@@ -443,7 +495,8 @@ public void testRecordDeserializeArray() throws Exception {
443
495
/* Regression: https://github.com/SkygearIO/skygear-SDK-Android/issues/44 */
444
496
public void testRecordDeserializeWithNullAccess () throws Exception {
445
497
JSONObject jsonObject = new JSONObject ();
446
- jsonObject .put ("_id" , "Note/48092492-0791-4120-B314-022202AD3971" );
498
+ jsonObject .put ("_recordType" , "Note" );
499
+ jsonObject .put ("_recordID" , "48092492-0791-4120-B314-022202AD3971" );
447
500
jsonObject .put ("_created_at" , "2016-06-15T07:55:32.342Z" );
448
501
jsonObject .put ("_created_by" , "5a497b0b-cf93-4720-bea4-14637478cfc0" );
449
502
jsonObject .put ("_ownerID" , "5a497b0b-cf93-4720-bea4-14637478cfc1" );
@@ -460,7 +513,8 @@ public void testRecordDeserializeWithNullAccess() throws Exception {
460
513
/* Regression: https://github.com/SkygearIO/skygear-SDK-Android/issues/45 */
461
514
public void testRecordDeserializeNotRequiredMetaData () throws Exception {
462
515
JSONObject jsonObject = new JSONObject ();
463
- jsonObject .put ("_id" , "Note/48092492-0791-4120-B314-022202AD3971" );
516
+ jsonObject .put ("_recordType" , "Note" );
517
+ jsonObject .put ("_recordID" , "48092492-0791-4120-B314-022202AD3971" );
464
518
jsonObject .put ("foo" , "bar" );
465
519
466
520
RecordSerializer .deserialize (jsonObject );
@@ -470,7 +524,8 @@ public void testRecordDeserializeNotRequiredMetaData() throws Exception {
470
524
/* Regression: https://github.com/SkygearIO/skygear-SDK-Android/issues/61 */
471
525
public void testRecordDeserializeNull () throws Exception {
472
526
JSONObject jsonObject = new JSONObject ();
473
- jsonObject .put ("_id" , "Note/48092492-0791-4120-B314-022202AD3971" );
527
+ jsonObject .put ("_recordType" , "Note" );
528
+ jsonObject .put ("_recordID" , "48092492-0791-4120-B314-022202AD3971" );
474
529
jsonObject .put ("null-value-key" , JSONObject .NULL );
475
530
476
531
Record aNote = RecordSerializer .deserialize (jsonObject );
@@ -483,7 +538,7 @@ public void testRecordSerializeAndDeserialize() throws Exception {
483
538
JSONObject jsonObject = RecordSerializer .serialize (note );
484
539
Record record = RecordSerializer .deserialize (jsonObject );
485
540
486
- assertEquals (note .id , record .id );
541
+ assertEquals (note .getId () , record .getId () );
487
542
assertEquals (note .ownerId , record .ownerId );
488
543
assertEquals (note .createdAt , record .createdAt );
489
544
assertEquals (note .creatorId , record .creatorId );
0 commit comments