package compbio.ws.server; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.net.ConnectException; import java.util.Arrays; import java.util.List; import java.util.Set; import javax.xml.ws.WebServiceException; import org.testng.annotations.Test; import compbio.data.msa.MsaWS; import compbio.data.sequence.FastaSequence; import compbio.data.sequence.SequenceUtil; import compbio.metadata.AllTestSuit; import compbio.metadata.ChunkHolder; import compbio.metadata.JobStatus; import compbio.metadata.JobSubmissionException; import compbio.metadata.ResultNotAvailableException; import compbio.ws.client.Jws2Client; import compbio.ws.client.Services; import compbio.ws.client.WSTesterTester; public class RegistryWSTester { @Test(groups = {AllTestSuit.test_group_webservices, AllTestSuit.test_group_windows_only}) public void testGetSupportedServices() { try { compbio.data.msa.RegistryWS reg = Jws2Client .connectToRegistry(WSTesterTester.SERVER); System.out.println(reg.getSupportedServices()); Set supserv = reg.getSupportedServices(); assertTrue(supserv.containsAll(Arrays.asList(new Services[]{ Services.AAConWS, Services.ClustalOWS, Services.IUPredWS, Services.MuscleWS, Services.ClustalWS, Services.JronnWS}))); } catch (ConnectException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (WebServiceException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } } @Test(groups = {AllTestSuit.test_group_webservices}) public void testTestService() { compbio.data.msa.RegistryWS reg = null; try { reg = Jws2Client.connectToRegistry(WSTesterTester.SERVER); assertNotNull(reg.testService(Services.AAConWS)); } catch (ConnectException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (WebServiceException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } } @Test(dependsOnMethods = {"testTestService"}, groups = {AllTestSuit.test_group_webservices}) public void testIsOperating() { try { compbio.data.msa.RegistryWS reg = Jws2Client .connectToRegistry(WSTesterTester.SERVER); assertTrue(reg.isOperating(Services.AAConWS)); } catch (ConnectException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (WebServiceException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } } @Test(dependsOnMethods = {"testTestService"}, groups = {AllTestSuit.test_group_webservices}) public void testGetLastTestedOn() { try { compbio.data.msa.RegistryWS reg = Jws2Client .connectToRegistry(WSTesterTester.SERVER); assertNotNull(reg.getLastTestedOn(Services.AAConWS)); } catch (ConnectException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (WebServiceException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } } @Test(dependsOnMethods = {"testTestService"}, groups = {AllTestSuit.test_group_webservices}) public void testGetLastTested() { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); fail(e.getMessage()); } try { compbio.data.msa.RegistryWS reg = Jws2Client .connectToRegistry(WSTesterTester.SERVER); System.out.println(reg.getLastTested(Services.AAConWS)); assertTrue(reg.getLastTested(Services.AAConWS) > 0); } catch (ConnectException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (WebServiceException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } } @Test(groups = {AllTestSuit.test_group_webservices}) public void testTestAllServices() { try { compbio.data.msa.RegistryWS reg = Jws2Client .connectToRegistry(WSTesterTester.SERVER); System.out.println(reg.testAllServices()); } catch (ConnectException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (WebServiceException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } } @Test(groups = {AllTestSuit.test_group_webservices}) public void testProgressReporting() { MsaWS service = null; try { service = (MsaWS) Jws2Client.connect( "http://www.compbio.dundee.ac.uk/jabaws", // "http://webserv1.cluster.lifesci.dundee.ac.uk:8089/jabaws", Services.ProbconsWS); File input = new File(AllTestSuit.TEST_DATA_PATH_ABSOLUTE + "200x500Protein.fasta"); assertTrue(input.exists()); List fs = SequenceUtil .readFasta(new FileInputStream(input)); String jobId = service.align(fs); Thread.sleep(5000); ChunkHolder pos = null; while (service.getJobStatus(jobId) == JobStatus.RUNNING) { if (pos == null) { pos = service.pullExecStatistics(jobId, 0); } else { pos = service.pullExecStatistics(jobId, pos.getNextPosition()); } Thread.sleep(10); System.out.print(pos.getChunk()); } System.out.println(); System.out.println(service.getResult(jobId)); } catch (ConnectException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (WebServiceException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (ResultNotAvailableException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (FileNotFoundException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (IOException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (JobSubmissionException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (InterruptedException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } } @Test(groups = {AllTestSuit.test_group_webservices}) public void testPullRunningJob() { MsaWS service = null; try { service = (MsaWS) Jws2Client.connect( "http://webserv1.cluster.lifesci.dundee.ac.uk:8089/jabaws", Services.ProbconsWS); String jobId = "@Probcons#158079030012566"; ChunkHolder pos = null; while (service.getJobStatus(jobId) == JobStatus.RUNNING) { if (pos == null) { pos = service.pullExecStatistics(jobId, 0); } else { pos = service.pullExecStatistics(jobId, pos.getNextPosition()); } Thread.sleep(10); System.out.print(pos.getChunk()); } System.out.println(); System.out.println(service.getResult(jobId)); } catch (ConnectException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (WebServiceException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (ResultNotAvailableException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } catch (InterruptedException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } } }