Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Integration test, launchable

  • Loading branch information...
commit e65298f6e6f5fefccc12db5f9419405f884ce6db 1 parent d205e3b
Laurent Mazuel authored
Showing with 90 additions and 70 deletions.
  1. +1 −1  .classpath
  2. +82 −59 src/test/java/MainIT.java
  3. +7 −10 src/test/java/Settings.java
View
2  .classpath
@@ -2,7 +2,7 @@
<classpath>
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
<classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
- <classpathentry kind="src" path="src/test/java"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/4.8.2/junit-4.8.2.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
View
141 src/test/java/MainIT.java
@@ -1,8 +1,10 @@
-
import java.io.File;
+import java.io.FilenameFilter;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Vector;
import junit.framework.TestCase;
import net.antidot.semantic.rdf.model.impl.sesame.SesameDataSet;
@@ -14,81 +16,109 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
import org.openrdf.rio.RDFFormat;
+@RunWith(Parameterized.class)
public class MainIT extends TestCase {
+ public enum NormTested {
+ DirectMapping, R2RML;
+ }
+
// Log
private static Log log = LogFactory.getLog(MainIT.class);
+ public static final File w3cDefinitionSearchPath = new File(
+ "src/test/resources/");
+ public static final String w3cDirPrefix = "rdb2rdf-ts";
+
+ // Base URI
+ private static final String baseURI = "http://example.com/base/";
+
+ // R2RML suffix. To be improved!
+ private static final String[] r2rmlSuffix = { "", "a", "b", "c", "d", "e",
+ "f", "g", "h", "i", "j", "k" };
+
// Database TEST settings
private static String userName = Settings.userName;
private static String password = Settings.password;
private static String url = Settings.url;
private static String driver = Settings.driver;
- private Connection conn = null;
-
- private static String[] r2rmlSuffix = { "", "a", "b", "c", "d", "e", "f",
- "g", "h", "i", "j", "k" };
+ // Instance field
- private static boolean doDirectMaping = true;
- private static boolean doR2RML = false;
+ private NormTested tested = null;
+ private String directory = null;
- // Base URI
- private static String baseURI = "http://example.com/base/";
-
- @Override
- protected void setUp() throws Exception {
- conn = SQLConnector.connect(userName, password, url, driver,
- Settings.testDbName);
+ public MainIT(NormTested tested, String directory) throws SQLException,
+ InstantiationException, IllegalAccessException,
+ ClassNotFoundException {
+ this.tested = tested;
+ this.directory = directory;
}
- @Test
- public void testExecute() {
- File[] files = listFiles("src/test/resources/rdb2rdf-ts_20120713");
- for (File f : files) {
- runDirectory(f);
+ @Parameters
+ public static Collection<Object[]> getTestsFiles() throws Exception {
+ Collection<Object[]> parameters = new Vector<Object[]>();
+ File[] w3cDirs = w3cDefinitionSearchPath
+ .listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.startsWith(w3cDirPrefix);
+ }
+ });
+
+ for (File w3cDir : w3cDirs) {
+ File[] files = w3cDir.listFiles();
+ for (File f : files) {
+ if (f.isFile()) {
+ continue;
+ }
+ final String file_path = f.getAbsolutePath();
+ parameters.add(new Object[] { NormTested.DirectMapping,
+ file_path });
+ parameters.add(new Object[] { NormTested.R2RML, file_path });
+ }
}
+ return parameters;
}
- private void runDirectory(File f) {
- if (!(f.isDirectory() && f.getName().startsWith("D002"))) {
- return;
- }
-
- log.info("[W3CTester:run] Run test from : " + f.getName());
- try {
- runDirTest(f.getAbsolutePath());
- }
- catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ @Test
+ public void testNorm() throws SQLException, InstantiationException,
+ IllegalAccessException, ClassNotFoundException {
+ log.info("[W3CTester:test] Run tests from : " + directory);
- private void runDirTest(String testAbsolutePath) throws SQLException {
- log.info("[W3CTester:runDirectMapping] Run tests from : "
- + testAbsolutePath);
+ log.info("[W3CTester:setUp] Initialize DB connection");
+ Connection conn = SQLConnector.connect(userName, password, url, driver,
+ Settings.testDbName);
// Clean TEST table
- log.info("[W3CTester:runDirectMapping] Clean test database...");
+ log.info("[W3CTester:test] Clean test database...");
SQLConnector.resetMySQLDatabase(conn, driver);
// Load TEST database
- log.info("[W3CTester:runDirectMapping] Load new tables...");
- SQLConnector.updateDatabase(conn, testAbsolutePath + "/create.sql");
- // Run Direct Mapping
- runDirectMapping(testAbsolutePath);
- // Run R2RML
- runR2RML(testAbsolutePath);
- }
+ log.info("[W3CTester:test] Load new tables...");
+ SQLConnector.updateDatabase(conn, directory + "/create.sql");
+
+ switch (tested) {
+ case DirectMapping:
+ // Run Direct Mapping
+ runDirectMapping(conn);
+ break;
+ case R2RML:
+ // Run R2RML
+ runR2RML(conn);
+ break;
+ default:
+ fail("Norm is not recognized!!!!");
+ }
- private void runDirectMapping(String testAbsolutePath) {
- if (!doDirectMaping)
- return;
+ conn.close();
+ }
+ private void runDirectMapping(Connection conn) {
// Create Direct Mapping
- log.info("[W3CTester:runDirectMapping] Create mapping...");
SesameDataSet result;
try {
result = DirectMapper.generateDirectMapping(conn,
@@ -101,22 +131,16 @@ private void runDirectMapping(String testAbsolutePath) {
return;
}
// Serialize result
- System.out.println(testAbsolutePath);
- result.dumpRDF(testAbsolutePath + "/directGraph-db2triples.ttl",
+ result.dumpRDF(directory + "/directGraph-db2triples.ttl",
RDFFormat.TURTLE);
}
- private void runR2RML(String testAbsolutePath) {
- if (!doR2RML)
- return;
-
+ private void runR2RML(Connection conn) {
// Create Direct Mapping
- log.info("[W3CTester:runR2RML] Working on dir: " + testAbsolutePath);
for (String suffix : r2rmlSuffix) {
// Create R2RML Mapping
- final String test_filepath = testAbsolutePath + "/r2rml" + suffix
- + ".ttl";
+ final String test_filepath = directory + "/r2rml" + suffix + ".ttl";
File r2rml_def_file = new File(test_filepath);
if (r2rml_def_file.exists()) {
log.info("[W3CTester:runR2RML] Working on test: "
@@ -132,8 +156,7 @@ private void runR2RML(String testAbsolutePath) {
continue;
}
// Serialize result
- System.out.println(testAbsolutePath);
- result.dumpRDF(testAbsolutePath + "/mapped" + suffix
+ result.dumpRDF(directory + "/mapped" + suffix
+ "-db2triples.nq", RDFFormat.TURTLE);
}
}
View
17 src/test/java/Settings.java
@@ -3,10 +3,7 @@
import net.antidot.sql.model.core.SQLConnector;
public interface Settings {
-
- // Path to rdb2rdf workspace
- public static String pathToRDB2RDF = "src/main/java/net/antidot/semantic/rdf/rdb2rdf/";
-
+
// MySQL Database TEST settings
/*public static String userName = "root";
public static String password = "root";
@@ -16,10 +13,10 @@
public static String dbName = "mysql";*/
// PostgreSQL Database TEST settings
- public static String userName = "root";
- public static String password = "root";
- public static String driver = SQLConnector.postgresqlDriver;
- public static String testDbName = "test";
- public static String url = "jdbc:postgresql://127.0.0.1:5432/";
- public static String dbName = "postgresql";
+ public static final String userName = "root";
+ public static final String password = "root";
+ public static final String driver = SQLConnector.postgresqlDriver;
+ public static final String testDbName = "test";
+ public static final String url = "jdbc:postgresql://127.0.0.1:5432/";
+ public static final String dbName = "postgresql";
}
Please sign in to comment.
Something went wrong with that request. Please try again.