--- /dev/null
+package org.simantics.db.testing.common;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.Platform;
+import org.simantics.db.Driver;
+import org.simantics.db.Driver.Management;
+import org.simantics.db.Manager;
+import org.simantics.db.ServerI;
+import org.simantics.db.Session;
+import org.simantics.db.SessionManager;
+import org.simantics.db.SessionReference;
+import org.simantics.db.exception.DatabaseException;
+
+import fi.vtt.simantics.procore.ProCoreServerReference;
+import fi.vtt.simantics.procore.ProCoreSessionReference;
+import fi.vtt.simantics.procore.SessionManagerSource;
+
+/**
+ * ProCore specific test handler.
+ *
+ */
+public class TestHandler {
+// private final TestSettings testSettings;
+ private final Driver driver;
+ private final File dbFolder;
+ TestHandler(TestSettings testSettings, String dbFolderName) throws DatabaseException {
+// this.testSettings = testSettings;
+ driver = Manager.getDriver("procore");
+ if (null == dbFolderName)
+ dbFolder = Platform.getLocation().append("db").toFile();
+ else
+ dbFolder = new File(dbFolderName);
+ }
+ void initNew() throws DatabaseException {
+ Management m = getManagement();
+ if (m.exist())
+ m.delete();
+ m.create();
+ }
+ void initIfNeccessary() throws DatabaseException {
+ Management m = getManagement();
+ if (!m.exist())
+ m.create();
+ }
+ public Session getSession() throws DatabaseException {
+ // Note that we normally user authentication agent for user identification.
+ Properties props = new Properties();
+ props.setProperty("user", "Default User");
+ props.setProperty("password", "");
+ return driver.getSession(dbFolder.getAbsolutePath(), props);
+ }
+ public ServerI getServer() throws DatabaseException {
+ return driver.getServer(dbFolder.getAbsolutePath(), null);
+ }
+ public Management getManagement() throws DatabaseException {
+ return driver.getManagement(dbFolder.getAbsolutePath(), null);
+ }
+ public Session regSession(long sessionId) throws DatabaseException, IOException {
+ SessionManager sm = SessionManagerSource.getSessionManager();
+ ProCoreServerReference ser = new ProCoreServerReference(dbFolder.toPath());
+ SessionReference ses = new ProCoreSessionReference(ser, sessionId);
+ return sm.createSession(ses, null);
+ }
+
+}
\ No newline at end of file