/*
 * The Gemma project
 * 
 * Copyright (c) 2007 University of British Columbia
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package ubic.gemma.ontology;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.Collection;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import ubic.basecode.ontology.model.OntologyTerm;
import ubic.gemma.model.common.description.Characteristic;
import ubic.gemma.ontology.OntologyService;
import ubic.gemma.testing.BaseSpringContextTest;

/**
 * @author paul
 * @version $Id$
 */
public class OntologyServiceTest extends BaseSpringContextTest {

    @Autowired
    OntologyService os;

    /**
     * This test can fail if the db isn't initialized public void testListAvailableOntologies() throws Exception {
     * Collection<Ontology> name = OntologyService.listAvailableOntologies(); assertTrue( name.size() > 0 ); }
     */
    @Test
    public final void testFindExactMatch() throws Exception {
        os.getMgedOntologyService().startInitializationThread( true );
        while ( !os.getMgedOntologyService().isOntologyLoaded() ) {
            Thread.sleep( 1000 );
            log.info( "Waiting for Ontology to load" );
        }
        Collection<Characteristic> name = os.findExactTerm( "male",
                "http://mged.sourceforge.net/ontologies/MGEDOntology.owl#Sex", null );
        for ( Characteristic characteristic : name ) {
            log.info( characteristic );
        }
        assertTrue( name.size() > 0 );
    }

    /**
     * Test for problem with birnlex, which returns 'organ' as a _subclass_ of 'liver'.
     * 
     * @throws Exception
     */
    @Test
    public final void testFindTerm() throws Exception {
        os.getBirnLexOntologyService().startInitializationThread( true );
        while ( !os.getBirnLexOntologyService().isOntologyLoaded() ) {
            Thread.sleep( 5000 );
            log.info( "Waiting for Ontology to load" );
        }
        Collection<OntologyTerm> terms = os.findTerms( "liver" );
        assertTrue( terms.size() > 0 );
        //
        for ( OntologyTerm term : terms ) {
            if ( term.getLabel().contains( "Organ" ) ) {
                fail( "Should get organ as a child of liver" );
            }
        }
    }

}

@@ -718,45 +718,8 @@
 rue;
-%0Aimport static org.junit.Assert.fail;
 %0A%0Aim
@@ -837,58 +837,8 @@
 d;%0A%0A
-import ubic.basecode.ontology.model.OntologyTerm;%0A
 impo
@@ -896,52 +896,8 @@
 ic;%0A
-import ubic.gemma.ontology.OntologyService;%0A
 impo
@@ -1951,768 +1951,9 @@
   %7D%0A
-%0A    /**%0A     * Test for problem with birnlex, which returns 'organ' as a _subclass_ of 'liver'.%0A     * %0A     * @throws Exception%0A     */%0A    @Test%0A    public final void testFindTerm() throws Exception %7B%0A        os.getBirnLexOntologyService().startInitializationThread( true );%0A        while ( !os.getBirnLexOntologyService().isOntologyLoaded() ) %7B%0A            Thread.sleep( 5000 );%0A            log.info( %22Waiting for Ontology to load%22 );%0A        %7D%0A        Collection%3COntologyTerm%3E terms = os.findTerms( %22liver%22 );%0A        assertTrue( terms.size() %3E 0 );%0A        //%0A        for ( OntologyTerm term : terms ) %7B%0A            if ( term.getLabel().contains( %22Organ%22 ) ) %7B%0A                fail( %22Should get organ as a child of liver%22 );%0A            %7D%0A        %7D%0A    %7D
+ 
 %0A%0A%7D%0A

remove unneeded test