Commit 4128b89e by Harish Butani

assertions in place of printlns for tests

parent 4c1f4c8f
......@@ -88,7 +88,7 @@ public abstract class BaseTest {
s.set("i", 1.0);
s.set("j", BigInteger.valueOf(1L));
s.set("k", new BigDecimal(1));
s.set("l", new Date(System.currentTimeMillis()));
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)}));
Map<String, Double> hm = Maps.<String, Double>newHashMap();
......
......@@ -20,6 +20,7 @@ package org.apache.metadata;
import org.apache.metadata.storage.StructInstance;
import org.apache.metadata.types.*;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
......@@ -39,7 +40,24 @@ public class StructTest extends BaseTest {
public void test1() throws MetadataException {
Struct s = createStruct(ms);
ITypedStruct ts = structType.convert(s, Multiplicity.REQUIRED);
System.out.println(ts);
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");
}
@Test
......@@ -50,7 +68,17 @@ public class StructTest extends BaseTest {
s2.set("a", 1);
s2.set("s", s1);
ITypedStruct ts = recursiveStructType.convert(s2, Multiplicity.REQUIRED);
System.out.println(ts);
Assert.assertEquals(ts.toString(), "{\n" +
"\ta : 1\n" +
"\ts : {\n" +
"\ta : 1\n" +
"\ts : {<null>\n" +
"\n" +
"\n" +
"}\n" +
"\n" +
"\n" +
"}\n");
}
}
package org.apache.metadata;
import com.google.common.collect.ImmutableList;
import org.junit.Assert;
import org.apache.metadata.storage.StructInstance;
import org.apache.metadata.types.*;
import org.junit.Before;
......@@ -65,7 +66,20 @@ public class TraitTest extends BaseTest {
ITypedStruct ts = DType.convert(s1, Multiplicity.REQUIRED);
System.out.println(ts);
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");
/*
* cast to B and set the 'b' attribute on A.
......@@ -74,7 +88,20 @@ public class TraitTest extends BaseTest {
IStruct s2 = DType.castAs(ts, "B");
s2.set("A.B.b", false);
System.out.println(ts);
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");
/*
* cast again to A and set the 'b' attribute on A.
......@@ -82,7 +109,20 @@ public class TraitTest extends BaseTest {
TraitType AType = (TraitType) ms.getTypeSystem().getDataType("A");
IStruct s3 = BType.castAs(s2, "A");
s3.set("b", true);
System.out.println(ts);
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");
}
}
......@@ -28,6 +28,7 @@ import org.json4s.native.Serialization._
import org.junit.{Test, Before}
import org.apache.metadata.dsl._
import org.json4s.native.JsonMethods._
import org.junit.Assert
class DSLTest extends BaseTest {
......@@ -39,7 +40,7 @@ class DSLTest extends BaseTest {
@Test def test1 {
// 1. Existing Types in System
println(s"Existing Types:\n\t ${listTypes}\n")
Assert.assertEquals(s"${listTypes}", "[t2, t1, int, array<bigdecimal>, long, double, date, float, short, biginteger, byte, string, boolean, bigdecimal, map<string,double>, array<int>]")
defineStructType("mytype",
attrDef("a", INT_TYPE, ATTR_REQUIRED),
......@@ -59,7 +60,7 @@ class DSLTest extends BaseTest {
attrDef("o", mapType(STRING_TYPE, DOUBLE_TYPE)))
// 2. 'mytype' available as a a Type
println(s"Added Type:\n\t ${listTypes}\n")
Assert.assertEquals(s"${listTypes}", "[t2, t1, int, mytype, array<bigdecimal>, long, double, date, float, short, biginteger, byte, string, boolean, bigdecimal, map<string,double>, array<int>]")
// 3. Create a 'mytype' instance from Json
val i = createInstance("mytype", """
......@@ -87,19 +88,19 @@ class DSLTest extends BaseTest {
""")
// 4. Navigate mytype instance in code
println("Examples of Navigate mytype instance in code:\n")
println(s"i.a -> ${i.a}")
println(s"i.o -> ${i.o}")
println(s"i.o.keys -> ${i.o.asInstanceOf[java.util.Map[_,_]].keySet}")
// Examples of Navigate mytype instance in code
Assert.assertEquals(s"${i.a}", "1")
Assert.assertEquals(s"${i.o}", "{b=2.0, a=1.0}")
Assert.assertEquals(s"${i.o.asInstanceOf[java.util.Map[_,_]].keySet}", "[b, a]")
// 5. Serialize mytype instance to Json
println(s"\nJSON:\n ${pretty(render(i))}")
Assert.assertEquals(s"${pretty(render(i))}", "{\n \"$typeName$\":\"mytype\",\n \"e\":1,\n \"n\":[1,1.100000000000000088817841970012523233890533447265625],\n \"h\":1.0,\n \"b\":true,\n \"k\":1,\n \"j\":1,\n \"d\":2,\n \"m\":[1,1],\n \"g\":1,\n \"a\":1,\n \"i\":1.0,\n \"c\":1,\n \"l\":\"2014-12-03T08:00:00.000Z\",\n \"f\":1,\n \"o\":{\n \"b\":2.0,\n \"a\":1.0\n }\n}")
}
@Test def test2 {
// 1. Existing Types in System
println(s"Existing Types:\n\t ${listTypes}\n")
Assert.assertEquals(s"${listTypes}", "[t2, t1, int, array<bigdecimal>, long, double, date, float, short, biginteger, byte, string, boolean, bigdecimal, map<string,double>, array<int>]")
val addrType = defineStructType("addressType",
attrDef("houseNum", INT_TYPE, ATTR_REQUIRED),
......@@ -117,7 +118,8 @@ class DSLTest extends BaseTest {
)
// 2. updated Types in System
println(s"Updated Types:\n\t ${listTypes}")
Assert.assertEquals(s"${listTypes}", "[t2, t1, int, addressType, array<bigdecimal>, long, double, date, float, short, biginteger, byte, string, boolean, bigdecimal, personType, map<string,double>, array<int>]")
// 3. Construct a Person in Code
val person = createInstance("personType")
......@@ -136,7 +138,7 @@ class DSLTest extends BaseTest {
person.address = address
// 4. Convert to Json
println(s"\nJSON:\n ${pretty(render(person))}")
Assert.assertEquals(s"${pretty(render(person))}", "{\n \"$typeName$\":\"personType\",\n \"first_name\":\"Meta\",\n \"address\":{\n \"$typeName$\":\"addressType\",\n \"houseNum\":3460,\n \"city\":\"Palo Alto\",\n \"country\":\"USA\",\n \"state\":\"CA\",\n \"zip\":94303,\n \"street\":\"W Bayshore Rd\"\n },\n \"last_name\":\"Hadoop\"\n}");
val p2 = createInstance("personType", """{
"first_name":"Meta",
......@@ -155,7 +157,7 @@ class DSLTest extends BaseTest {
@Test def testHive(): Unit = {
val hiveTable = HiveMockMetadataService.getTable("tpcds", "date_dim")
println(hiveTable)
//println(hiveTable)
//name : String, typeName : String, comment : String
val fieldType = defineStructType("FieldSchema",
......
......@@ -26,6 +26,7 @@ import org.apache.metadata.types._
import org.json4s.NoTypeHints
import org.junit.Before
import org.junit.Test
import org.junit.Assert
import org.json4s._
import org.json4s.native.Serialization.{read, write => swrite}
......@@ -47,19 +48,18 @@ class SerializationTest extends BaseTest {
val s: Struct = BaseTest.createStruct(ms)
val ts: ITypedStruct = structType.convert(s, Multiplicity.REQUIRED)
println("Typed Struct :")
println(ts)
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")
implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer +
new BigDecimalSerializer + new BigIntegerSerializer
//Json representation
val ser = swrite(ts)
println("Json representation :")
println(ser)
Assert.assertEquals(ser, "{\"$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-11T02:35:58.440Z\",\"f\":1,\"o\":{\"b\":2.0,\"a\":1.0}}")
// Typed Struct read back
val ts1 = read[StructInstance](ser)
println("Typed Struct read back:")
println(ts1)
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")
}
@Test def test2 {
......@@ -73,8 +73,8 @@ 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}}""")
println("Typed Struct read from string:")
println(ts1)
// 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")
}
@Test def testTrait {
......@@ -112,16 +112,18 @@ class SerializationTest extends BaseTest {
implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer +
new BigDecimalSerializer + new BigIntegerSerializer
println("Typed Struct :")
println(ts)
// 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")
// Json representation :
val ser = swrite(ts)
println("Json representation :")
println(ser)
Assert.assertEquals(ser, "{\"$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}")
val ts1 = read[StructInstance](
"""
{"$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}""")
println("Typed Struct read from string:")
println(ts1)
// 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")
}
}
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