Package org.gedcom4j.parser

Source Code of org.gedcom4j.parser.Issue61Test

package org.gedcom4j.parser;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.gedcom4j.model.Gedcom;
import org.gedcom4j.model.Individual;
import org.gedcom4j.model.StringTree;
import org.junit.Test;

/**
* Test for <a href="https://github.com/frizbog/gedcom4j/issues/61">issue 61</a> which allows unknown tags to be treated
* as custom tags, as an option.
*
* @author frizbog
*/
public class Issue61Test {

    /**
     * Test loading a file with bad tags using loose custom tag handling.
     *
     * @throws IOException
     *             if the file can't be read
     * @throws GedcomParserException
     *             if there's a parsing problem
     */
    @Test
    public void testIssue61Loose() throws IOException, GedcomParserException {
        GedcomParser gp = new GedcomParser();
        gp.strictCustomTags = false;
        gp.load("sample/Harry_Potter.ged");
        Gedcom g = gp.gedcom;
        assertNotNull(g);
        assertTrue(gp.errors.isEmpty());
        for (Individual i : g.individuals.values()) {
            assertNotNull(i);
            assertNotNull(i.customTags);
            assertFalse("Individual " + i + " has no custom tags", i.customTags.isEmpty());
            for (StringTree ct : i.customTags) {
                assertTrue("Custom tag should be WAND or MUGL, but is " + ct.value, "WAND".equals(ct.tag) || "MUGL".equals(ct.tag));
                if ("WAND".equals(ct.tag)) {
                    assertNotNull(ct.value);
                    assertFalse(ct.value.trim().length() == 0);
                }
                if ("MUGL".equals(ct.tag)) {
                    assertNull(ct.value);
                }
            }
        }
    }

    /**
     * Test loading a file with bad tags using strict custom tag handling.
     *
     * @throws IOException
     *             if the file can't be read
     * @throws GedcomParserException
     *             if there's a parsing problem
     */
    @Test
    public void testIssue61Strict() throws IOException, GedcomParserException {
        GedcomParser gp = new GedcomParser();
        gp.strictCustomTags = true;
        gp.load("sample/Harry_Potter.ged");
        Gedcom g = gp.gedcom;
        assertNotNull(g);
        assertTrue(!gp.errors.isEmpty());
        for (String e : gp.errors) {
            // These are the bad tags that were deliberately introduced
            assertTrue(e.contains("WAND") || e.contains("MUGL"));
        }
        for (Individual i : g.individuals.values()) {
            assertNotNull(i);
            assertNotNull(i.customTags);
            assertTrue(i.customTags.isEmpty());
        }
    }
}
TOP

Related Classes of org.gedcom4j.parser.Issue61Test

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.