2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.testng.Assert.assertNotNull;
25 import java.io.BufferedReader;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29 import java.util.concurrent.TimeUnit;
31 import org.testng.Assert;
32 import org.testng.annotations.BeforeTest;
33 import org.testng.annotations.Test;
35 import io.github.classgraph.ClassGraph;
36 import io.github.classgraph.ScanResult;
37 import jalview.bin.Console;
39 public class Log4jTest
41 private static final int TIMEOUT = 10;
43 private static class Worker extends Thread
45 private final Process process;
47 private BufferedReader outputReader;
49 private BufferedReader errorReader;
51 private boolean exited;
53 private Worker(Process process)
55 this.process = process;
63 exited = process.waitFor(TIMEOUT, TimeUnit.SECONDS);
64 } catch (InterruptedException ignore)
69 this.process.destroy();
72 public BufferedReader getOutputReader()
77 public void setOutputReader(BufferedReader outputReader)
79 this.outputReader = outputReader;
82 public BufferedReader getErrorReader()
87 public void setErrorReader(BufferedReader errorReader)
89 this.errorReader = errorReader;
93 private static ClassGraph scanner = null;
95 private static String classpath = null;
97 private static String java_exe = null;
99 public synchronized static String getClassPath()
103 scanner = new ClassGraph();
104 ScanResult scan = scanner.scan();
105 classpath = scan.getClasspath();
106 java_exe = System.getProperty("java.home") + File.separator + "bin"
107 + File.separator + "java";
110 while (classpath == null)
115 } catch (InterruptedException x)
123 private Worker getJalviewDesktopRunner(String appArgs)
125 String classpath = getClassPath();
126 String cmd = java_exe + " " + " -classpath " + classpath + " "
127 + " jalview.bin.Jalview " + " "
128 + "-props test/jalview/util/log4jTestProps.jvprops " + appArgs;
130 Worker worker = null;
133 proc = Runtime.getRuntime().exec(cmd);
134 } catch (Throwable e)
140 BufferedReader outputReader = new BufferedReader(
141 new InputStreamReader(proc.getInputStream()));
142 BufferedReader errorReader = new BufferedReader(
143 new InputStreamReader(proc.getErrorStream()));
144 worker = new Worker(proc);
146 worker.setOutputReader(outputReader);
147 worker.setErrorReader(errorReader);
152 @BeforeTest(alwaysRun = true)
153 public void initialize()
158 @Test(groups = { "Functional" })
159 public void testLog4j()
161 String appArgs = " -open examples/uniref50.fa -nosplash -nonews -noquestionnaire -nousagestats -nowebservicediscovery";
163 Worker worker = getJalviewDesktopRunner(appArgs);
164 assertNotNull(worker, "worker is null");
168 boolean logTestFound = false;
171 while ((ln = worker.getErrorReader().readLine()) != null)
177 if (ln.contains(Console.LOGGING_TEST_MESSAGE))
183 } catch (IOException e)
187 if (worker != null && worker.exited == false)
190 worker.process.destroy();
194 Assert.fail("Did not find Log4j Test message line '"
195 + Console.LOGGING_TEST_MESSAGE + "'");