Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / test / jalview / ws / sifts / SiftsClientTest.java
index 44a6a02..ebe7f25 100644 (file)
@@ -23,16 +23,6 @@ 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;
-import jalview.datamodel.DBRefSource;
-import jalview.datamodel.Sequence;
-import jalview.datamodel.SequenceI;
-import jalview.gui.JvOptionPane;
-import jalview.io.DataSourceType;
-import jalview.structure.StructureMapping;
-import jalview.xml.binding.sifts.Entry.Entity;
 
 import java.io.File;
 import java.io.IOException;
@@ -48,6 +38,16 @@ import org.testng.annotations.BeforeClass;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
 
+import jalview.api.DBRefEntryI;
+import jalview.bin.Cache;
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+import jalview.gui.JvOptionPane;
+import jalview.io.DataSourceType;
+import jalview.structure.StructureMapping;
+import jalview.xml.binding.sifts.Entry.Entity;
 import mc_view.Atom;
 import mc_view.PDBfile;
 
@@ -62,18 +62,19 @@ public class SiftsClientTest
   }
 
   public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
-          .getProperty("user.home") + File.separatorChar
+          .getProperty("user.home")
+          + File.separatorChar
           + ".sifts_downloads" + File.separatorChar;
 
   private String testPDBId = "1a70";
 
   private SiftsClient siftsClient = null;
 
-  SequenceI testSeq = new Sequence("P00221",
+  SequenceI testSeq = new Sequence(
+          "P00221",
           "MAAT..TTTMMG..MATTFVPKPQAPPMMAALPSNTGR..SLFGLKT.GSR..GGRMTMA"
                   + "AYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDD"
-                  + "QSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEELTA.",
-          1, 147);
+                  + "QSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEELTA.", 1, 147);
 
   int u = SiftsClient.UNASSIGNED;
 
@@ -188,15 +189,14 @@ public class SiftsClientTest
     Cache.loadProperties("test/jalview/io/testProps.jvprops");
     // SIFTs entries are updated weekly - so use saved SIFTs file to enforce
     // test reproducibility
-    new SiftsSettings();
-    SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache
-            .getDefault("sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
+    SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache.getDefault(
+            "sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
     SiftsSettings.setMapWithSifts(true);
     SiftsSettings.setCacheThresholdInDays("2");
     SiftsSettings.setFailSafePIDThreshold("70");
     PDBfile pdbFile;
-    pdbFile = new PDBfile(false, false, false,
-            "test/jalview/io/" + testPDBId + ".pdb", DataSourceType.FILE);
+    pdbFile = new PDBfile(false, false, false, "test/jalview/io/"
+            + testPDBId + ".pdb", DataSourceType.FILE);
     siftsClient = new SiftsClient(pdbFile);
   }
 
@@ -277,8 +277,8 @@ public class SiftsClientTest
 
     try
     {
-      HashMap<Integer, int[]> actualMapping = siftsClient
-              .getGreedyMapping("A", testSeq, null);
+      HashMap<Integer, int[]> actualMapping = siftsClient.getGreedyMapping(
+              "A", testSeq, null);
       Assert.assertEquals(testSeq.getStart(), 1);
       Assert.assertEquals(testSeq.getEnd(), 147);
       // Can't do Assert.assertEquals(actualMapping, expectedMapping);
@@ -310,14 +310,13 @@ public class SiftsClientTest
     atom.atomIndex = 7;
     atoms.add(atom);
     int actualAtomIndex = siftsClient.getAtomIndex(1, atoms);
-    Assert.assertEquals(actualAtomIndex, siftsClient.UNASSIGNED);
+    Assert.assertEquals(actualAtomIndex, SiftsClient.UNASSIGNED);
     actualAtomIndex = siftsClient.getAtomIndex(43, atoms);
     Assert.assertEquals(actualAtomIndex, 7);
   }
 
   @Test(
-    groups =
-    { "Network" },
+    groups = { "Network" },
     expectedExceptions = IllegalArgumentException.class)
   private void getAtomIndexNullTest()
   {
@@ -330,14 +329,18 @@ public class SiftsClientTest
 
   }
 
-  @Test(groups = { "Network" }, expectedExceptions = SiftsException.class)
+  @Test(
+groups = { "Network" },
+    expectedExceptions = SiftsException.class)
   private void populateAtomPositionsNullTest1()
           throws IllegalArgumentException, SiftsException
   {
     siftsClient.populateAtomPositions(null, null);
   }
 
-  @Test(groups = { "Network" }, expectedExceptions = SiftsException.class)
+  @Test(
+groups = { "Network" },
+    expectedExceptions = SiftsException.class)
   private void populateAtomPositionsNullTest2()
           throws IllegalArgumentException, SiftsException
   {
@@ -356,14 +359,18 @@ public class SiftsClientTest
     Assert.assertEquals(actualValidSrcDBRef, expectedDBRef);
   }
 
-  @Test(groups = { "Network" }, expectedExceptions = SiftsException.class)
+  @Test(
+groups = { "Network" },
+    expectedExceptions = SiftsException.class)
   public void getValidSourceDBRefExceptionTest() throws SiftsException
   {
     SequenceI invalidTestSeq = new Sequence("testSeq", "ABCDEFGH");
     siftsClient.getValidSourceDBRef(invalidTestSeq);
   }
 
-  @Test(groups = { "Network" }, expectedExceptions = SiftsException.class)
+  @Test(
+groups = { "Network" },
+    expectedExceptions = SiftsException.class)
   public void getValidSourceDBRefExceptionXTest() throws SiftsException
   {
     SequenceI invalidTestSeq = new Sequence("testSeq", "ABCDEFGH");
@@ -387,10 +394,11 @@ public class SiftsClientTest
   public void getSiftsStructureMappingTest() throws SiftsException
   {
     Assert.assertTrue(SiftsSettings.isMapWithSifts());
-    StructureMapping strucMapping = siftsClient
-            .getSiftsStructureMapping(testSeq, testPDBId, "A");
+    StructureMapping strucMapping = siftsClient.getSiftsStructureMapping(
+            testSeq, testPDBId, "A");
     String expectedMappingOutput = "\nSequence ⟷ Structure mapping details\n"
-            + "Method: SIFTS\n\n" + "P00221 :  51 - 147 Maps to \n"
+            + "Method: SIFTS\n\n"
+            + "P00221 :  51 - 147 Maps to \n"
             + "1A70|A :  1 - 97\n\n"
             + "P00221 AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n"
             + "       |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"
@@ -414,8 +422,8 @@ public class SiftsClientTest
     while (it.hasNext())
     {
       Map.Entry<Integer, int[]> pair = it.next();
-      Assert.assertTrue(
-              strucMapping.getMapping().containsKey(pair.getKey()));
+      Assert.assertTrue(strucMapping.getMapping()
+              .containsKey(pair.getKey()));
       Assert.assertEquals(strucMapping.getMapping().get(pair.getKey()),
               pair.getValue());
     }
@@ -462,13 +470,13 @@ public class SiftsClientTest
   }
 
   @Test(groups = { "Network" })
-  public void getEntityByMostOptimalMatchedIdTest1()
-          throws IOException, SiftsException
+  public void getEntityByMostOptimalMatchedIdTest1() throws IOException,
+          SiftsException
   {
     SiftsClient siftsClientX = null;
     PDBfile pdbFile;
-    pdbFile = new PDBfile(false, false, false,
-            "test/jalview/io/2nq2" + ".pdb", DataSourceType.FILE);
+    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");
@@ -482,8 +490,8 @@ public class SiftsClientTest
   }
 
   @Test(groups = { "Network" })
-  public void getEntityByMostOptimalMatchedIdTest2()
-          throws IOException, SiftsException
+  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
@@ -505,18 +513,4 @@ public class SiftsClientTest
     Assert.assertNull(entityP);
 
   }
-
-  @Test(groups = { "Network" })
-  public void getLeadingIntegerFromString()
-  {
-    Assert.assertEquals(SiftsClient.getLeadingIntegerValue("1234abcd", -1),
-            1234);
-    Assert.assertEquals(SiftsClient.getLeadingIntegerValue("1234", -1),
-            1234);
-    Assert.assertEquals(SiftsClient.getLeadingIntegerValue("abcd", -1), -1);
-    Assert.assertEquals(SiftsClient.getLeadingIntegerValue("abcd1234", -1),
-            -1);
-    Assert.assertEquals(SiftsClient.getLeadingIntegerValue("None", -1), -1);
-    Assert.assertEquals(SiftsClient.getLeadingIntegerValue("Null", -1), -1);
-  }
 }