1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.flatfile;
18
19 import org.apache.commons.flatfile.Entity;
20 import org.apache.commons.flatfile.EntityArray;
21 import org.apache.commons.flatfile.EntityMap;
22
23
24
25
26 public class ValuesTest extends EntityParserTestBase {
27
28 public void testValues() throws Exception {
29 EntityMap values = (EntityMap) entityFactory.getEntity("values");
30 assertValue("A", values.getChild("A"));
31 assertValue("BB", values.getChild("BB"));
32 assertValue("CCC", values.getChild("CCC"));
33 assertValue("DDDD", values.getChild("DDDD"));
34 assertValue("AAAA", values.getChild("A4"));
35 assertValue("BBBB", values.getChild("B4"));
36 assertValue("CCCC", values.getChild("C4"));
37 assertValue("DDDD", values.getChild("D4"));
38 testArray((EntityArray) ((EntityMap) values.getChild("initarray"))
39 .getChild("array"));
40 testArray((EntityArray) values.getChild("array"));
41 assertValue("twv", values.getChild("x"));
42 assertValue("vwt", values.getChild("y"));
43 assertValue("123123", values.getChild("z"));
44 assertValue("twvtwv", values.getChild("typeWithValue"));
45 }
46
47 private void testArray(EntityArray array) throws Exception {
48 assertValue("123456", array);
49 assertValue("12", array.getChild(0));
50 assertValue("34", array.getChild(1));
51 assertValue("56", array.getChild(2));
52 }
53
54 public void testImplicitLength() throws Exception {
55 Entity e = entityFactory.getEntity("implicitLength");
56 assertEquals(12, e.length());
57 assertValue("foo-bar-baz!", e);
58 }
59
60 public void testOverrideChildren() throws Exception {
61 Entity e = entityFactory.getEntity("overrideChildren");
62 assertEquals(45, e.length());
63 assertEquals("", new String(e.getValue()).trim());
64 }
65
66
67
68
69
70
71 protected String getSource() {
72 return "values.test";
73 }
74 }