package owltools.io;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;

import org.coode.owlapi.obo.parser.OBOOntologyFormat;
import org.junit.Test;
import org.obolibrary.obo2owl.Obo2Owl;
import org.obolibrary.oboformat.model.OBODoc;
import org.obolibrary.oboformat.parser.OBOFormatParser;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLObject;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;

import owltools.OWLToolsTestBasics;
import owltools.graph.OWLGraphEdge;
import owltools.graph.OWLGraphWrapper;
import owltools.graph.OWLGraphWrapper.ISynonym;
import owltools.io.OWLGsonRenderer;

public class OWLGraphWrapperNameProviderTest extends OWLToolsTestBasics {


	@Test
	public void testWriter() throws Exception{
		OBOFormatParser p = new OBOFormatParser();
		ParserWrapper pw = new ParserWrapper();
		OWLGraphWrapper  wrapper = getOBO2OWLOntologyWrapper("regulation_of_anti_apoptosis_xp_addon.obo");

		Obo2Owl bridge = new Obo2Owl();
		OBODoc obodoc = p.parse(new BufferedReader(new FileReader(getResource("regulation_of_anti_apoptosis_xp-baseline.obo"))));
		OWLOntology ontology = bridge.convert(obodoc);
		wrapper.addSupportOntology(ontology);
		
		ByteArrayOutputStream s = new ByteArrayOutputStream();

		pw.saveOWL(wrapper.getSourceOntology(), new OBOOntologyFormat(), s, wrapper);
		
		String oboString = s.toString();
		
		String[] lines = oboString.split("\n");
		int n = 0;
		for (String line : lines) {
			System.out.println("LINE: "+line);	
			if (line.startsWith("id: GO:0043066 ! negative regulation of apoptosis")) {
				n++;
			}
			if (line.startsWith("GO:0043069 ! negative regulation of programmed cell death")) {
				n++;
			}
		}
		
		assertEquals("ids do not have comments added", 2, n);

	}



	
	private OWLGraphWrapper getOBO2OWLOntologyWrapper(String file) throws OWLOntologyCreationException, FileNotFoundException, IOException{
		OBOFormatParser p = new OBOFormatParser();
		OBODoc obodoc = p.parse(new BufferedReader(new FileReader(getResource(file))));
		Obo2Owl bridge = new Obo2Owl();
		OWLOntology ontology = bridge.convert(obodoc);
		OWLGraphWrapper wrapper = new OWLGraphWrapper(ontology);
		return wrapper;
	}
	
	

}

@@ -56,206 +56,11 @@
 ert.
-assertEquals;%0Aimport static junit.framework.Assert.assertNotNull;%0Aimport static junit.framework.Assert.assertNull;%0Aimport static junit.framework.Assert.assertTrue;%0Aimport static org.junit.Assert.
 *;%0A
+
 %0Aimp
@@ -91,39 +91,8 @@
 er;%0A
-import java.io.BufferedWriter;%0A
 impo
@@ -221,88 +221,8 @@
 ion;
-%0Aimport java.io.PrintWriter;%0Aimport java.io.StringWriter;%0Aimport java.util.List;
 %0A%0Aim
@@ -441,200 +441,8 @@
 er;%0A
-import org.semanticweb.owlapi.apibinding.OWLManager;%0Aimport org.semanticweb.owlapi.model.OWLAxiom;%0Aimport org.semanticweb.owlapi.model.OWLClass;%0Aimport org.semanticweb.owlapi.model.OWLObject;%0A
 impo
@@ -555,64 +555,8 @@
 ion;
-%0Aimport org.semanticweb.owlapi.model.OWLOntologyManager;
 %0A%0Aim
@@ -593,44 +593,8 @@
 cs;%0A
-import owltools.graph.OWLGraphEdge;%0A
 impo
@@ -631,92 +631,8 @@
 per;
-%0Aimport owltools.graph.OWLGraphWrapper.ISynonym;%0Aimport owltools.io.OWLGsonRenderer;
 %0A%0Apu
@@ -1615,16 +1615,20 @@
 tsWith(%22
+id: 
 GO:00430
@@ -1768,12 +1768,8 @@
 %09%7D%0A%0A
-%0A%0A%09%0A
 %09pri

fix test case