Package fr.inra.lipm.jezlucene.cfg

Source Code of fr.inra.lipm.jezlucene.cfg.IniLoaderTest

package fr.inra.lipm.jezlucene.cfg;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;
import java.nio.file.NoSuchFileException;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import fr.inra.lipm.jezlucene.cfg.IniLoader;

/**
* @author llegrand
*/
@RunWith(MockitoJUnitRunner.class)
public class IniLoaderTest {

    @Rule
    public ExpectedException exception = ExpectedException.none();

    @Before
    public void setUp() throws Exception {

    }

    @Test
    public final void testVoid() throws Exception {
        final IniLoader parser = new IniLoader(new File(ClassLoader.getSystemResource("empty.cfg").getFile()));
        assertTrue(parser.getAll().isEmpty());
    }

    @Test
    public final void testDirectory() throws IOException {
        exception.expect(IOException.class);
        new IniLoader(new File(""));
    }

    @Test
    public final void testNoFile() throws IOException {
        exception.expect(NoSuchFileException.class);
        new IniLoader(new File("thisfiledoesntexists"));
    }

    @Test
    public final void testXPathGetAll() throws IOException {
        final IniLoader parser = new IniLoader(new File(ClassLoader.getSystemResource("idx.sequence.cfg").getFile()));
        assertEquals(174, parser.getAll().size());
    }

    @Test
    public final void testXPathGet() throws IOException {
        final IniLoader parser = new IniLoader(new File(ClassLoader.getSystemResource("idx.sequence.cfg").getFile()));
        for (final String key : parser.getAll()) {
            assertNotNull(key, parser.get(key));
        }
    }

    @Test
    public final void testXPathGetBadKey() throws IOException {
        final IniLoader parser = new IniLoader(new File(ClassLoader.getSystemResource("idx.sequence.cfg").getFile()));
        assertNull(parser.get("toto"));
    }

    @Test
    public final void testXPathGetDuplicatedKey() throws IOException {
        final IniLoader parser = new IniLoader(new File(ClassLoader.getSystemResource("idx.sequence.cfg").getFile()));
        assertTrue("get last value", "private".equals(parser.get("status:archive_sequence-date")));
    }

    @Test
    public final void testXPathGetKey() throws IOException {
        final IniLoader parser = new IniLoader(new File(ClassLoader.getSystemResource("idx.sequence.cfg").getFile()));
        assertTrue("metadata_filepath".equals(parser.get("docid")));
    }

    @Test
    public final void testTextGetAll() throws IOException {
        final IniLoader parser = new IniLoader(new File(ClassLoader.getSystemResource("idx.fasta.cfg").getFile()));
        assertEquals(9, parser.getAll().size());
    }

    @Test
    public final void testTextGet() throws IOException {
        final IniLoader parser = new IniLoader(new File(ClassLoader.getSystemResource("idx.fasta.cfg").getFile()));
        for (final String key : parser.getAll()) {
            assertNotNull(key, parser.get(key));
        }
    }

    @Test
    public final void testGFFGetAll() throws IOException {
        final IniLoader parser = new IniLoader(new File(ClassLoader.getSystemResource("idx.gff.cfg").getFile()));
        assertEquals(9, parser.getAll().size());
    }
}
TOP

Related Classes of fr.inra.lipm.jezlucene.cfg.IniLoaderTest

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.