<commit_before>package org.intermine.bio.dataconversion;

/*
 * Copyright (C) 2002-2008 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.intermine.dataconversion.ItemWriter;
import org.intermine.dataconversion.ItemsTestCase;
import org.intermine.dataconversion.MockItemWriter;
import org.intermine.metadata.Model;
import org.intermine.sql.Database;
import org.intermine.xml.full.Item;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;

public class ChadoDBConverterTest extends ItemsTestCase
{
    public ChadoDBConverterTest(String arg) {
        super(arg);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setUp() throws Exception {
        super.setUp();
    }

    public void testProcessTaxon() throws Exception {
        String orgId = "7227";
        doTestProcess(orgId);
    }

    public void testProcessAbbreviation() throws Exception {
        String orgId = "Dmel";
        doTestProcess(orgId);
    }

    private void doTestProcess(String orgId) throws Exception, IOException {
        MockItemWriter itemWriter = new MockItemWriter(new HashMap<String, org.intermine.model.fulldata.Item>());
        ChadoDBConverter converter =
            new TestChadoDBConverter(null, Model.getInstanceByName("genomic"), itemWriter);
        converter.setOrganisms(orgId);
        converter.setProcessors("org.intermine.bio.dataconversion.TestFlyBaseModuleProcessor");
        converter.process();
        itemWriter.close();
        FileWriter fw = new FileWriter("/tmp/chado-db-test-items.xml");
        PrintWriter pw = new PrintWriter(fw);
        pw.println("<items>");
        for (Object item: itemWriter.getItems()) {
            pw.println(item);
        }
        pw.println("</items>");
        pw.close();
        fw.close();
        assertEquals(readItemSet("ChadoDBConverterTest.xml"), itemWriter.getItems());
    }

    public void testGetFeatures() throws Exception {

        final List<String> minimalSet = Arrays.asList("gene", "exon");

        MockItemWriter itemWriter = new MockItemWriter(new HashMap<String, org.intermine.model.fulldata.Item>());
        ChadoDBConverter converter =
            new ChadoDBConverter(null, Model.getInstanceByName("genomic"), itemWriter);
        FlyBaseModuleProcessor processor = new TestFlyBaseModuleProcessor(converter);
        List<String> actualSet = processor.getFeatures();
        assertTrue(actualSet.containsAll(minimalSet));
    }

    public void testFlyBaseChromosomes() throws Exception {

        MockItemWriter itemWriter =<commit_msg>Better debug output for ChadoDBConverterTest.<commit_after>package org.intermine.bio.dataconversion;

/*
 * Copyright (C) 2002-2008 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.intermine.dataconversion.ItemWriter;
import org.intermine.dataconversion.ItemsTestCase;
import org.intermine.dataconversion.MockItemWriter;
import org.intermine.metadata.Model;
import org.intermine.sql.Database;
import org.intermine.xml.full.Item;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;

public class ChadoDBConverterTest extends ItemsTestCase
{
    public ChadoDBConverterTest(String arg) {
        super(arg);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setUp() throws Exception {
        super.setUp();
    }

    public void testProcessTaxon() throws Exception {
        String orgId = "7227";
        doTestProcess(orgId);
    }

    public void testProcessAbbreviation() throws Exception {
        String orgId = "Dmel";
        doTestProcess(orgId);
    }

    private void doTestProcess(String orgId) throws Exception, IOException {
        MockItemWriter itemWriter = new MockItemWriter(new HashMap<String, org.intermine.model.fulldata.Item>());
        ChadoDBConverter converter =
            new TestChadoDBConverter(null, Model.getInstanceByName("genomic"), itemWriter);
        converter.setOrganisms(orgId);
        converter.setProcessors("org.intermine.bio.dataconversion.TestFlyBaseModuleProcessor");
        converter.process();
        itemWriter.close();
        FileWriter fw = new FileWriter("/tmp/chado-db-test-items-" + orgId + ".xml");
        PrintWriter pw = new PrintWriter(fw);
        pw.println("<items>");
        for (Object item: itemWriter.getItems()) {
            pw.print(item);
        }
        pw.println("</items>");
        pw.close();
        fw.close();
        assertEquals(readItemSet("ChadoDBConverterTest.xml"), itemWriter.getItems());
    }

    public void testGetFeatures() throws Exception {

        final List<String> minimalSet = Arrays.asList("gene", "exon");

        MockItemWriter itemWriter = new MockItemWriter(new HashMap<String, org.intermine.model.fulldata.Item>());
        ChadoDBConverter converter =
            new ChadoDBConverter(null, Model.getInstanceByName("genomic"), itemWriter);
        FlyBaseModuleProcessor processor = new TestFlyBaseModuleProcessor(converter);
        List<String> actualSet = processor.getFeatures();
        assertTrue(actualSet.containsAll(minimalSet));
    }

    public void testFlyBaseChromosomes() throws Exception {

        MockItemWriter itemWriter =
{'fraction_non_alphanumeric': 0.10478128179043744, 'fraction_numerical': 0.004069175991861648, 'mean_word_length': 3.3989560029828487, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '263624', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1633, 'n_words': 370}