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 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       * (non-Javadoc)
68       * 
69       * @see com.pgac.fixedlength.EntityParserTestBase#getSource()
70       */
71      protected String getSource() {
72          return "values.test";
73      }
74  }