]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java
Fixed typo from string returned from Rename.renameNode
[simantics/platform.git] / bundles / org.simantics.db.testing / src / org / simantics / db / testing / common / TestBase.java
index 574ab95f6ab7a09b876ba7098a5f4027f0a05156..73e6ff8f13b47377064af2f7a2041aefe5da829b 100644 (file)
@@ -20,29 +20,34 @@ import org.eclipse.core.runtime.Platform;
 import org.junit.After;
 import org.junit.Before;
 import org.simantics.SimanticsPlatform;
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.WriteOnlyGraph;
 import org.simantics.db.common.request.WriteOnlyRequest;
-import org.simantics.db.common.utils.Logger;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.ServiceNotFoundException;
 import org.simantics.db.management.SessionContext;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.db.request.AsyncRead;
 import org.simantics.db.request.Read;
 import org.simantics.db.service.LifecycleSupport;
 import org.simantics.db.testing.impl.Configuration;
 import org.simantics.layer0.Layer0;
 import org.simantics.utils.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * Base class for Simantics Test Cases. Assumes that ProCore is already running.
+ * Base class for Simantics Test Cases.
+ * Assumes that the Simantics database is already running.
  *
  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
- *
  */
-abstract public class TestBase /*extends TestCase*/ {
+public abstract class TestBase {
+    private static final Logger LOGGER = LoggerFactory.getLogger(TestBase.class);
     public static final boolean DEBUG = Configuration.get().debug;
     public static final String ROOT_LIBRARY_URI = "http:/";
     private NoExitSecurityManager noExitSecurityManager;
@@ -53,7 +58,7 @@ abstract public class TestBase /*extends TestCase*/ {
     static boolean printStart = true;
     public static final ArrayList<String> initialWorkspaceFiles = FileUtils.createFileFilter(Platform.getLocation().toFile(), null);
     public static void printStart(Object t) {
-        if(printStart) System.out.println("Test is " + t.getClass().getName() /*+ "." + t.getName()*/);
+        if(printStart) LOGGER.info("Test is {}", t.getClass().getName());
     }
     protected static void setPrintStart(boolean value) {
         printStart = value;
@@ -145,9 +150,46 @@ abstract public class TestBase /*extends TestCase*/ {
 
     }
 
+    protected abstract class AsyncReadQuery<Result> implements AsyncRead<Result> {
+        protected Result result = null;
+
+        public abstract void run(AsyncReadGraph graph) throws Throwable;
+
+        @Override
+        public void perform(AsyncReadGraph graph, AsyncProcedure<Result> procedure) {
+            try {
+                run(graph);
+            } catch(Throwable t) {
+                if (DEBUG) {
+                    new Exception().printStackTrace();
+                    t.printStackTrace();
+                }
+                if (null == exception2)
+                    exception2 = t;
+            }
+        }
+
+    }
+
     protected abstract class TestReadRequest extends ReadQuery<Object> {
     }
 
+    protected abstract class TestAsyncReadRequest extends AsyncReadQuery<Object> {
+
+               @Override
+               public int getFlags() {
+                       // TODO Auto-generated method stub
+                       return 0;
+               }
+
+               @Override
+               public int threadHash() {
+                       // TODO Auto-generated method stub
+                       return 0;
+               }
+
+    }
+
     protected abstract class WriteOnlyQuery
     extends WriteOnlyRequest
     {
@@ -230,9 +272,9 @@ abstract public class TestBase /*extends TestCase*/ {
                 try {
                     session.getService(LifecycleSupport.class).close(0, true);
                 } catch (ServiceNotFoundException e) {
-                    Logger.defaultLogError(e);
+                    LOGGER.error("Failed to find LifecycleSupport service", e);
                 } catch (DatabaseException e) {
-                    Logger.defaultLogError(e);
+                    LOGGER.error("Failed to close database", e);
                 }
             }
 //            if (!Thread.currentThread().equals(thread)) {