View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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  }