X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fext%2Fjmol%2FJmolCommandsTest.java;h=968460335741cd431d1d80e941e4d8c4c1163003;hb=cd669a0e8c7b91b379bca8fe6e702cf0fcbd1ce0;hp=1ade00ee5be3cbaa240f044f00486a4e94446849;hpb=9dabc02511e3a334a5749a504f57f69d6c9017bd;p=jalview.git diff --git a/test/jalview/ext/jmol/JmolCommandsTest.java b/test/jalview/ext/jmol/JmolCommandsTest.java index 1ade00e..9684603 100644 --- a/test/jalview/ext/jmol/JmolCommandsTest.java +++ b/test/jalview/ext/jmol/JmolCommandsTest.java @@ -38,23 +38,22 @@ import jalview.datamodel.ColumnSelection; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; -import jalview.gui.JvOptionPane; import jalview.gui.SequenceRenderer; import jalview.schemes.JalviewColourScheme; import jalview.structure.AtomSpecModel; import jalview.structure.StructureCommandI; -import jalview.structure.StructureCommandsI; +import jalview.structure.StructureCommandsI.AtomSpecType; import jalview.structure.StructureMapping; import jalview.structure.StructureSelectionManager; public class JmolCommandsTest { + private JmolCommands testee; @BeforeClass(alwaysRun = true) - public void setUpJvOptionPane() + public void setUp() { - JvOptionPane.setInteractiveMode(false); - JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + testee = new JmolCommands(); } @Test(groups = { "Functional" }) @@ -95,8 +94,8 @@ public class JmolCommandsTest "B", map, null); ssm.addStructureMapping(sm2); - String[] commands = new JmolCommands().colourBySequence(ssm, files, - seqs, sr, af.alignPanel); + String[] commands = testee.colourBySequence(ssm, files, seqs, sr, + af.alignPanel); assertEquals(commands.length, 2); String chainACommand = commands[0]; @@ -130,38 +129,39 @@ public class JmolCommandsTest @Test(groups = "Functional") public void testGetAtomSpec() { - StructureCommandsI testee = new JmolCommands(); AtomSpecModel model = new AtomSpecModel(); - assertEquals(testee.getAtomSpec(model, false), ""); + assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), ""); model.addRange("1", 2, 4, "A"); - assertEquals(testee.getAtomSpec(model, false), "2-4:A/1.1"); + assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), + "2-4:A/1.1"); model.addRange("1", 8, 8, "A"); - assertEquals(testee.getAtomSpec(model, false), "2-4:A/1.1|8:A/1.1"); + assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), + "2-4:A/1.1|8:A/1.1"); model.addRange("1", 5, 7, "B"); - assertEquals(testee.getAtomSpec(model, false), + assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), "2-4:A/1.1|8:A/1.1|5-7:B/1.1"); model.addRange("1", 3, 5, "A"); - assertEquals(testee.getAtomSpec(model, false), + assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), "2-5:A/1.1|8:A/1.1|5-7:B/1.1"); model.addRange("2", 1, 4, "B"); - assertEquals(testee.getAtomSpec(model, false), + assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), "2-5:A/1.1|8:A/1.1|5-7:B/1.1|1-4:B/2.1"); model.addRange("2", 5, 9, "C"); - assertEquals(testee.getAtomSpec(model, false), + assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), "2-5:A/1.1|8:A/1.1|5-7:B/1.1|1-4:B/2.1|5-9:C/2.1"); model.addRange("1", 8, 10, "B"); - assertEquals(testee.getAtomSpec(model, false), + assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), "2-5:A/1.1|8:A/1.1|5-10:B/1.1|1-4:B/2.1|5-9:C/2.1"); model.addRange("1", 8, 9, "B"); - assertEquals(testee.getAtomSpec(model, false), + assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), "2-5:A/1.1|8:A/1.1|5-10:B/1.1|1-4:B/2.1|5-9:C/2.1"); model.addRange("2", 3, 10, "C"); // subsumes 5-9 - assertEquals(testee.getAtomSpec(model, false), + assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), "2-5:A/1.1|8:A/1.1|5-10:B/1.1|1-4:B/2.1|3-10:C/2.1"); model.addRange("5", 25, 35, " "); - assertEquals(testee.getAtomSpec(model, false), + assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), "2-5:A/1.1|8:A/1.1|5-10:B/1.1|1-4:B/2.1|3-10:C/2.1|25-35:/5.1"); - + } @Test(groups = { "Functional" }) @@ -180,8 +180,7 @@ public class JmolCommandsTest // Colours should appear in the Jmol command in the order in which // they were added; within colour, by model, by chain, ranges in start order - List commands = new JmolCommands() - .colourBySequence(map); + List commands = testee.colourBySequence(map); assertEquals(commands.size(), 1); String expected1 = "select 2-5:A/1.1|9-23:A/1.1|7:B/1.1|1:A/2.1|4-7:B/2.1;color[0,0,255]"; String expected2 = "select 3-5:A/2.1|8:A/2.1;color[255,255,0]"; @@ -193,7 +192,6 @@ public class JmolCommandsTest @Test(groups = { "Functional" }) public void testSuperposeStructures() { - StructureCommandsI testee = new JmolCommands(); AtomSpecModel ref = new AtomSpecModel(); ref.addRange("1", 12, 14, "A"); ref.addRange("1", 18, 18, "B"); @@ -203,7 +201,8 @@ public class JmolCommandsTest toAlign.addRange("2", 20, 21, "B"); toAlign.addRange("2", 22, 22, "C"); List command = testee.superposeStructures(ref, - toAlign); + toAlign, AtomSpecType.ALPHA); // doesn't matter for Jmol whether nuc + // or protein assertEquals(command.size(), 1); String refSpec = "12-14:A/1.1|18:B/1.1|22-23:B/1.1"; String toAlignSpec = "15-17:B/2.1|20-21:B/2.1|22:C/2.1"; @@ -216,7 +215,75 @@ public class JmolCommandsTest @Test(groups = "Functional") public void testGetModelStartNo() { - StructureCommandsI testee = new JmolCommands(); assertEquals(testee.getModelStartNo(), 1); } + + @Test(groups = "Functional") + public void testColourByChain() + { + StructureCommandI cmd = testee.colourByChain(); + assertEquals(cmd.getCommand(), "select *;color chain"); + } + + @Test(groups = "Functional") + public void testColourByCharge() + { + List cmds = testee.colourByCharge(); + assertEquals(cmds.size(), 1); + assertEquals(cmds.get(0).getCommand(), + "select *;color white;select ASP,GLU;color red;" + + "select LYS,ARG;color blue;select CYS;color yellow"); + } + + @Test(groups = "Functional") + public void testSetBackgroundColour() + { + StructureCommandI cmd = testee.setBackgroundColour(Color.PINK); + assertEquals(cmd.getCommand(), "background [255,175,175]"); + } + + @Test(groups = "Functional") + public void testFocusView() + { + StructureCommandI cmd = testee.focusView(); + assertEquals(cmd.getCommand(), "zoom 0"); + } + + @Test(groups = "Functional") + public void testSaveSession() + { + StructureCommandI cmd = testee.saveSession("/some/filepath"); + assertEquals(cmd.getCommand(), "write STATE \"/some/filepath\""); + } + + @Test(groups = "Functional") + public void testShowBackbone() + { + List cmds = testee.showBackbone(); + assertEquals(cmds.size(), 1); + assertEquals(cmds.get(0).getCommand(), + "select *; cartoons off; backbone"); + } + + @Test(groups = "Functional") + public void testLoadFile() + { + StructureCommandI cmd = testee.loadFile("/some/filepath"); + assertEquals(cmd.getCommand(), "load FILES \"/some/filepath\""); + + // single backslash gets escaped to double + cmd = testee.loadFile("\\some\\filepath"); + assertEquals(cmd.getCommand(), "load FILES \"\\\\some\\\\filepath\""); + } + + @Test(groups = "Functional") + public void testOpenSession() + { + StructureCommandI cmd = testee.openSession("/some/filepath"); + assertEquals(cmd.getCommand(), "load FILES \"/some/filepath\""); + + // single backslash gets escaped to double + cmd = testee.openSession("\\some\\filepath"); + assertEquals(cmd.getCommand(), "load FILES \"\\\\some\\\\filepath\""); + } }