package edu.columbia.gemma.loader.expression.arrayDesign;

import java.io.InputStream;
import java.util.Iterator;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import edu.columbia.gemma.expression.designElement.CompositeSequence;
import edu.columbia.gemma.expression.designElement.Reporter;

/**
 * <hr>
 * <p>
 * Copyright (c) 2004-2005 Columbia University
 * 
 * @author pavlidis
 * @version $Id$
 */
public class AffyProbeReaderTest extends TestCase {
    protected static final Log log = LogFactory.getLog( AffyProbeReaderTest.class );
    AffyProbeReader apr;
    InputStream is;

    /*
     * @see TestCase#setUp()
     */
    protected void setUp() throws Exception {
        super.setUp();
        apr = new AffyProbeReader();
        apr.setSequenceField( 5 );
        is = AffyProbeReaderTest.class.getResourceAsStream( "/data/loader/affymetrix-probes-test.txt" );

    }

    /*
     * @see TestCase#tearDown()
     */
    protected void tearDown() throws Exception {
        super.tearDown();
        apr = null;
        is.close();
    }

    /*
     * Class under test for Map read(InputStream)
     */
    public final void testReadInputStream() throws Exception {

        assertTrue( "InputStream was null", is != null );

        apr.parse( is );

        String expectedValue = "TCACGGCAGGACAACGAGAAAGCCC"; // 10
        CompositeSequence cs = ( ( CompositeSequence ) apr.get( "1004_at" ) );

        assertTrue( "CompositeSequence was null", cs != null );

        boolean foundIt = false;
        for ( Iterator iter = cs.getReporters().iterator(); iter.hasNext(); ) {
            Reporter element = ( Reporter ) iter.next();
            if ( element.getName().equals( "1004_at:265:573" ) ) {
                String actualValue = element.getImmobilizedCharacteristic().getSequence();

                assertEquals( expectedValue, actualValue );
                foundIt = true;
                break;
            }
        }
        assertTrue( "Didn't find the probe ", foundIt );
    }

}

@@ -1113,32 +1113,1012 @@
 close();%0A    %7D%0A%0A
+    public final void testReadInputStreamNew() throws Exception %7B%0A        is = AffyProbeReaderTest.class.getResourceAsStream( %22/data/loader/affymetrix-newprobes-example.txt%22 );%0A        apr.setSequenceField( 4 );%0A        apr.parse( is );%0A%0A        String expectedValue = %22AGCTCAGGTGGCCCCAGTTCAATCT%22; // 4%0A        CompositeSequence cs = ( ( CompositeSequence ) apr.get( %221000_at%22 ) );%0A%0A        assertTrue( %22CompositeSequence was null%22, cs != null );%0A%0A        boolean foundIt = false;%0A        for ( Iterator iter = cs.getReporters().iterator(); iter.hasNext(); ) %7B%0A            Reporter element = ( Reporter ) iter.next();%0A            if ( element.getName().equals( %221000_at:617:349%22 ) ) %7B%0A                String actualValue = element.getImmobilizedCharacteristic().getSequence();%0A%0A                assertEquals( expectedValue, actualValue );%0A                foundIt = true;%0A                break;%0A            %7D%0A        %7D%0A        assertTrue( %22Didn't find the probe %22, foundIt );%0A    %7D%0A%0A
     /*%0A     * Cl

add new test that uses "new" file format.