package org.wikipathways.wp2rdf;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import org.junit.Assert;
import org.pathvisio.core.model.ConverterException;
import org.pathvisio.core.model.Pathway;
import org.wikipathways.wp2rdf.io.PathwayReader;

import com.hp.hpl.jena.rdf.model.Model;

public abstract class AbstractConvertorTest {

	protected static Model model;

	private static String toString(Model model) {
		ByteArrayOutputStream output = new ByteArrayOutputStream();
		model.write(output, "TURTLE");
		return new String(output.toByteArray());
	}

	public static void loadModelAsGPMLRDF(String gpmlFile, String wpid, String revision) throws ConverterException {
		InputStream input = AbstractConvertorTest.class.getClassLoader().getResourceAsStream(gpmlFile);
		Pathway pathway = PathwayReader.readPathway(input);
		Assert.assertNotNull(pathway);
		model = GpmlConverter.convertGpml(pathway, wpid, revision);
		Assert.assertNotNull(model);
		System.out.println("===== " + gpmlFile + " =====");
		System.out.println(toString(model));
	}

	public static void loadModelAsWPRDF(String gpmlFile, String wpid, String revision) throws ConverterException {
		InputStream input = AbstractConvertorTest.class.getClassLoader().getResourceAsStream(gpmlFile);
		Pathway pathway = PathwayReader.readPathway(input);
		Assert.assertNotNull(pathway);
		model = GpmlConverter.convertWp(pathway, wpid, revision);
		Assert.assertNotNull(model);
		System.out.println("===== " + gpmlFile + " =====");
		System.out.println(toString(model));
	}

}

@@ -119,16 +119,39 @@
 Assert;%0A
+import org.junit.Test;%0A
 import o
@@ -324,16 +324,59 @@
 l.Model;
+%0Aimport com.hp.hpl.jena.rdf.model.Resource;
 %0A%0Apublic
@@ -1611,10 +1611,601 @@
 ));%0A%09%7D%0A%0A
+%09@Test%0A%09public void testForResourceURIsWithWhitespace() %7B%0A%09%09String errors = %22%22;%0A%09%09int errorCount = 0;%0A%09%09for (Resource resource : model.listSubjects().toSet()) %7B%0A%09%09%09String resourceURI = resource.getURI();%0A%09%09%09if (containsWhiteSpace(resourceURI)) %7B%0A%09%09%09%09errors += %22%3C%22 + resourceURI + %22%3E%5Cn%22;%0A%09%09%09%09errorCount++;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09Assert.assertEquals(%0A%09%09%09%22Resource URIs with whitespace:%5Cn%22 + errors,%0A%09%09%090, errorCount%0A%09%09);%0A%09%7D%0A%0A%09private boolean containsWhiteSpace(String string) %7B%0A%09%09for (int i=0; i%3Cstring.length(); i++) %7B%0A%09%09%09if (Character.isWhitespace(string.charAt(i))) return true;%0A%09%09%7D%0A%09%09return false;%0A%09%7D%0A
 %7D%0A

General test: URIs should not contain whitespace