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 BasicFunctionalityTest extends EntityParserTestBase {
27  
28      @Test
29      public void testBasicFunctionality() throws Exception {
30          EntityMap test1 = (EntityMap) entityFactory.getEntity("basic");
31          assertEquals(1, test1.getChild("foo").length());
32          assertEquals(2, test1.getChild("bar").length());
33          assertEquals(3, test1.getChild("baz").length());
34          EntityArray simpleArray = (EntityArray) test1.getChild("simpleArray");
35          int sz = simpleArray.size();
36          assertEquals(3, sz);
37          for (int i = 0; i < sz; i++) {
38              assertEquals(1, simpleArray.getChild(i).length());
39          }
40          EntityMap complex = (EntityMap) test1.getChild("complex");
41          assertEquals(3, complex.getChildMap().size());
42          assertEquals(1, complex.getChild("foo").length());
43          assertEquals(2, complex.getChild("bar").length());
44          assertEquals(3, complex.getChild("baz").length());
45  
46          EntityArray complexArray = (EntityArray) test1.getChild("complexArray");
47          sz = complexArray.size();
48          assertEquals(3, sz);
49          for (int i = 0; i < sz; i++) {
50              EntityMap child = (EntityMap) complexArray.getChild(i);
51              assertEquals(6, child.length());
52              assertEquals(1, child.getChild("foo").length());
53              assertEquals(2, child.getChild("bar").length());
54              assertEquals(3, child.getChild("baz").length());
55          }
56      }
57  
58      protected String getSource() {
59          return "basic.test";
60      }
61  }