/*
 * Copyright (C) 2015 see CREDITS.txt
 * All rights reserved.
 */

package fi.uef.envi.emrooz.sesame.test;

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

import java.io.File;
import java.io.IOException;
import java.util.Set;

import junitparams.FileParameters;
import junitparams.JUnitParamsRunner;
import junitparams.converters.ConvertParam;

import org.apache.commons.collections4.CollectionUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openrdf.model.Statement;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.rio.RDFFormat;
import org.openrdf.rio.RDFParseException;
import org.openrdf.sail.memory.MemoryStore;

import fi.uef.envi.emrooz.entity.ssn.Sensor;
import fi.uef.envi.emrooz.rdf.RDFEntityRepresenter;
import fi.uef.envi.emrooz.sesame.SesameKnowledgeStore;
import fi.uef.envi.emrooz.test.ParamsConverterTest;

/**
 * <p>
 * Title: SesameKnowledgeStoreTest
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Project: Emrooz
 * </p>
 * <p>
 * Copyright: Copyright (C) 2015
 * </p>
 * 
 * @author Markus Stocker
 */

@RunWith(JUnitParamsRunner.class)
public class SesameKnowledgeStoreTest {

	@Test
	@FileParameters("src/test/resources/SesameKnowledgeStoreTest-testGetSensors.csv")
	public void testGetSensors(
			String kb,
			@ConvertParam(value = ParamsConverterTest.StringToStatementsConverter.class) Set<Statement> statements,
			String assertType) throws RepositoryException, RDFParseException,
			IOException {
		Repository r = new SailRepository(new MemoryStore());
		r.initialize();
		RepositoryConnection c = r.getConnection();
		c.add(new File(kb), null, RDFFormat.RDFXML);

		RDFEntityRepresenter er = new RDFEntityRepresenter();
		Set<Sensor> e = er.createSensors(statements);

		SesameKnowledgeStore ks = new SesameKnowledgeStore(r);

		Set<Sensor> a = ks.getSensors();

		if (assertType.equals("assertEquals")) {
			assertTrue(CollectionUtils.isEqualCollection(e, a));
			return;
		}

		assertFalse(CollectionUtils.isEqualCollection(e, a));
	}
}

@@ -1661,173 +1661,126 @@
 %7B%0A%09%09
-Repository r = new SailRepository(new MemoryStore());%0A%09%09r.initialize();%0A%09%09RepositoryConnection c = r.getConnection();%0A%09%09c.add(new File(kb), null, RDFFormat.RDFXML
+SesameKnowledgeStore ks = new SesameKnowledgeStore(new SailRepository(new MemoryStore()));%0A%09%09ks.load(new File(kb)
 );%0A
+%09%09
 %0A%09%09R
@@ -1885,66 +1885,8 @@
 );%0A%0A
-%09%09SesameKnowledgeStore ks = new SesameKnowledgeStore(r);%0A%0A
 %09%09Se

test by loading kb file via the sesame knowledge store, rather than the sesame repository connection