@Test
public void testBytesToComplexTypeMisc() throws IOException, ParseException {
String s = "(a,b";
Schema schema = Utils.getSchemaFromString("t:tuple(a:chararray, b:chararray)");
ResourceFieldSchema rfs = new ResourceSchema(schema).getFields()[0];
Tuple t = ps.getLoadCaster().bytesToTuple(s.getBytes(), rfs);
assertTrue(t==null);
s = "{(a,b}";
schema = Utils.getSchemaFromString("b:bag{t:tuple(a:chararray, b:chararray)}");
rfs = new ResourceSchema(schema).getFields()[0];
DataBag b = ps.getLoadCaster().bytesToBag(s.getBytes(), rfs);
assertTrue(b==null);
s = "{(a,b)";
schema = Utils.getSchemaFromString("b:bag{t:tuple(a:chararray, b:chararray)}");
rfs = new ResourceSchema(schema).getFields()[0];
b = ps.getLoadCaster().bytesToBag(s.getBytes(), rfs);
assertTrue(b==null);
s = "[ab]";
Map<String, Object> m = ps.getLoadCaster().bytesToMap(s.getBytes());
assertTrue(m==null);
s = "[a#b";
m = ps.getLoadCaster().bytesToMap(s.getBytes());
assertTrue(m==null);
s = "[a#]";
m = ps.getLoadCaster().bytesToMap(s.getBytes());
Map.Entry<String, Object> entry = m.entrySet().iterator().next();
assertTrue(entry.getKey().equals("a"));
assertTrue(entry.getValue()==null);
s = "[#]";
m = ps.getLoadCaster().bytesToMap(s.getBytes());
assertTrue(m==null);
s = "(a,b)";
schema = Utils.getSchemaFromString("t:tuple()");
rfs = new ResourceSchema(schema).getFields()[0];
t = ps.getLoadCaster().bytesToTuple(s.getBytes(), rfs);
assertTrue(t.size()==1);
assertTrue(t.get(0) instanceof DataByteArray);
assertTrue(t.get(0).toString().equals("a,b"));
s = "[a#(1,2,3)]";
m = ps.getLoadCaster().bytesToMap(s.getBytes());
entry = m.entrySet().iterator().next();
assertTrue(entry.getKey().equals("a"));
assertTrue(entry.getValue() instanceof DataByteArray);
assertTrue(entry.getValue().toString().equals("(1,2,3)"));
s = "(a,b,(123,456,{(1,2,3)}))";
schema = Utils.getSchemaFromString("t:tuple()");
rfs = new ResourceSchema(schema).getFields()[0];
t = ps.getLoadCaster().bytesToTuple(s.getBytes(), rfs);
assertTrue(t.size()==1);
assertTrue(t.get(0) instanceof DataByteArray);
assertTrue(t.get(0).toString().equals("a,b,(123,456,{(1,2,3)})"));
s = "(a,b,(123,456,{(1,2,3}))";
schema = Utils.getSchemaFromString("t:tuple()");
rfs = new ResourceSchema(schema).getFields()[0];
t = ps.getLoadCaster().bytesToTuple(s.getBytes(), rfs);
assertTrue(t==null);
}