/*
 * $Id: EDOALParserTest.java 1367 2010-03-26 21:48:04Z euzenat $
 *
 * Copyright (C) INRIA, 2009-2010
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Configuration;
import org.testng.annotations.Test;

import org.semanticweb.owl.align.AlignmentVisitor;
import org.semanticweb.owl.align.AlignmentException;
import org.semanticweb.owl.align.Alignment;

import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor;
import fr.inrialpes.exmo.align.parser.AlignmentParser;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.FileOutputStream;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.net.URI;


/**
 * These tests corresponds to the tests presented in the examples/omwg directory
 */

public class EDOALParserTest {

    private AlignmentParser aparser1 = null;

    @Test(groups = { "full", "omwg", "raw" })
    public void setUp() throws Exception {
	aparser1 = new AlignmentParser( 0 );
	assertNotNull( aparser1 );
    }

    @Test(groups = { "full", "omwg", "raw" }, dependsOnMethods={ "setUp" })
    public void roundTripTest() throws Exception {
	// Load the full test
	aparser1.initAlignment( null );
	Alignment alignment = aparser1.parse( "file:examples/omwg/total.xml" );
	assertNotNull( alignment );
	// Print it in a string
	ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
	PrintWriter writer = new PrintWriter (
			  new BufferedWriter(
			       new OutputStreamWriter( stream, "UTF-8" )), true);
	AlignmentVisitor renderer = new RDFRendererVisitor( writer );
	alignment.render( renderer );
	writer.flush();
	writer.close();
	String str1 = stream.toString();
	// Read it again
	aparser1 = new AlignmentParser( 0 );
	aparser1.initAlignment( null );
	//System.err.println( str1 );
	alignment = aparser1.parseString( str1 );
	// Print it in another string
	stream = new ByteArrayOutputStream(); 
	writer = new PrintWriter (
			  new BufferedWriter(
			       new OutputStreamWriter( stream, "UTF-8" )), true);
	renderer = new RDFRendererVisitor( writer );
	alignment.render( renderer );
	writer.flush();
	writer.close();
	String str2 = stream.toString();
	// They should be the same... (no because of invertion...)
	//assertEquals( str1, str2 );
	// But have the same length
	assertEquals( str1.length(), str2.length() );
    }
}
