r236 - in trunk/src: main/java/org/nuiton/j2r test/java/org/nuiton/j2r
Author: jcouteau Date: 2010-10-18 11:43:32 +0200 (Mon, 18 Oct 2010) New Revision: 236 Url: http://nuiton.org/repositories/revision/nuiton-j2r/236 Log: Proper test skipping when no R environment present Modified: trunk/src/main/java/org/nuiton/j2r/RProxy.java trunk/src/test/java/org/nuiton/j2r/DataframeTest.java trunk/src/test/java/org/nuiton/j2r/JNITest.java trunk/src/test/java/org/nuiton/j2r/ListTest.java trunk/src/test/java/org/nuiton/j2r/NetTest.java Modified: trunk/src/main/java/org/nuiton/j2r/RProxy.java =================================================================== --- trunk/src/main/java/org/nuiton/j2r/RProxy.java 2010-10-18 09:21:30 UTC (rev 235) +++ trunk/src/main/java/org/nuiton/j2r/RProxy.java 2010-10-18 09:43:32 UTC (rev 236) @@ -669,5 +669,31 @@ engine.plot(filename, x, y, type, main, sub, xlab, ylab, asp); } + /** + * To know if the engine interfaced is a RNetEngine. + * + * @return true if the engine interfaced is a RNetEngine. + */ + public boolean isNet() { + if (engine != null) { + return engine instanceof RNetEngine; + } else { + return false; + } + } + + /** + * To know if the engine interfaced is a RJniEngine. + * + * @return true if the engine interfaced is a RJniEngine. + */ + public boolean isJni() { + if (engine != null) { + return engine instanceof RJniEngine; + } else { + return false; + } + } + } //RProxy Modified: trunk/src/test/java/org/nuiton/j2r/DataframeTest.java =================================================================== --- trunk/src/test/java/org/nuiton/j2r/DataframeTest.java 2010-10-18 09:21:30 UTC (rev 235) +++ trunk/src/test/java/org/nuiton/j2r/DataframeTest.java 2010-10-18 09:43:32 UTC (rev 236) @@ -37,6 +37,7 @@ import org.junit.Assert; import org.junit.Assume; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.j2r.types.RDataFrame; @@ -46,17 +47,23 @@ private REngine engine; - @Before - public void setUp() throws Exception { - if (engine == null) { - try { - engine = new RProxy(); - } catch (RException eee){ - Assume.assumeTrue(false); + @BeforeClass + public static void tryREnv(){ + try { + new RProxy(); + } catch (RException eee) { + if (log.isErrorEnabled()) { + log.error("No R environment found to run tests. Skip"); } + Assume.assumeTrue(false); } } + @Before + public void setUp() throws Exception { + engine = new RProxy(); + } + @After public void tearDown() throws Exception { if (engine != null){ Modified: trunk/src/test/java/org/nuiton/j2r/JNITest.java =================================================================== --- trunk/src/test/java/org/nuiton/j2r/JNITest.java 2010-10-18 09:21:30 UTC (rev 235) +++ trunk/src/test/java/org/nuiton/j2r/JNITest.java 2010-10-18 09:43:32 UTC (rev 236) @@ -41,6 +41,7 @@ import org.junit.Assert; import org.junit.Assume; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.j2r.jni.RJniEngine; import org.nuiton.j2r.types.RDataFrame; @@ -56,6 +57,37 @@ private REngine engine; private String savedRType; + @BeforeClass + public static void tryREnv() { + + RProxy testedEngine = null; + + //Force R.type to net + String savedRType = System.getProperty("R.type", ""); + System.setProperty("R.type", "jni"); + + try { + testedEngine = new RProxy(); + } catch (RException eee) { + if (log.isErrorEnabled()) { + log.error("No R environment found to run tests. Skip"); + } + Assume.assumeTrue(false); + } + + //Restore old R.type + System.setProperty("R.type", savedRType); + + if (testedEngine != null) { + Assume.assumeTrue(testedEngine.isJni()); + if (log.isErrorEnabled()) { + log.error("No JRI environment found. Skip tests."); + } + } + + + } + @Before public void setUp() throws Exception { LutinTimer init = new LutinTimer(); Modified: trunk/src/test/java/org/nuiton/j2r/ListTest.java =================================================================== --- trunk/src/test/java/org/nuiton/j2r/ListTest.java 2010-10-18 09:21:30 UTC (rev 235) +++ trunk/src/test/java/org/nuiton/j2r/ListTest.java 2010-10-18 09:43:32 UTC (rev 236) @@ -31,6 +31,7 @@ import org.junit.Assert; import org.junit.Assume; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.j2r.types.RList; @@ -47,17 +48,23 @@ private REngine engine; - @Before - public void setUp() throws Exception { - if (engine == null) { - try { - engine = new RProxy(); - } catch (RException eee) { - Assume.assumeTrue(false); + @BeforeClass + public static void tryREnv() { + try { + new RProxy(); + } catch (RException eee) { + if (log.isErrorEnabled()) { + log.error("No R environment found to run tests. Skip"); } + Assume.assumeTrue(false); } } + @Before + public void setUp() throws Exception { + engine = new RProxy(); + } + @After public void tearDown() throws Exception { if (engine != null) { Modified: trunk/src/test/java/org/nuiton/j2r/NetTest.java =================================================================== --- trunk/src/test/java/org/nuiton/j2r/NetTest.java 2010-10-18 09:21:30 UTC (rev 235) +++ trunk/src/test/java/org/nuiton/j2r/NetTest.java 2010-10-18 09:43:32 UTC (rev 236) @@ -51,11 +51,11 @@ import org.junit.Assert; import org.junit.Assume; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.j2r.net.RNetEngine; import org.nuiton.j2r.types.RDataFrame; import org.nuiton.j2r.types.RList; -import org.rosuda.REngine.Rserve.RserveException; public class NetTest { @@ -63,6 +63,37 @@ private REngine engine; private String savedRType; + @BeforeClass + public static void tryREnv() { + + RProxy testedEngine= null; + + //Force R.type to net + String savedRType = System.getProperty("R.type", ""); + System.setProperty("R.type", "net://:6311"); + + try { + testedEngine = new RProxy(); + } catch (RException eee) { + if (log.isErrorEnabled()) { + log.error("No R environment found to run tests. Skip"); + } + Assume.assumeTrue(false); + } + + //Restore old R.type + System.setProperty("R.type", savedRType); + + if (testedEngine != null){ + Assume.assumeTrue(testedEngine.isNet()); + if (log.isErrorEnabled()) { + log.error("No Rserve environment found. Skip tests."); + } + } + + + } + @Before public void setUp() throws Exception { LutinTimer init = new LutinTimer();
participants (1)
-
jcouteau@users.nuiton.org