*/
package jalview.ws.sifts;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
import jalview.api.DBRefEntryI;
import jalview.bin.Cache;
import jalview.datamodel.DBRefEntry;
}
@BeforeTest(alwaysRun = true)
- public void setUpSiftsClient() throws SiftsException
+ public void setUpSiftsClient() throws SiftsException, IOException
{
// read test props before manipulating config
Cache.loadProperties("test/jalview/io/testProps.jvprops");
SiftsSettings.setCacheThresholdInDays("2");
SiftsSettings.setFailSafePIDThreshold("70");
PDBfile pdbFile;
- try
- {
- pdbFile = new PDBfile(false, false, false, "test/jalview/io/"
- + testPDBId + ".pdb", DataSourceType.FILE);
- siftsClient = new SiftsClient(pdbFile);
- } catch (Exception e)
- {
- e.printStackTrace();
- }
+ pdbFile = new PDBfile(false, false, false, "test/jalview/io/"
+ + testPDBId + ".pdb", DataSourceType.FILE);
+ siftsClient = new SiftsClient(pdbFile);
}
@AfterTest(alwaysRun = true)
siftsClient = null;
}
- @Test(groups = { "Functional" })
- public void getSIFTsFileTest() throws SiftsException
+ @Test(groups = { "Network" })
+ public void getSIFTsFileTest() throws SiftsException, IOException
{
File siftsFile;
- try
- {
- siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
- FileAssert.assertFile(siftsFile);
- // test for SIFTs file caching
- SiftsSettings.setCacheThresholdInDays("0");
- siftsFile = SiftsClient.getSiftsFile(testPDBId);
- FileAssert.assertFile(siftsFile);
- SiftsSettings.setCacheThresholdInDays("2");
- } catch (IOException e)
+ siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
+ FileAssert.assertFile(siftsFile);
+ long t1 = siftsFile.lastModified();
+
+ // re-read file should be returned from cache
+ siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
+ FileAssert.assertFile(siftsFile);
+ long t2 = siftsFile.lastModified();
+ assertEquals(t1, t2);
+
+ /*
+ * force fetch by having 0 expiry of cache
+ * also wait one second, because file timestamp does not
+ * give millisecond resolution :-(
+ */
+ synchronized (this)
{
- e.printStackTrace();
+ try
+ {
+ wait(1000);
+ } catch (InterruptedException e)
+ {
+ }
}
+ SiftsSettings.setCacheThresholdInDays("0");
+ siftsFile = SiftsClient.getSiftsFile(testPDBId);
+ FileAssert.assertFile(siftsFile);
+ long t3 = siftsFile.lastModified();
+ assertTrue(t3 > t2, "file timestamp unchanged at " + t3);
+
+ SiftsSettings.setCacheThresholdInDays("2");
}
- @Test(groups = { "Functional" })
- public void downloadSiftsFileTest() throws SiftsException
+ @Test(groups = { "Network" })
+ public void downloadSiftsFileTest() throws SiftsException, IOException
{
// Assert that file isn't yet downloaded - if already downloaded, assert it
// is deleted
Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId));
File siftsFile;
- try
- {
- siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
- FileAssert.assertFile(siftsFile);
- SiftsClient.downloadSiftsFile(testPDBId);
- } catch (IOException e)
- {
- e.printStackTrace();
- }
+ siftsFile = SiftsClient.downloadSiftsFile(testPDBId);
+ FileAssert.assertFile(siftsFile);
+ SiftsClient.downloadSiftsFile(testPDBId);
}
- @Test(groups = { "Functional" })
+ @Test(groups = { "Network" })
public void getAllMappingAccessionTest()
{
Assert.assertNotNull(siftsClient);
Assert.assertTrue(siftsClient.getAllMappingAccession().size() > 1);
}
- @Test(groups = { "Functional" })
+ @Test(groups = { "Network" })
public void getGreedyMappingTest()
{
Assert.assertNotNull(siftsClient);
}
}
- @Test(groups = { "Functional" })
+ @Test(groups = { "Network" })
private void getAtomIndexTest()
{
ArrayList<Atom> atoms = new ArrayList<Atom>();
}
@Test(
- groups = { "Functional" },
+ groups = { "Network" },
expectedExceptions = IllegalArgumentException.class)
private void getAtomIndexNullTest()
{
siftsClient.getAtomIndex(1, null);
}
- @Test(groups = { "Functional" })
+ @Test(groups = { "Network" })
private void padWithGapsTest()
{
}
@Test(
- groups = { "Functional" },
+groups = { "Network" },
expectedExceptions = SiftsException.class)
private void populateAtomPositionsNullTest1()
throws IllegalArgumentException, SiftsException
}
@Test(
- groups = { "Functional" },
+groups = { "Network" },
expectedExceptions = SiftsException.class)
private void populateAtomPositionsNullTest2()
throws IllegalArgumentException, SiftsException
siftsClient.populateAtomPositions("A", null);
}
- @Test(groups = { "Functional" })
- public void getValidSourceDBRefTest()
+ @Test(groups = { "Network" })
+ public void getValidSourceDBRefTest() throws SiftsException
{
- try
- {
- DBRefEntryI actualValidSrcDBRef = siftsClient
- .getValidSourceDBRef(testSeq);
- DBRefEntryI expectedDBRef = new DBRefEntry();
- expectedDBRef.setSource(DBRefSource.UNIPROT);
- expectedDBRef.setAccessionId("P00221");
- expectedDBRef.setVersion("");
- Assert.assertEquals(actualValidSrcDBRef, expectedDBRef);
- } catch (Exception e)
- {
- }
+ DBRefEntryI actualValidSrcDBRef = siftsClient
+ .getValidSourceDBRef(testSeq);
+ DBRefEntryI expectedDBRef = new DBRefEntry();
+ expectedDBRef.setSource(DBRefSource.UNIPROT);
+ expectedDBRef.setAccessionId("P00221");
+ expectedDBRef.setVersion("");
+ Assert.assertEquals(actualValidSrcDBRef, expectedDBRef);
}
@Test(
- groups = { "Functional" },
+groups = { "Network" },
expectedExceptions = SiftsException.class)
public void getValidSourceDBRefExceptionTest() throws SiftsException
{
SequenceI invalidTestSeq = new Sequence("testSeq", "ABCDEFGH");
- try
- {
- siftsClient.getValidSourceDBRef(invalidTestSeq);
- } catch (SiftsException e)
- {
- throw new SiftsException(e.getMessage());
- }
+ siftsClient.getValidSourceDBRef(invalidTestSeq);
}
@Test(
- groups = { "Functional" },
+groups = { "Network" },
expectedExceptions = SiftsException.class)
public void getValidSourceDBRefExceptionXTest() throws SiftsException
{
DBRefEntry invalidDBRef = new DBRefEntry();
invalidDBRef.setAccessionId("BLAR");
invalidTestSeq.addDBRef(invalidDBRef);
- try
- {
- siftsClient.getValidSourceDBRef(invalidTestSeq);
- } catch (SiftsException e)
- {
- throw new SiftsException(e.getMessage());
- }
-
+ siftsClient.getValidSourceDBRef(invalidTestSeq);
}
- @Test(groups = { "Functional" })
+ @Test(groups = { "Network" })
public void isValidDBRefEntryTest()
{
DBRefEntryI validDBRef = new DBRefEntry();
Assert.assertTrue(siftsClient.isValidDBRefEntry(validDBRef));
}
- @Test(groups = { "Functional" })
- public void getSiftsStructureMappingTest()
+ @Test(groups = { "Network" })
+ public void getSiftsStructureMappingTest() throws SiftsException
{
- try
- {
- Assert.assertTrue(SiftsSettings.isMapWithSifts());
- StructureMapping strucMapping = siftsClient.getSiftsStructureMapping(
- testSeq, testPDBId, "A");
- String expectedMappingOutput = "\nSequence ⟷ Structure mapping details\n"
- + "Method: SIFTS\n\n"
- + "P00221 : 51 - 147 Maps to \n"
- + "1A70|A : 1 - 97\n\n"
- + "P00221 AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n"
- + " |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"
- + "1A70|A AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n\n"
-
- + "P00221 DDQIDEGWVLTCAAYPVSDVTIETHKEEELTA\n"
- + " |||||||||||||||||||||||||| |||||\n"
- + "1A70|A DDQIDEGWVLTCAAYPVSDVTIETHKKEELTA\n\n" +
-
- "Length of alignment = 97\n" + "Percentage ID = 98.97\n";
-
- Assert.assertEquals(strucMapping.getMappingDetailsOutput(),
- expectedMappingOutput);
- Assert.assertEquals(strucMapping.getMapping(), expectedMapping);
- } catch (SiftsException e)
- {
- e.printStackTrace();
- }
+ Assert.assertTrue(SiftsSettings.isMapWithSifts());
+ StructureMapping strucMapping = siftsClient.getSiftsStructureMapping(
+ testSeq, testPDBId, "A");
+ String expectedMappingOutput = "\nSequence ⟷ Structure mapping details\n"
+ + "Method: SIFTS\n\n"
+ + "P00221 : 51 - 147 Maps to \n"
+ + "1A70|A : 1 - 97\n\n"
+ + "P00221 AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n"
+ + " |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"
+ + "1A70|A AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n\n"
+
+ + "P00221 DDQIDEGWVLTCAAYPVSDVTIETHKEEELTA\n"
+ + " |||||||||||||||||||||||||| |||||\n"
+ + "1A70|A DDQIDEGWVLTCAAYPVSDVTIETHKKEELTA\n\n" +
+
+ "Length of alignment = 97\n" + "Percentage ID = 98.97\n";
+
+ Assert.assertEquals(strucMapping.getMappingDetailsOutput(),
+ expectedMappingOutput);
+ Assert.assertEquals(strucMapping.getMapping(), expectedMapping);
}
- @Test(groups = { "Functional" })
+ @Test(groups = { "Network" })
public void getEntityCountTest()
{
int actualEntityCount = siftsClient.getEntityCount();
Assert.assertEquals(actualEntityCount, 1);
}
- @Test(groups = { "Functional" })
+ @Test(groups = { "Network" })
public void getDbAccessionIdTest()
{
String actualDbAccId = siftsClient.getDbAccessionId();
Assert.assertEquals(actualDbAccId, "1a70");
}
- @Test(groups = { "Functional" })
+ @Test(groups = { "Network" })
public void getDbCoordSysTest()
{
String actualDbCoordSys = siftsClient.getDbCoordSys();
Assert.assertEquals(actualDbCoordSys, "PDBe");
}
- @Test(groups = { "Functional" })
+ @Test(groups = { "Network" })
public void getDbSourceTest()
{
String actualDbSource = siftsClient.getDbSource();
Assert.assertEquals(actualDbSource, "PDBe");
}
- @Test(groups = { "Functional" })
+ @Test(groups = { "Network" })
public void getDbVersionTest()
{
String actualDbVersion = siftsClient.getDbVersion();
Assert.assertEquals(actualDbVersion, "2.0");
}
- @Test(groups = { "Functional" })
- public void getEntityByMostOptimalMatchedIdTest1()
+ @Test(groups = { "Network" })
+ public void getEntityByMostOptimalMatchedIdTest1() throws IOException,
+ SiftsException
{
SiftsClient siftsClientX = null;
PDBfile pdbFile;
- try
- {
- pdbFile = new PDBfile(false, false, false, "test/jalview/io/2nq2"
- + ".pdb", DataSourceType.FILE);
- siftsClientX = new SiftsClient(pdbFile);
- } catch (Exception e)
- {
- e.printStackTrace();
- }
+ pdbFile = new PDBfile(false, false, false, "test/jalview/io/2nq2"
+ + ".pdb", DataSourceType.FILE);
+ siftsClientX = new SiftsClient(pdbFile);
Entity entityA = siftsClientX.getEntityByMostOptimalMatchedId("A");
Assert.assertEquals(entityA.getEntityId(), "A");
Entity entityB = siftsClientX.getEntityByMostOptimalMatchedId("B");
}
- @Test(groups = { "Functional" })
- public void getEntityByMostOptimalMatchedIdTest2()
+ @Test(groups = { "Network" })
+ public void getEntityByMostOptimalMatchedIdTest2() throws IOException,
+ SiftsException
{
// This test is for a SIFTS file in which entity A should map to chain P for
// the given PDB Id. All the other chains shouldn't be mapped as there are
// no SIFTS entity records for them.
SiftsClient siftsClientX = null;
PDBfile pdbFile;
- try
- {
- pdbFile = new PDBfile(false, false, false,
- "test/jalview/io/3ucu.cif", DataSourceType.FILE);
- siftsClientX = new SiftsClient(pdbFile);
- } catch (Exception e)
- {
- e.printStackTrace();
- }
+ pdbFile = new PDBfile(false, false, false, "test/jalview/io/3ucu.cif",
+ DataSourceType.FILE);
+ siftsClientX = new SiftsClient(pdbFile);
Entity entityA = siftsClientX.getEntityByMostOptimalMatchedId("P");
Entity entityP = siftsClientX.getEntityByMostOptimalMatchedId("A");
Entity entityR = siftsClientX.getEntityByMostOptimalMatchedId("R");