001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.flatfile;
018
019import static org.junit.Assert.assertEquals;
020
021import org.junit.Test;
022
023/**
024 *
025 */
026public class BasicFunctionalityTest extends EntityParserTestBase {
027
028    @Test
029    public void testBasicFunctionality() throws Exception {
030        EntityMap test1 = (EntityMap) entityFactory.getEntity("basic");
031        assertEquals(1, test1.getChild("foo").length());
032        assertEquals(2, test1.getChild("bar").length());
033        assertEquals(3, test1.getChild("baz").length());
034        EntityArray simpleArray = (EntityArray) test1.getChild("simpleArray");
035        int sz = simpleArray.size();
036        assertEquals(3, sz);
037        for (int i = 0; i < sz; i++) {
038            assertEquals(1, simpleArray.getChild(i).length());
039        }
040        EntityMap complex = (EntityMap) test1.getChild("complex");
041        assertEquals(3, complex.getChildMap().size());
042        assertEquals(1, complex.getChild("foo").length());
043        assertEquals(2, complex.getChild("bar").length());
044        assertEquals(3, complex.getChild("baz").length());
045
046        EntityArray complexArray = (EntityArray) test1.getChild("complexArray");
047        sz = complexArray.size();
048        assertEquals(3, sz);
049        for (int i = 0; i < sz; i++) {
050            EntityMap child = (EntityMap) complexArray.getChild(i);
051            assertEquals(6, child.length());
052            assertEquals(1, child.getChild("foo").length());
053            assertEquals(2, child.getChild("bar").length());
054            assertEquals(3, child.getChild("baz").length());
055        }
056    }
057
058    protected String getSource() {
059        return "basic.test";
060    }
061}