Commit f09a14be by Harish Butani

fix issues with ClassType output and convert

parent 37ec473d
......@@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap;
import org.apache.metadata.IStruct;
import org.apache.metadata.ITypedReferenceableInstance;
import org.apache.metadata.ITypedStruct;
import org.apache.metadata.MetadataException;
import org.apache.metadata.types.FieldMapping;
import java.math.BigDecimal;
......@@ -73,4 +74,18 @@ public class ReferenceableInstance extends StructInstance implements ITypedRefer
public IStruct getTrait(String typeName) {
return traits.get(typeName);
}
@Override
public String toString() {
try {
StringBuilder buf = new StringBuilder();
String prefix = "";
fieldMapping.output(this, buf, prefix);
return buf.toString();
} catch(MetadataException me) {
throw new RuntimeException(me);
}
}
}
......@@ -129,18 +129,7 @@ public class StructInstance implements ITypedStruct {
StringBuilder buf = new StringBuilder();
String prefix = "";
TypeUtils.outputVal("{", buf, prefix);
TypeUtils.outputVal("\n", buf, "");
String fieldPrefix = prefix + "\t";
for(Map.Entry<String,AttributeInfo> e : fieldMapping.fields.entrySet()) {
String attrName = e.getKey();
AttributeInfo i = e.getValue();
Object aVal = get(attrName);
TypeUtils.outputVal(attrName + " : ", buf, fieldPrefix);
i.dataType().output(aVal, buf, "");
TypeUtils.outputVal("\n", buf, "");
}
TypeUtils.outputVal("\n}\n", buf, "");
fieldMapping.output(this, buf, prefix);
return buf.toString();
} catch(MetadataException me) {
......
......@@ -63,6 +63,13 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
}
}
protected Id getId(Object val) throws MetadataException {
if ( val instanceof Referenceable ) {
return ((Referenceable)val).getId();
}
throw new MetadataException(String.format("Cannot get id from class %s", val.getClass()));
}
@Override
public ITypedReferenceableInstance convert(Object val, Multiplicity m) throws MetadataException {
......@@ -72,6 +79,13 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
Referenceable r = null;
if ( s.typeName != getName() ) {
/*
* If val is a subType instance; invoke convert on it.
*/
ClassType valType = typeSystem.getDataType(superTypeClass, s.typeName);
if ( valType.superTypePaths.containsKey(name) ) {
return valType.convert(s, m);
}
throw new ValueConversionException(this, val);
}
......@@ -86,6 +100,12 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
String attrKey = e.getKey();
AttributeInfo i = e.getValue();
Object aVal = s.get(attrKey);
if ( aVal != null && i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS ) {
if ( !i.isComposite ) {
aVal = ((IReferenceableInstance)aVal).getId();
}
}
try {
tr.set(attrKey, aVal);
} catch(ValueConversionException ve) {
......@@ -149,32 +169,7 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
@Override
public void output(IReferenceableInstance s, Appendable buf, String prefix) throws MetadataException {
TypeUtils.outputVal("{", buf, prefix);
if ( s == null ) {
TypeUtils.outputVal("<null>\n", buf, "");
return;
}
TypeUtils.outputVal("\n", buf, "");
String fieldPrefix = prefix + "\t";
TypeUtils.outputVal("id : ", buf, fieldPrefix);
TypeUtils.outputVal(s.getId().toString(), buf, "");
TypeUtils.outputVal("\n", buf, "");
for(AttributeInfo i : fieldMapping.fields.values()) {
Object aVal = s.get(i.name);
TypeUtils.outputVal(i.name + " : ", buf, fieldPrefix);
i.dataType().output(aVal, buf, "");
TypeUtils.outputVal("\n", buf, "");
}
for(String sT : s.getTraits() ) {
TraitType tt = typeSystem.getDataType(TraitType.class, sT);
TypeUtils.outputVal(sT + " : ", buf, fieldPrefix);
tt.output(s.getTrait(sT), buf, fieldPrefix);
}
TypeUtils.outputVal("}", buf, fieldPrefix);
fieldMapping.output(s, buf, prefix);
}
}
\ No newline at end of file
......@@ -19,8 +19,7 @@ package org.apache.metadata.types;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.apache.metadata.MetadataException;
import org.apache.metadata.MetadataService;
import org.apache.metadata.*;
import org.apache.metadata.storage.Id;
import org.apache.metadata.storage.ReferenceableInstance;
import org.apache.metadata.storage.StructInstance;
......@@ -178,11 +177,75 @@ public class FieldMapping {
return s.arrays[pos];
} else if ( i.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP ) {
return s.maps[pos];
} else if ( i.dataType().getTypeCategory() == DataTypes.TypeCategory.STRUCT ) {
} else if ( i.dataType().getTypeCategory() == DataTypes.TypeCategory.STRUCT ||
i.dataType().getTypeCategory() == DataTypes.TypeCategory.TRAIT ) {
return s.structs[pos];
} else if ( i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS ) {
if ( s.ids[pos] != null ) {
return s.ids[pos];
} else {
return s.referenceables[pos];
}
} else {
throw new MetadataException(String.format("Unknown datatype %s", i.dataType()));
}
}
protected void outputFields(IStruct s, Appendable buf, String fieldPrefix) throws MetadataException {
for(Map.Entry<String,AttributeInfo> e : fields.entrySet()) {
String attrName = e.getKey();
AttributeInfo i = e.getValue();
Object aVal = s.get(attrName);
TypeUtils.outputVal(attrName + " : ", buf, fieldPrefix);
if ( aVal != null && aVal instanceof Id ) {
TypeUtils.outputVal(aVal.toString(), buf, "");
} else {
i.dataType().output(aVal, buf, fieldPrefix);
}
TypeUtils.outputVal("\n", buf, "");
}
}
public void output(IStruct s, Appendable buf, String prefix) throws MetadataException {
if ( s == null ) {
TypeUtils.outputVal("<null>\n", buf, "");
return;
}
TypeUtils.outputVal("{", buf, prefix);
TypeUtils.outputVal("\n", buf, "");
String fieldPrefix = prefix + "\t";
outputFields(s, buf, fieldPrefix);
TypeUtils.outputVal("}", buf, prefix);
}
public void output(IReferenceableInstance s, Appendable buf, String prefix) throws MetadataException {
if ( s == null ) {
TypeUtils.outputVal("<null>\n", buf, "");
return;
}
TypeUtils.outputVal("{", buf, prefix);
TypeUtils.outputVal("\n", buf, "");
String fieldPrefix = prefix + "\t";
TypeUtils.outputVal("id : ", buf, fieldPrefix);
TypeUtils.outputVal(s.getId().toString(), buf, "");
TypeUtils.outputVal("\n", buf, "");
outputFields(s, buf, fieldPrefix);
TypeSystem ts = MetadataService.getCurrentTypeSystem();
for(String sT : s.getTraits() ) {
TraitType tt = ts.getDataType(TraitType.class, sT);
TypeUtils.outputVal(sT + " : ", buf, fieldPrefix);
tt.output(s.getTrait(sT), buf, fieldPrefix);
}
TypeUtils.outputVal("}", buf, prefix);
}
}
......@@ -101,20 +101,7 @@ public class TypedStructHandler {
}
public void output(IStruct s, Appendable buf, String prefix) throws MetadataException {
TypeUtils.outputVal("{", buf, prefix);
if ( s == null ) {
TypeUtils.outputVal("<null>\n", buf, "");
return;
}
TypeUtils.outputVal("\n", buf, "");
String fieldPrefix = prefix + "\t";
for(AttributeInfo i : fieldMapping.fields.values()) {
Object aVal = s.get(i.name);
TypeUtils.outputVal(i.name + " : ", buf, fieldPrefix);
i.dataType().output(aVal, buf, "");
TypeUtils.outputVal("\n", buf, "");
}
TypeUtils.outputVal("\n}\n", buf, "");
fieldMapping.output(s, buf, prefix);
}
}
......@@ -75,8 +75,8 @@ public abstract class BaseTest {
Struct s = new Struct(structType.getName());
s.set("a", 1);
s.set("b", true);
s.set("c", (byte)1);
s.set("d", (short)2);
s.set("c", (byte) 1);
s.set("d", (short) 2);
s.set("e", 1);
s.set("f", 1);
s.set("g", 1L);
......@@ -86,10 +86,10 @@ public abstract class BaseTest {
s.set("k", new BigDecimal(1));
s.set("l", new Date(1418265358440L));
s.set("m", Lists.<Integer>asList(Integer.valueOf(1), new Integer[]{Integer.valueOf(1)}));
s.set("n", Lists.<BigDecimal>asList(BigDecimal.valueOf(1.1), new BigDecimal[] {BigDecimal.valueOf(1.1)}));
s.set("n", Lists.<BigDecimal>asList(BigDecimal.valueOf(1.1), new BigDecimal[]{BigDecimal.valueOf(1.1)}));
Map<String, Double> hm = Maps.<String, Double>newHashMap();
hm.put("a", 1.0);
hm.put("b",2.0);
hm.put("b", 2.0);
s.set("o", hm);
return s;
}
......@@ -102,7 +102,7 @@ public abstract class BaseTest {
}
public static AttributeDefinition createOptionalAttrDef(String name,
String dataType
String dataType
) {
return new AttributeDefinition(name, dataType, Multiplicity.OPTIONAL, false, null);
}
......@@ -116,7 +116,7 @@ public abstract class BaseTest {
}
public static AttributeDefinition createRequiredAttrDef(String name,
String dataType
String dataType
) {
return new AttributeDefinition(name, dataType, Multiplicity.REQUIRED, false, null);
......@@ -127,12 +127,12 @@ public abstract class BaseTest {
}
protected HierarchicalTypeDefinition<TraitType> createTraitTypeDef(String name, ImmutableList<String> superTypes,
AttributeDefinition... attrDefs) {
AttributeDefinition... attrDefs) {
return new HierarchicalTypeDefinition(TraitType.class, name, superTypes, attrDefs);
}
protected HierarchicalTypeDefinition<ClassType> createClassTypeDef(String name, ImmutableList<String> superTypes,
AttributeDefinition... attrDefs) {
AttributeDefinition... attrDefs) {
return new HierarchicalTypeDefinition(ClassType.class, name, superTypes, attrDefs);
}
......
......@@ -16,9 +16,9 @@ public class ClassTest extends BaseTest {
/*
* Class Hierarchy is:
* Department(name, employee : Array[Person])
* Person(name, Department, Manager)
* Manager(subordinate : Array[Person]) extends Person
* Department(name : String, employees : Array[Person])
* Person(name : String, department : Department, manager : Manager)
* Manager(subordinates : Array[Person]) extends Person
*
* Persons can have SecurityClearance(level : Int) clearance.
*/
......@@ -27,8 +27,78 @@ public class ClassTest extends BaseTest {
TypeSystem ts = ms.getTypeSystem();
/*ClassTypeDefinition deptDef = createClassTypeDef("Department", ImmutableList.<String>of(),
HierarchicalTypeDefinition<ClassType> deptTypeDef = createClassTypeDef("Department", ImmutableList.<String>of(),
createRequiredAttrDef("name", DataTypes.STRING_TYPE),
createOptionalAttrDef("employee", ts.defineArrayType(DataTypes.INT_TYPE)))*/
new AttributeDefinition("employees",
String.format("array<%s>", "Person"), Multiplicity.COLLECTION, true, "department")
);
HierarchicalTypeDefinition<ClassType> personTypeDef = createClassTypeDef("Person", ImmutableList.<String>of(),
createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("department",
"Department", Multiplicity.REQUIRED, false, "employees"),
new AttributeDefinition("manager",
"Manager", Multiplicity.OPTIONAL, false, "subordinates")
);
HierarchicalTypeDefinition<ClassType> managerTypeDef = createClassTypeDef("Manager",
ImmutableList.<String>of("Person"),
new AttributeDefinition("subordinates",
String.format("array<%s>", "Person"), Multiplicity.COLLECTION, false, "manager")
);
HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef = createTraitTypeDef("SecurityClearance",
ImmutableList.<String>of(),
createRequiredAttrDef("level", DataTypes.INT_TYPE)
);
ts.defineTypes(ImmutableList.<StructTypeDefinition>of(),
ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(securityClearanceTypeDef),
ImmutableList.<HierarchicalTypeDefinition<ClassType>>of(deptTypeDef, personTypeDef, managerTypeDef));
Referenceable hrDept = new Referenceable("Department");
Referenceable john = new Referenceable("Person");
Referenceable jane = new Referenceable("Manager", "SecurityClearance");
hrDept.set("name", "hr");
john.set("name", "John");
john.set("department", hrDept);
jane.set("name", "Jane");
jane.set("department", hrDept);
john.set("manager", jane);
hrDept.set("employees", ImmutableList.<Referenceable>of(john, jane));
jane.set("subordinates", ImmutableList.<Referenceable>of(john));
jane.getTrait("SecurityClearance").set("level", 1);
ClassType deptType = ts.getDataType(ClassType.class, "Department");
ITypedReferenceableInstance hrDept2 = deptType.convert(hrDept, Multiplicity.REQUIRED);
Assert.assertEquals(hrDept2.toString(), "{\n" +
"\tid : (type: Department, id: <unassigned>)\n" +
"\tname : \thr\n" +
"\temployees : \t[{\n" +
"\tid : (type: Person, id: <unassigned>)\n" +
"\tname : \tJohn\n" +
"\tdepartment : (type: Department, id: <unassigned>)\n" +
"\tmanager : (type: Manager, id: <unassigned>)\n" +
"}, {\n" +
"\tid : (type: Manager, id: <unassigned>)\n" +
"\tsubordinates : \t[{\n" +
"\tid : (type: Person, id: <unassigned>)\n" +
"\tname : \tJohn\n" +
"\tdepartment : (type: Department, id: <unassigned>)\n" +
"\tmanager : (type: Manager, id: <unassigned>)\n" +
"}]\n" +
"\tname : \tJane\n" +
"\tdepartment : (type: Department, id: <unassigned>)\n" +
"\tmanager : <null>\n" +
"\n" +
"\tSecurityClearance : \t{\n" +
"\t\tlevel : \t\t1\n" +
"\t}}]\n" +
"}");
}
}
......@@ -41,23 +41,22 @@ public class StructTest extends BaseTest {
Struct s = createStruct(ms);
ITypedStruct ts = structType.convert(s, Multiplicity.REQUIRED);
Assert.assertEquals(ts.toString(), "{\n" +
"\ta : 1\n" +
"\tb : true\n" +
"\tc : 1\n" +
"\td : 2\n" +
"\te : 1\n" +
"\tf : 1\n" +
"\tg : 1\n" +
"\th : 1.0\n" +
"\ti : 1.0\n" +
"\tj : 1\n" +
"\tk : 1\n" +
"\tl : Wed Dec 10 18:35:58 PST 2014\n" +
"\tm : [1, 1]\n" +
"\tn : [1.1, 1.1]\n" +
"\to : {b=2.0, a=1.0}\n" +
"\n" +
"}\n");
"\ta : \t1\n" +
"\tb : \ttrue\n" +
"\tc : \t1\n" +
"\td : \t2\n" +
"\te : \t1\n" +
"\tf : \t1\n" +
"\tg : \t1\n" +
"\th : \t1.0\n" +
"\ti : \t1.0\n" +
"\tj : \t1\n" +
"\tk : \t1\n" +
"\tl : \tWed Dec 10 18:35:58 PST 2014\n" +
"\tm : \t[1, 1]\n" +
"\tn : \t[1.1, 1.1]\n" +
"\to : \t{b=2.0, a=1.0}\n" +
"}");
}
@Test
......@@ -69,16 +68,13 @@ public class StructTest extends BaseTest {
s2.set("s", s1);
ITypedStruct ts = recursiveStructType.convert(s2, Multiplicity.REQUIRED);
Assert.assertEquals(ts.toString(), "{\n" +
"\ta : 1\n" +
"\ts : {\n" +
"\ta : 1\n" +
"\ts : {<null>\n" +
"\n" +
"\n" +
"}\n" +
"\n" +
"\ta : \t1\n" +
"\ts : \t{\n" +
"\t\ta : \t\t1\n" +
"\t\ts : <null>\n" +
"\n" +
"}\n");
"\t}\n" +
"}");
}
}
......@@ -64,19 +64,18 @@ public class TraitTest extends BaseTest {
ITypedStruct ts = DType.convert(s1, Multiplicity.REQUIRED);
Assert.assertEquals(ts.toString(), "{\n" +
"\td : 1\n" +
"\tb : true\n" +
"\tc : 1\n" +
"\ta : 1\n" +
"\tA.B.D.b : true\n" +
"\tA.B.D.c : 2\n" +
"\tA.B.D.d : 2\n" +
"\tA.C.D.a : 3\n" +
"\tA.C.D.b : false\n" +
"\tA.C.D.c : 3\n" +
"\tA.C.D.d : 3\n" +
"\n" +
"}\n");
"\td : \t1\n" +
"\tb : \ttrue\n" +
"\tc : \t1\n" +
"\ta : \t1\n" +
"\tA.B.D.b : \ttrue\n" +
"\tA.B.D.c : \t2\n" +
"\tA.B.D.d : \t2\n" +
"\tA.C.D.a : \t3\n" +
"\tA.C.D.b : \tfalse\n" +
"\tA.C.D.c : \t3\n" +
"\tA.C.D.d : \t3\n" +
"}");
/*
* cast to B and set the 'b' attribute on A.
......@@ -86,19 +85,18 @@ public class TraitTest extends BaseTest {
s2.set("A.B.b", false);
Assert.assertEquals(ts.toString(), "{\n" +
"\td : 1\n" +
"\tb : true\n" +
"\tc : 1\n" +
"\ta : 1\n" +
"\tA.B.D.b : false\n" +
"\tA.B.D.c : 2\n" +
"\tA.B.D.d : 2\n" +
"\tA.C.D.a : 3\n" +
"\tA.C.D.b : false\n" +
"\tA.C.D.c : 3\n" +
"\tA.C.D.d : 3\n" +
"\n" +
"}\n");
"\td : \t1\n" +
"\tb : \ttrue\n" +
"\tc : \t1\n" +
"\ta : \t1\n" +
"\tA.B.D.b : \tfalse\n" +
"\tA.B.D.c : \t2\n" +
"\tA.B.D.d : \t2\n" +
"\tA.C.D.a : \t3\n" +
"\tA.C.D.b : \tfalse\n" +
"\tA.C.D.c : \t3\n" +
"\tA.C.D.d : \t3\n" +
"}");
/*
* cast again to A and set the 'b' attribute on A.
......@@ -107,19 +105,18 @@ public class TraitTest extends BaseTest {
IStruct s3 = BType.castAs(s2, "A");
s3.set("b", true);
Assert.assertEquals(ts.toString(), "{\n" +
"\td : 1\n" +
"\tb : true\n" +
"\tc : 1\n" +
"\ta : 1\n" +
"\tA.B.D.b : true\n" +
"\tA.B.D.c : 2\n" +
"\tA.B.D.d : 2\n" +
"\tA.C.D.a : 3\n" +
"\tA.C.D.b : false\n" +
"\tA.C.D.c : 3\n" +
"\tA.C.D.d : 3\n" +
"\n" +
"}\n");
"\td : \t1\n" +
"\tb : \ttrue\n" +
"\tc : \t1\n" +
"\ta : \t1\n" +
"\tA.B.D.b : \ttrue\n" +
"\tA.B.D.c : \t2\n" +
"\tA.B.D.d : \t2\n" +
"\tA.C.D.a : \t3\n" +
"\tA.C.D.b : \tfalse\n" +
"\tA.C.D.c : \t3\n" +
"\tA.C.D.d : \t3\n" +
"}");
}
@Test
......@@ -157,19 +154,18 @@ public class TraitTest extends BaseTest {
ITypedStruct ts = DType.convert(s1, Multiplicity.REQUIRED);
Assert.assertEquals(ts.toString(), "{\n" +
"\td : 1\n" +
"\tb : true\n" +
"\tc : 1\n" +
"\ta : 1\n" +
"\tA.B.D.b : true\n" +
"\tA.B.D.c : 2\n" +
"\tA.B.D.d : 2\n" +
"\tA.C.D.a : 3\n" +
"\tA.C.D.b : false\n" +
"\tA.C.D.c : 3\n" +
"\tA.C.D.d : 3\n" +
"\n" +
"}\n");
"\td : \t1\n" +
"\tb : \ttrue\n" +
"\tc : \t1\n" +
"\ta : \t1\n" +
"\tA.B.D.b : \ttrue\n" +
"\tA.B.D.c : \t2\n" +
"\tA.B.D.d : \t2\n" +
"\tA.C.D.a : \t3\n" +
"\tA.C.D.b : \tfalse\n" +
"\tA.C.D.c : \t3\n" +
"\tA.C.D.d : \t3\n" +
"}");
}
......
......@@ -48,7 +48,7 @@ class SerializationTest extends BaseTest {
val s: Struct = BaseTest.createStruct(ms)
val ts: ITypedStruct = structType.convert(s, Multiplicity.REQUIRED)
Assert.assertEquals(ts.toString, "{\n\ta : 1\n\tb : true\n\tc : 1\n\td : 2\n\te : 1\n\tf : 1\n\tg : 1\n\th : 1.0\n\ti : 1.0\n\tj : 1\n\tk : 1\n\tl : Wed Dec 10 18:35:58 PST 2014\n\tm : [1, 1]\n\tn : [1.1, 1.1]\n\to : {b=2.0, a=1.0}\n\n}\n")
Assert.assertEquals(ts.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \tWed Dec 10 18:35:58 PST 2014\n\tm : \t[1, 1]\n\tn : \t[1.1, 1.1]\n\to : \t{b=2.0, a=1.0}\n}")
implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer +
new BigDecimalSerializer + new BigIntegerSerializer
......@@ -59,7 +59,7 @@ class SerializationTest extends BaseTest {
// Typed Struct read back
val ts1 = read[StructInstance](ser)
Assert.assertEquals(ts1.toString, "{\n\ta : 1\n\tb : true\n\tc : 1\n\td : 2\n\te : 1\n\tf : 1\n\tg : 1\n\th : 1.0\n\ti : 1.0\n\tj : 1\n\tk : 1\n\tl : Thu Dec 11 00:00:00 PST 2014\n\tm : [1, 1]\n\tn : [1.100000000000000088817841970012523233890533447265625, 1.100000000000000088817841970012523233890533447265625]\n\to : {b=2.0, a=1.0}\n\n}\n")
Assert.assertEquals(ts1.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \tThu Dec 11 00:00:00 PST 2014\n\tm : \t[1, 1]\n\tn : \t[1.100000000000000088817841970012523233890533447265625, 1.100000000000000088817841970012523233890533447265625]\n\to : \t{b=2.0, a=1.0}\n}")
}
@Test def test2 {
......@@ -74,7 +74,7 @@ class SerializationTest extends BaseTest {
{"$typeName$":"t1","e":1,"n":[1.1,1.1],"h":1.0,"b":true,"k":1,"j":1,"d":2,"m":[1,1],"g":1,"a":1,"i":1.0,
"c":1,"l":"2014-12-03T19:38:55.053Z","f":1,"o":{"b":2.0,"a":1.0}}""")
// Typed Struct read from string
Assert.assertEquals(ts1.toString, "{\n\ta : 1\n\tb : true\n\tc : 1\n\td : 2\n\te : 1\n\tf : 1\n\tg : 1\n\th : 1.0\n\ti : 1.0\n\tj : 1\n\tk : 1\n\tl : Wed Dec 03 00:00:00 PST 2014\n\tm : [1, 1]\n\tn : [1.100000000000000088817841970012523233890533447265625, 1.100000000000000088817841970012523233890533447265625]\n\to : {b=2.0, a=1.0}\n\n}\n")
Assert.assertEquals(ts1.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \tWed Dec 03 00:00:00 PST 2014\n\tm : \t[1, 1]\n\tn : \t[1.100000000000000088817841970012523233890533447265625, 1.100000000000000088817841970012523233890533447265625]\n\to : \t{b=2.0, a=1.0}\n}")
}
@Test def testTrait {
......@@ -113,7 +113,7 @@ class SerializationTest extends BaseTest {
new BigDecimalSerializer + new BigIntegerSerializer
// Typed Struct :
Assert.assertEquals(ts.toString, "{\n\td : 1\n\tb : true\n\tc : 1\n\ta : 1\n\tA.B.D.b : true\n\tA.B.D.c : 2\n\tA.B.D.d : 2\n\tA.C.D.a : 3\n\tA.C.D.b : false\n\tA.C.D.c : 3\n\tA.C.D.d : 3\n\n}\n")
Assert.assertEquals(ts.toString, "{\n\td : \t1\n\tb : \ttrue\n\tc : \t1\n\ta : \t1\n\tA.B.D.b : \ttrue\n\tA.B.D.c : \t2\n\tA.B.D.d : \t2\n\tA.C.D.a : \t3\n\tA.C.D.b : \tfalse\n\tA.C.D.c : \t3\n\tA.C.D.d : \t3\n}")
// Json representation :
val ser = swrite(ts)
......@@ -124,6 +124,6 @@ class SerializationTest extends BaseTest {
{"$typeName$":"D","A.C.D.d":3,"A.B.D.c":2,"b":true,"A.C.D.c":3,"d":1,
"A.B.D.b":true,"a":1,"A.C.D.b":false,"A.B.D.d":2,"c":1,"A.C.D.a":3}""")
// Typed Struct read from string:
Assert.assertEquals(ts1.toString, "{\n\td : 1\n\tb : true\n\tc : 1\n\ta : 1\n\tA.B.D.b : true\n\tA.B.D.c : 2\n\tA.B.D.d : 2\n\tA.C.D.a : 3\n\tA.C.D.b : false\n\tA.C.D.c : 3\n\tA.C.D.d : 3\n\n}\n")
Assert.assertEquals(ts1.toString, "{\n\td : \t1\n\tb : \ttrue\n\tc : \t1\n\ta : \t1\n\tA.B.D.b : \ttrue\n\tA.B.D.c : \t2\n\tA.B.D.d : \t2\n\tA.C.D.a : \t3\n\tA.C.D.b : \tfalse\n\tA.C.D.c : \t3\n\tA.C.D.d : \t3\n}")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment