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