]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Tests.java
Fixing problems in the database unit testing environment with Acorn
[simantics/platform.git] / bundles / org.simantics.db.testing / src / org / simantics / db / testing / common / Tests.java
index 311360cdcb97b6638eb516b8566ba3c1e78ae8ad..2848aabe1f2279faea903839dce4501c2a5ffdea 100644 (file)
@@ -21,7 +21,6 @@ import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.Statement;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.util.RuntimeEnvironmentRequest;
 import org.simantics.db.management.ISessionContextProvider;
 import org.simantics.db.management.ISessionContextProviderSource;
 import org.simantics.db.management.SessionContext;
@@ -34,7 +33,9 @@ import org.simantics.graph.representation.TransferableGraph1;
 import org.simantics.scl.osgi.SCLOsgi;
 
 public class Tests {
-    private static TestHandler testHandler;
+
+    private static AcornTestHandler testHandler;
+
     public static boolean contains(Collection<Statement> stms, Resource predicate, Resource object) {
         for(Statement stm : stms) {
             if(stm.getPredicate().equals(predicate) && stm.getObject().equals(object)) return true;
@@ -48,17 +49,21 @@ public class Tests {
         }
         return false;
     }
+
     public static DatabaseState freshWorkspace(String CORE_DIR, ArrayList<String> fileFilter) throws Exception {
         SimanticsPlatform.INSTANCE.resetWorkspace(null, fileFilter);
         return newSimanticsWorkspace(null, CORE_DIR);
     }
+
     public static void freshDatabase() throws Exception {
         DatabaseState state = freshWorkspace(Configuration.get().coreDir, null);
-        Tests.shutdown(state);
+        shutdown(state);
     }
+
     public static DatabaseState existingDatabase() throws Exception {
         return oldSimanticsWorkspace(null, Configuration.get().coreDir);
     }
+
     private static void initSimanticsStuff() {
         // Set session context provider.
         final ISessionContextProvider provider = new SessionContextProvider(null);
@@ -66,76 +71,28 @@ public class Tests {
         Simantics.setSessionContextProviderSource(source);
         org.simantics.db.layer0.internal.SimanticsInternal.setSessionContextProviderSource(source);
     }
+
     public static DatabaseState newSimanticsWorkspace(TestSettings testSettings, String address) throws Exception {
-        TestHandler testHandler = Tests.getTestHandler(testSettings, address);
+        AcornTestHandler testHandler = getTestHandler(testSettings, address);
         testHandler.initNew();
         initSimanticsStuff();
         SessionContext sessionContext = SimanticsPlatform.INSTANCE.startUp(Simantics.getDefaultDatabaseDriver(), null, RecoveryPolicy.FixError, OntologyRecoveryPolicy.Merge, true, new DefaultChoiceUserAgent());
-       return new DatabaseState(address, sessionContext);
+        return new DatabaseState(address, sessionContext);
     }
+
     public static DatabaseState oldSimanticsWorkspace(TestSettings testSettings, String address) throws Exception {
-        Tests.getTestHandler(testSettings, address);
+        getTestHandler(testSettings, address);
         initSimanticsStuff();
         SessionContext sessionContext = SimanticsPlatform.INSTANCE.startUp(Simantics.getDefaultDatabaseDriver(), null, RecoveryPolicy.FixError, OntologyRecoveryPolicy.Merge, false, null);
         return new DatabaseState(address, sessionContext);
     }
-//        for (String ontology : testSettings.getOntologies()) {
-//            initOntology(session, ontology);
-//        }
-//        String[] adapters = testSettings.getAdapters();
-//        if(adapters != null) {
-//            File[] files = new File[adapters.length];
-//            for(int i=0;i<adapters.length;i++)
-//                files[i] = new File(testSettings.getWorkspace(), adapters[i]);
-//            System.err.println("Loading adapters: " + Arrays.toString(files));
-//            AdapterRegistry2.getInstance().initialize(testSettings.getClass().getClassLoader(), null, files);
-//            new AdaptionServiceInitializer().initialize(session);
-//        }
-//        return new DatabaseState(testHandler.getServer(), SessionContext.create(session, false));
-//    }
-//    @SuppressWarnings("deprecation")
-//    private static DatabaseState initPlatform(TestHandler testHandler, boolean fresh) throws Exception {
-//            // Starts database server.
-//            SimanticsPlatform.INSTANCE.startUpExisting(null, RecoveryPolicy.ThrowError, true);
-//            return new DatabaseState(SimanticsPlatform.INSTANCE.server, SimanticsPlatform.INSTANCE.sessionContext);
-//        }
-//    }
-//    private static DatabaseState initDatabase(TestHandler testHandler, boolean fresh) throws DatabaseException {
-//        TestSettings settings = TestSettings.getInstance();
-//        if (fresh)
-//            testHandler.initNew();
-//        else
-//            testHandler.initOld();
-//        Session session = testHandler.getSession();
-//        if (fresh) {
-//            for(String ontology : settings.getOntologies()) {
-//                initOntology(session, ontology);
-//            }
-//        }
-//        String[] adapters = settings.getAdapters();
-//        if(adapters != null) {
-//            File[] files = new File[adapters.length];
-//            for(int i=0;i<adapters.length;i++)
-//                files[i] = new File(settings.getWorkspace(), adapters[i]);
-//            System.err.println("Loading adapters: " + Arrays.toString(files));
-//            AdapterRegistry2.getInstance().initialize(settings.getClass().getClassLoader(), null, files);
-//            new AdaptionServiceInitializer().initialize(session);
-//        }
-//        return new DatabaseState(testHandler.getServer(), SessionContext.create(session, false));
-//    }
-//    private static DatabaseState initDatabaseDep(TestHandler testHandler, boolean fresh) throws Exception {
-//        if (Platform.isRunning())
-//            return initPlatform(testHandler, fresh);
-//        else
-//            return initDatabase(testHandler, fresh);
-//    }
     public static void shutdown(DatabaseState state) throws Exception {
         if (SCLOsgi.MODULE_REPOSITORY != null)
             SCLOsgi.MODULE_REPOSITORY.flush();
         SCLOsgi.SOURCE_REPOSITORY = null;
         SCLOsgi.MODULE_REPOSITORY = null;
         SCLOsgi.TEST_REPOSITORY = null;
-        
+
         if (Platform.isRunning()) {
             SimanticsPlatform.INSTANCE.shutdown(null);
             return;
@@ -151,8 +108,7 @@ public class Tests {
         }
     }
 
-    public static void initOntology(Session session, String relative)
-    throws DatabaseException {
+    public static void initOntology(Session session, String relative) throws DatabaseException {
         // Open transferable graph file for layer0.
         Binding binding;
         try {
@@ -183,14 +139,17 @@ public class Tests {
 //    public static TestHandler newTestHandler(TestSettings testSettings, String dbFolderName) throws DatabaseException {
 //        return new TestHandler(testSettings, dbFolderName);
 //    }
-    public static TestHandler getTestHandler() throws DatabaseException {
+
+    public static AcornTestHandler getTestHandler() throws DatabaseException {
         return getTestHandler(null, null);
     }
-    public static TestHandler getTestHandler(TestSettings testSettings, String address) throws DatabaseException {
+
+    public static AcornTestHandler getTestHandler(TestSettings testSettings, String address) throws DatabaseException {
         if (null == testHandler)
-            testHandler = new TestHandler(testSettings, address);
+            testHandler = new AcornTestHandler(testSettings, address);
         return testHandler;
     }
+
     public static void closeSession(Session session) throws DatabaseException {
         try {
             LifecycleSupport support = session.getService(LifecycleSupport.class);
@@ -198,10 +157,11 @@ public class Tests {
             session = null;
         } catch (Exception e) {
             session = null;
-            throw new DatabaseException("Sessuion did not close cleanly.");
+            throw new DatabaseException("Session did not close cleanly.");
         }
     }
-    public static void killCore() throws DatabaseException {
 
+    public static void killCore() throws DatabaseException {
     }
+
 }