diff --git a/iris-common/src/test/java/cfa/vo/iris/test/unit/it/AbstractSAMPTest.java b/iris-common/src/test/java/cfa/vo/iris/test/unit/it/AbstractSAMPTest.java index 7eeedaeb..e6a6fd7c 100644 --- a/iris-common/src/test/java/cfa/vo/iris/test/unit/it/AbstractSAMPTest.java +++ b/iris-common/src/test/java/cfa/vo/iris/test/unit/it/AbstractSAMPTest.java @@ -18,6 +18,7 @@ import cfa.vo.interop.SAMPController; import cfa.vo.sherpa.SherpaClient; +import java.util.logging.Logger; import org.astrogrid.samp.client.SampException; import org.junit.After; import static org.junit.Assert.*; @@ -31,22 +32,43 @@ */ public class AbstractSAMPTest { + private final Logger logger = Logger.getLogger(AbstractSAMPTest.class.getName()); + + private final int SAMP_CONN_RETRIES = 3; + protected SAMPController controller; private int TIMEOUT; private String controller_name; protected SherpaClient client; public AbstractSAMPTest() { - this.TIMEOUT = 5; - this.controller_name = "Iris Component"; + this.controller_name = "Iris Test Controller"; } public AbstractSAMPTest(int timeout, String controller_name) { - this.TIMEOUT = timeout; this.controller_name = controller_name; } +// /** +// * This rule allows the component loader to be initialized only once for the whole suite. +// * This works around the fact that @BeforeClass and @AfterClass methods need to be static. +// */ +// @Rule +// public ExternalResource resource = new ExternalResource() { +// @Override +// protected void before() throws Exception { +// // asserts that the SAMP Hub is up, and that sherpa-samp is connected. +// connectToSAMPHub(); +// isSherpaConnected(); +// } +// @Override +// protected void after() { +// // disconnect controller +// controller.stop(); +// } +// }; + // forces the concrete classes to make their own before class, and it will // not override this Before class @Before @@ -76,24 +98,22 @@ public void connectToSAMPHub() throws InterruptedException, Exception { // If the controller doesn't connect after 2 seconds, add additional // wait time. - int time = 0; - while (!controller.isConnected()) { - time += TIMEOUT*1000; - Thread.sleep(time); - - // If the controller doesn't connect within the additional time, - // fail. - if (time >= TIMEOUT*1000) { - fail("Could not connect to SAMP Hub."); - } - } - assertTrue(controller.isConnected()); + int count = 0; + while (!controller.isConnected()) { + if (++count > SAMP_CONN_RETRIES) { + String msg = "Failed to connect to SAMP, failing Unit tests"; + logger.info(msg); + fail(msg); + } + logger.info("waiting connection"); + Thread.sleep(1000); + } + assertTrue(controller.isConnected()); } public void isSherpaConnected() throws SampException { - - this.client = new SherpaClient(this.controller); - assertTrue(!this.client.findSherpa().isEmpty()); + this.client = SherpaClient.create(controller); + assertTrue(SherpaClient.ping(controller)); } } diff --git a/sed-builder/src/test/java/cfa/vo/sed/science/interpolation/SherpaRedshifterTest.java b/sed-builder/src/test/java/cfa/vo/sed/science/interpolation/SherpaRedshifterIT.java similarity index 92% rename from sed-builder/src/test/java/cfa/vo/sed/science/interpolation/SherpaRedshifterTest.java rename to sed-builder/src/test/java/cfa/vo/sed/science/interpolation/SherpaRedshifterIT.java index daed8204..854b67c4 100644 --- a/sed-builder/src/test/java/cfa/vo/sed/science/interpolation/SherpaRedshifterTest.java +++ b/sed-builder/src/test/java/cfa/vo/sed/science/interpolation/SherpaRedshifterIT.java @@ -22,11 +22,12 @@ package cfa.vo.sed.science.interpolation; -import cfa.vo.interop.SAMPController; import cfa.vo.interop.SAMPFactory; import cfa.vo.interop.SAMPMessage; import cfa.vo.iris.interop.SedSAMPController; import cfa.vo.sherpa.SherpaClient; +import cfa.vo.iris.test.unit.it.AbstractSAMPTest; + import java.util.logging.Logger; import org.astrogrid.samp.Response; import org.junit.After; @@ -40,23 +41,21 @@ * * @author jbudynk */ -public class SherpaRedshifterTest { +public class SherpaRedshifterIT extends AbstractSAMPTest { - private static final Logger logger = Logger.getLogger(SherpaRedshifterTest.class.getName()); - - private SAMPController controller; + private static final Logger logger = Logger.getLogger(SherpaRedshifterIT.class.getName()); private static String REDSHIFT_MTYPE = "spectrum.redshift.calc"; - public SherpaRedshifterTest() { + public SherpaRedshifterIT() { } @Before - public void setUp() { + public void setup() { } @After - public void tearDown() { + public void teardown() { } @Ignore("need sherpa-samp running") @@ -79,7 +78,6 @@ public void testShift() throws Exception { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - // Start the SAMP controller controller = SedSAMPController.createAndStart("SEDStacker", "SEDStacker", this.getClass().getResource("/tools_tiny.png"), false, false); @@ -95,22 +93,15 @@ public void testShift() throws Exception { SherpaClient client = SherpaClient.create(controller); Response rspns = client.sendMessage(message); - RedshiftPayload response = (RedshiftPayload) SAMPFactory.get(rspns.getResult(), RedshiftPayload.class); double[] controlYerr = new double[]{ 1, 21, 11, 2, 22, 12, 3, 23, 13, 4, 24, 14, 25, 15, 5, 16, 6, 26, 17, 7, 27, 18, 8, 28, 29, 19, 9, 20, 10, 30 }; - // tests // Make sure flux errors are sorted correctly with the SED points. for (int i = 0; i < response.getY().length; i++) { assertEquals(controlYerr[i], response.getYerr()[i], 0.00001); } - - controller.stop(); - } - - } diff --git a/sed-builder/src/test/java/cfa/vo/sed/science/stacker/AbstracSEDStackerIT.java b/sed-builder/src/test/java/cfa/vo/sed/science/stacker/AbstracSEDStackerIT.java index 15480270..9a3cf71f 100644 --- a/sed-builder/src/test/java/cfa/vo/sed/science/stacker/AbstracSEDStackerIT.java +++ b/sed-builder/src/test/java/cfa/vo/sed/science/stacker/AbstracSEDStackerIT.java @@ -12,6 +12,7 @@ import cfa.vo.interop.SAMPFactory; import cfa.vo.iris.interop.SedSAMPController; import org.uispec4j.UISpec4J; +import cfa.vo.iris.test.unit.it.AbstractSAMPTest; /** * Abstract class for integration testing of SAMP integration. Tests will fail if they are @@ -33,6 +34,7 @@ public abstract class AbstracSEDStackerIT { } private static final Logger logger = Logger.getLogger(AbstracSEDStackerIT.class.getName()); + protected static final double EPSILON = 0.00001; protected double[] x1; @@ -62,7 +64,7 @@ public static void afterClass() throws Exception { } @Before - public void setUp() throws Exception { + public void setup() throws Exception { initVariables(); } diff --git a/sed-builder/src/test/java/cfa/vo/sed/science/stacker/SedStackerNormalizerIT.java b/sed-builder/src/test/java/cfa/vo/sed/science/stacker/SedStackerNormalizerIT.java index 637247b6..38dbcd61 100644 --- a/sed-builder/src/test/java/cfa/vo/sed/science/stacker/SedStackerNormalizerIT.java +++ b/sed-builder/src/test/java/cfa/vo/sed/science/stacker/SedStackerNormalizerIT.java @@ -22,6 +22,7 @@ import cfa.vo.iris.utils.Default; import cfa.vo.iris.utils.UTYPE; import cfa.vo.sedlib.Segment; + import java.util.ArrayList; import java.util.List; import org.astrogrid.samp.Response;