package org.intermine.bio.dataconversion;

import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;

import junit.framework.TestCase;

/**
 * IdResolverFactory Unit Tests
 *
 * @author Fengyuan Hu
 *
 */
public class IdResolverFactoryTest extends TestCase {

    IdResolverFactory factory;
    String idresolverCache = "resolver.cache.test";

    public IdResolverFactoryTest() {
    }

    public IdResolverFactoryTest(String name) {
        super(name);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        factory = new EntrezGeneIdResolverFactory(); // can only test on a concrete class
        IdResolverFactory.resolver = new IdResolver();
    }

    public void testCreateMultipleResolvers() throws Exception {
        // test entrez + mgi factory
        EntrezGeneIdResolverFactory entrezFactory = new EntrezGeneIdResolverFactory();
        File entrezFile = new File("resources/entrez.data.sample");
        if (!entrezFile.exists()) {
            fail("data file not found");
        }
        entrezFactory.createFromFile(entrezFile, new HashSet<String>(Arrays.asList(new String[] {"7227", "4932", "7955"})));


        MgiIdentifiersResolverFactory mgiFactory = new MgiIdentifiersResolverFactory();
        File mgiFile = new File("resources/mgi.data.sample");
        if (!mgiFile.exists()) {
            fail("data file not found");
        }
        mgiFactory.createFromFile(mgiFile);

        assertTrue(IdResolverFactory.resolver.getTaxons().size() == 3);
        assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] {"4932", "10090", "7955"})), IdResolverFactory.resolver.getTaxons());
    }
}

@@ -57,16 +57,37 @@
 o.File;%0A
+import java.net.URL;%0A
 import j
@@ -403,16 +403,133 @@
 .test%22;%0A
+    final static String ENTREZ_FILE = %22entrez.data.sample%22;%0A    final static String MOUSE_FILE = %22mgi.data.sample%22;%0A%0A
 %0A    pub
@@ -1062,32 +1062,34 @@
 rFactory();%0A
+%0A%0A
         
 File entrezF
@@ -1080,91 +1080,248 @@
     
-File entrezFile = new File(%22resources/entrez.data.sample%22);%0A        if (!entrezFile
+ClassLoader cl = getClass().getClassLoader();%0A        URL u = cl.getResource(ENTREZ_FILE);%0A        if (u == null) %7B%0A            fail(%22data file not found%22);%0A            return;%0A        %7D%0A%0A        File f = new File(u.toURI());%0A        if (!f
 .exi
@@ -1372,32 +1372,33 @@
 nd%22);%0A        %7D%0A
+%0A
         entrezFa
@@ -1422,18 +1422,9 @@
 ile(
-entrezFile
+f
 , ne
@@ -1494,25 +1494,24 @@
 7955%22%7D)));%0A%0A
-%0A
         MgiI
@@ -1582,24 +1582,25 @@
 rFactory();%0A
+%0A
         File
@@ -1623,35 +1623,67 @@
 ile(
-%22resources/mgi.data.sample%22
+getClass().getClassLoader().getResource(MOUSE_FILE).toURI()
 );%0A 
@@ -2034,8 +2034,9 @@
     %7D%0A%7D%0A
+%0A

update test so it works regardless of which task called it. Refs #754