/*
 * The Gemma project
 * 
 * Copyright (c) 2007-2013 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.assertNotNull;
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.testing.BaseSpringContextTest;

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

    @Autowired
    private OntologyService os;

    /** 
     */
    @Test
    public final void testFindExactMatch() throws Exception {
        // if ( !os.getMgedOntologyService().isOntologyLoaded() ) {
        // os.getMgedOntologyService().startInitializationThread( true );
        // int c = 0;
        // while ( !os.getMgedOntologyService().isOntologyLoaded() ) {
        // Thread.sleep( 10000 );
        // log.info( "Waiting for Ontology to load" );
        // if ( ++c > 10 ) {
        // fail( "Ontology load timeout" );
        // }
        // }
        // }
        // 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
    public void testObsolete() throws Exception {
        os.getDiseaseOntologyService().startInitializationThread( true );
        int c = 0;

        while ( !os.getDiseaseOntologyService().isOntologyLoaded() ) {
            Thread.sleep( 10000 );
            log.info( "Waiting for DiseaseOntology to load" );
            if ( ++c > 20 ) {
                fail( "Ontology load timeout" );
            }
        }

        OntologyTerm t1 = os.getTerm( "http://purl.obolibrary.org/obo/DOID_0050001" );
        assertNotNull( t1 );

        // Actinomadura madurae infectious disease
        assertTrue( os.isObsolete( "http://purl.obolibrary.org/obo/DOID_0050001" ) );

        // inflammatory diarrhea, not obsolete as of May 2012.
        assertNotNull( os.getTerm( "http://purl.obolibrary.org/obo/DOID_0050132" ) );
        assertTrue( !os.isObsolete( "http://purl.obolibrary.org/obo/DOID_0050132" ) );

    }
}

@@ -2139,16 +2139,19 @@
 %0A       
+ //
  os.getD
@@ -2216,16 +2216,19 @@
 %0A       
+ //
  int c =
@@ -2231,24 +2231,34 @@
  c = 0;%0A
+        //
 %0A       
  while (
@@ -2249,16 +2249,19 @@
 %0A       
+ //
  while (
@@ -2324,19 +2324,18 @@
         
-   
+//
  Thread.
@@ -2358,19 +2358,18 @@
         
- 
-  
+//
  log.inf
@@ -2420,19 +2420,18 @@
         
-   
+//
  if ( ++
@@ -2449,23 +2449,18 @@
         
-       
+//
  fail( %22
@@ -2491,21 +2491,33 @@
 ;%0A      
+  // %7D%0A
      
+   //
  %7D%0A     
@@ -2523,18 +2523,18 @@
     
-%7D%0A
+//
 %0A       
  Ont
@@ -2529,16 +2529,19 @@
 %0A       
+ //
  Ontolog
@@ -2611,32 +2611,35 @@
 0001%22 );%0A       
+ //
  assertNotNull( 
@@ -2640,24 +2640,34 @@
 Null( t1 );%0A
+        //
 %0A        // 
@@ -2665,16 +2665,19 @@
       //
+ //
  Actinom
@@ -2708,32 +2708,35 @@
  disease%0A       
+ //
  assertTrue( os.
@@ -2794,24 +2794,34 @@
 50001%22 ) );%0A
+        //
 %0A        // 
@@ -2819,16 +2819,19 @@
       //
+ //
  inflamm
@@ -2878,24 +2878,27 @@
 012.%0A       
+ //
  assertNotNu
@@ -2971,16 +2971,19 @@
 %0A       
+ //
  assertT

test tweaks/disable temporarily