From 033af56216900fb4bee63487391b92a1fc28ef7f Mon Sep 17 00:00:00 2001
From: pkupczyk <piotr.kupczyk@id.ethz.ch>
Date: Wed, 27 Mar 2024 15:58:30 +0100
Subject: [PATCH] SSDM-13578 : 2PT : Database and V3 Implementation - js facade

---
 .../suite/common/JsTestCommonSelenium.java    |  6 +-
 .../test/server/TestApplicationServer.java    | 88 ++++---------------
 .../test/server/TestDataStoreServer.java      |  2 +-
 3 files changed, 24 insertions(+), 72 deletions(-)

diff --git a/test-api-openbis-javascript/source/java/ch/systemsx/cisd/openbis/jstest/suite/common/JsTestCommonSelenium.java b/test-api-openbis-javascript/source/java/ch/systemsx/cisd/openbis/jstest/suite/common/JsTestCommonSelenium.java
index 6693486214d..048790ab75c 100644
--- a/test-api-openbis-javascript/source/java/ch/systemsx/cisd/openbis/jstest/suite/common/JsTestCommonSelenium.java
+++ b/test-api-openbis-javascript/source/java/ch/systemsx/cisd/openbis/jstest/suite/common/JsTestCommonSelenium.java
@@ -77,8 +77,6 @@ public class JsTestCommonSelenium extends SeleniumTest
 
     @BeforeSuite @Override public void initialization() throws Exception
     {
-        System.setProperty("log4j.configuration", "etc/log.xml");
-        System.setProperty("log4j.configurationFile", "etc/log.xml");
         super.initialization();
         startAfsServer();
     }
@@ -86,6 +84,10 @@ public class JsTestCommonSelenium extends SeleniumTest
     @Override
     protected String startApplicationServer() throws Exception
     {
+        File configurationFile = new File("etc/log4j1.xml");
+        System.setProperty("log4j.configuration", configurationFile.getAbsolutePath());
+        System.setProperty("log4j.configurationFile", configurationFile.getAbsolutePath());
+
         JsTestCommonApplicationServer as = new JsTestCommonApplicationServer();
         as.setDeamon(true);
         String result = as.start();
diff --git a/test-api-openbis-javascript/source/java/ch/systemsx/cisd/openbis/test/server/TestApplicationServer.java b/test-api-openbis-javascript/source/java/ch/systemsx/cisd/openbis/test/server/TestApplicationServer.java
index 0927d027405..378d7b22b50 100644
--- a/test-api-openbis-javascript/source/java/ch/systemsx/cisd/openbis/test/server/TestApplicationServer.java
+++ b/test-api-openbis-javascript/source/java/ch/systemsx/cisd/openbis/test/server/TestApplicationServer.java
@@ -15,12 +15,7 @@
  */
 package ch.systemsx.cisd.openbis.test.server;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.InputStreamReader;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-import java.io.PrintStream;
 
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker;
@@ -48,73 +43,28 @@ public class TestApplicationServer
     {
         TestDatabase.restoreDumps(getDumpsPath());
 
-        Runnable r = new Runnable()
-            {
-                @SuppressWarnings({ "unchecked", "rawtypes" })
-                @Override
-                public void run()
-                {
-                    Server server = new Server(getPort());
-
-                    WebAppContext context = new WebAppContext();
-
-                    File war = new File("../../../targets/gradle/openbis-war/openbis.war");
-                    if (war.exists())
-                    {
-                        context.setWar(war.getAbsolutePath());
-                        context.setExtractWAR(true);
-                        context.setTempDirectory(new File(System.getProperty("jetty.home") + "/webapps"));
-                        context.addAliasCheck(new AllowSymLinkAliasChecker());
-                    } else
-                    {
-                        context.setDescriptor(getWebXmlPath());
-                        context.setResourceBase(getRootPath());
-                    }
-                    context.setContextPath(getContextPath());
-                    context.setParentLoaderPriority(true);
-
-                    server.setHandler(context);
-
-                    try
-                    {
-                        server.start();
-                        server.join();
-                    } catch (Exception ex)
-                    {
-                        ex.printStackTrace();
-                    }
-                }
-            };
-
-        PrintStream originalOut = System.out;
-
-        PipedOutputStream outpipe = new PipedOutputStream();
-        PipedInputStream inpipe = new PipedInputStream(outpipe);
-        BufferedReader reader = new BufferedReader(new InputStreamReader(inpipe));
-        PrintStream newOut = new PrintStream(outpipe);
-        System.setOut(newOut);
-
-        Thread t = new Thread(r);
-        t.setDaemon(true);
-        t.start();
-
-        String line;
-        while ((line = reader.readLine()) != null)
-        {
-            originalOut.println(line);
+        Server server = new Server(getPort());
+
+        WebAppContext context = new WebAppContext();
 
-            if (line.contains("SERVER STARTED"))
-            {
-                originalOut.println("SERVER START DETECTED");
-                break;
-            }
+        File war = new File("../../../targets/gradle/openbis-war/openbis.war");
+        if (war.exists())
+        {
+            context.setWar(war.getAbsolutePath());
+            context.setExtractWAR(true);
+            context.setTempDirectory(new File(System.getProperty("jetty.home") + "/webapps"));
+            context.addAliasCheck(new AllowSymLinkAliasChecker());
+        } else
+        {
+            context.setDescriptor(getWebXmlPath());
+            context.setResourceBase(getRootPath());
         }
-        outpipe.close();
-        inpipe.close();
-        reader.close();
-        newOut.close();
+        context.setContextPath(getContextPath());
+        context.setParentLoaderPriority(true);
+
+        server.setHandler(context);
 
-        System.setOut(originalOut);
+        server.start();
 
         return "http://localhost:" + getPort();
     }
diff --git a/test-api-openbis-javascript/source/java/ch/systemsx/cisd/openbis/test/server/TestDataStoreServer.java b/test-api-openbis-javascript/source/java/ch/systemsx/cisd/openbis/test/server/TestDataStoreServer.java
index 76b6f3da678..ffb221b1508 100644
--- a/test-api-openbis-javascript/source/java/ch/systemsx/cisd/openbis/test/server/TestDataStoreServer.java
+++ b/test-api-openbis-javascript/source/java/ch/systemsx/cisd/openbis/test/server/TestDataStoreServer.java
@@ -61,7 +61,7 @@ public abstract class TestDataStoreServer
                 @Override
                 public void newLine(String line)
                 {
-                    System.out.println("DATA STORE " + getName() + ": " + line);
+                    System.out.println("[" + getName() + "] " + line);
                 }
             });
         LogLineReader reader = new LogLineReader();
-- 
GitLab