Skip to content

Commit

Permalink
Updated AbstractSAMPTest with inputs from #195. Extends existing sed-…
Browse files Browse the repository at this point in the history
…builder IT tests from it.
  • Loading branch information
jbudynk authored and Erik H committed Dec 2, 2015
1 parent 4194aae commit 8dd9023
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand All @@ -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);

Expand All @@ -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();

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -62,7 +64,7 @@ public static void afterClass() throws Exception {
}

@Before
public void setUp() throws Exception {
public void setup() throws Exception {
initVariables();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8dd9023

Please sign in to comment.