1 package org.simantics.db.testing.common;
4 import java.io.IOException;
5 import java.util.Properties;
7 import org.eclipse.core.runtime.Platform;
8 import org.simantics.db.Driver;
9 import org.simantics.db.Driver.Management;
10 import org.simantics.db.Manager;
11 import org.simantics.db.ServerI;
12 import org.simantics.db.Session;
13 import org.simantics.db.SessionManager;
14 import org.simantics.db.SessionReference;
15 import org.simantics.db.exception.DatabaseException;
17 import fi.vtt.simantics.procore.ProCoreServerReference;
18 import fi.vtt.simantics.procore.ProCoreSessionReference;
19 import fi.vtt.simantics.procore.SessionManagerSource;
22 * ProCore specific test handler.
25 public class TestHandler {
26 // private final TestSettings testSettings;
27 private final Driver driver;
28 private final File dbFolder;
29 TestHandler(TestSettings testSettings, String dbFolderName) throws DatabaseException {
30 // this.testSettings = testSettings;
31 driver = Manager.getDriver("procore");
32 if (null == dbFolderName)
33 dbFolder = Platform.getLocation().append("db").toFile();
35 dbFolder = new File(dbFolderName);
37 void initNew() throws DatabaseException {
38 Management m = getManagement();
43 void initIfNeccessary() throws DatabaseException {
44 Management m = getManagement();
48 public Session getSession() throws DatabaseException {
49 // Note that we normally user authentication agent for user identification.
50 Properties props = new Properties();
51 props.setProperty("user", "Default User");
52 props.setProperty("password", "");
53 return driver.getSession(dbFolder.getAbsolutePath(), props);
55 public ServerI getServer() throws DatabaseException {
56 return driver.getServer(dbFolder.getAbsolutePath(), null);
58 public Management getManagement() throws DatabaseException {
59 return driver.getManagement(dbFolder.getAbsolutePath(), null);
61 public Session regSession(long sessionId) throws DatabaseException, IOException {
62 SessionManager sm = SessionManagerSource.getSessionManager();
63 ProCoreServerReference ser = new ProCoreServerReference(dbFolder.toPath());
64 SessionReference ses = new ProCoreSessionReference(ser, sessionId);
65 return sm.createSession(ses, null);