Package com.fb2pdf.hadoop

Source Code of com.fb2pdf.hadoop.OnDemandSAXParserTest

package com.fb2pdf.hadoop;

import static org.junit.Assert.*;

import java.io.FileInputStream;
import java.io.IOException;

import org.junit.Test;

import com.fb2pdf.hadoop.OnDemandSAXParser.StringPair;

public class OnDemandSAXParserTest
{

    @Test(expected=IOException.class)
    public void testBroken() throws IOException
    {
        FileInputStream fs = new FileInputStream("test_data/broken_fictionbook_2_1.fb2");
        OnDemandSAXParser p = new OnDemandSAXParser(fs);
        StringPair n;
        while((n = p.getNext()) != null)
        {
            assertNotNull(n.a);
            assertNotNull(n.b);
        }
        p.stop();
    }

    /**
     * This test ensures that we are not parsing whole file at once.
     * The XML is broken down the road, but we do not see as we only get first few elements.
     * @throws IOException
     */
    public void testOnDemand() throws IOException
    {
        FileInputStream fs = new FileInputStream("test_data/broken_fictionbook_2_1.fb2");
        OnDemandSAXParser p = new OnDemandSAXParser(fs);
        StringPair n= p.getNext();
        assertNotNull(n);
        p.stop();
    }

    @Test
    public void testGood() throws IOException
    {
        FileInputStream fs = new FileInputStream("test_data/fictionbook_2_1.fb2");
        OnDemandSAXParser p = new OnDemandSAXParser(fs);
        StringPair n;
        int i = 0;
        while((n = p.getNext()) != null)
        {
            i++;
            assertNotNull(n.a);
            assertNotNull(n.b);

            if(i == 19)
            {
                assertEquals("FictionBook/description/title-info/lang", n.a);
                assertEquals("ru", n.b.trim());
            }
            // System.err.println(i+": next: "+n);
        }
        assertEquals(156, i);
        p.stop();
    }

}
TOP

Related Classes of com.fb2pdf.hadoop.OnDemandSAXParserTest

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.