Skip to content

Commit

Permalink
add more unit test for the default value behavior (#474)
Browse files Browse the repository at this point in the history
Co-authored-by: Zihan Li <[email protected]>
  • Loading branch information
ZihanLi58 and Zihan Li authored Nov 12, 2024
1 parent 017f037 commit 14ff8c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.data.template.StringArray;
import com.linkedin.metadata.aspect.AuditedAspect;
import com.linkedin.metadata.dao.BaseLocalDAO;
import com.linkedin.metadata.dao.EbeanLocalAccess;
import com.linkedin.metadata.dao.EbeanMetadataAspect;
import com.linkedin.metadata.dao.ListResult;
Expand All @@ -22,8 +23,10 @@
import com.linkedin.testing.AnnotatedRelationshipFoo;
import com.linkedin.testing.AnnotatedRelationshipFooArray;
import com.linkedin.testing.AspectFoo;
import com.linkedin.testing.AspectWithDefaultValue;
import com.linkedin.testing.CommonAspect;
import com.linkedin.testing.CommonAspectArray;
import com.linkedin.testing.MapValueRecord;
import com.linkedin.testing.urn.BurgerUrn;
import com.linkedin.testing.urn.FooUrn;
import io.ebean.Ebean;
Expand Down Expand Up @@ -508,6 +511,25 @@ public void testToAndFromJson() throws NoSuchMethodException, InvocationTargetEx
assertNotNull(RecordUtils.toRecordTemplate(AspectFoo.class, (String) extractAspectJsonString.invoke(EBeanDAOUtils.class, toJson)));
}

@Test
public void testToAndFromJsonWithDefaultValue() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
AuditedAspect auditedAspect = new AuditedAspect();
AspectWithDefaultValue defaultValueAspect = new AspectWithDefaultValue().setNestedValueWithDefault(new MapValueRecord());
BaseLocalDAO.validateAgainstSchemaAndFillinDefault(defaultValueAspect);
String actual = RecordUtils.toJsonString(defaultValueAspect);

auditedAspect.setLastmodifiedby("0");
auditedAspect.setLastmodifiedon("1");
auditedAspect.setAspect(RecordUtils.toJsonString(defaultValueAspect));
String toJson = EbeanLocalAccess.toJsonString(auditedAspect);

Method extractAspectJsonString = EBeanDAOUtils.class.getDeclaredMethod("extractAspectJsonString", String.class);
extractAspectJsonString.setAccessible(true);
assertEquals("{\"lastmodifiedon\":\"1\",\"aspect\":{\"nestedValueWithDefault\":{\"mapValueWithDefaultmap\":{}},"
+ "\"valueWithDefault\":\"\"},\"lastmodifiedby\":\"0\"}", toJson);
assertNotNull(RecordUtils.toRecordTemplate(AspectFoo.class, (String) extractAspectJsonString.invoke(EBeanDAOUtils.class, toJson)));
}

@Test
public void testGetFromJdbc() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ record AspectWithDefaultValue {
*/
valueWithDefault: string = ""
nestedValueWithDefault: record MapValueRecord {mapValueWithDefaultmap: map[string, string] = { }}
optionalValueWithDefualt: optional string = ""
}

0 comments on commit 14ff8c8

Please sign in to comment.