X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fext%2Frbvi%2Fchimera%2FChimeraCommandsTest.java;h=49a93c2f97ef33b89bf4e791edcbf4806c600317;hb=600851b134c738f1453881fa60a7b699377b8e52;hp=5fc9fdc9fc9abe18698dcca9854e12803372976f;hpb=bee310c7b5755403cedfb7f717f65769bb4b59d5;p=jalview.git diff --git a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java index 5fc9fdc..49a93c2 100644 --- a/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java +++ b/test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java @@ -29,14 +29,21 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import jalview.structure.AtomSpecModel; import jalview.structure.StructureCommandI; -import jalview.structure.StructureCommandsI; public class ChimeraCommandsTest { + private ChimeraCommands testee; + + @BeforeClass + public void setUp() + { + testee = new ChimeraCommands(); + } @Test(groups = { "Functional" }) public void testColourBySequence() @@ -55,8 +62,7 @@ public class ChimeraCommandsTest // Colours should appear in the Chimera command in the order in which // they were added; within colour, by model, by chain, ranges in start order - List commands = new ChimeraCommands() - .colourBySequence(map); + List commands = testee.colourBySequence(map); assertEquals(commands.size(), 1); assertEquals(commands.get(0).getCommand(), "color #0000ff #0:2-5.A,9-23.A,7.B|#1:1.A,4-7.B;color #ffff00 #1:3-5.A,8.A;color #ff0000 #0:3-9.A"); @@ -70,16 +76,14 @@ public class ChimeraCommandsTest */ Map> featuresMap = new LinkedHashMap<>(); Map featureValues = new HashMap<>(); - + /* * start with just one feature/value... */ featuresMap.put("chain", featureValues); ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 8, 20, "A"); - - ChimeraCommands commandGenerator = new ChimeraCommands(); - List commands = commandGenerator - .setAttributes(featuresMap); + + List commands = testee.setAttributes(featuresMap); assertEquals(1, commands.size()); /* @@ -93,7 +97,7 @@ public class ChimeraCommandsTest ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 3, 9, "A"); // same feature value, contiguous range ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 21, 25, "A"); - commands = commandGenerator.setAttributes(featuresMap); + commands = testee.setAttributes(featuresMap); assertEquals(1, commands.size()); assertEquals(commands.get(0).getCommand(), "setattr res jv_chain 'X' #0:3-25.A"); @@ -102,14 +106,14 @@ public class ChimeraCommandsTest ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 21, 25, "B"); // same feature value and chain, different model ChimeraCommands.addAtomSpecRange(featureValues, "X", "1", 26, 30, "A"); - commands = commandGenerator.setAttributes(featuresMap); + commands = testee.setAttributes(featuresMap); assertEquals(1, commands.size()); String expected1 = "setattr res jv_chain 'X' #0:3-25.A,21-25.B|#1:26-30.A"; assertEquals(commands.get(0).getCommand(), expected1); // same feature, different value ChimeraCommands.addAtomSpecRange(featureValues, "Y", "0", 40, 50, "A"); - commands = commandGenerator.setAttributes(featuresMap); + commands = testee.setAttributes(featuresMap); assertEquals(2, commands.size()); // commands are ordered by feature type but not by value // so test for the expected command in either order @@ -123,11 +127,10 @@ public class ChimeraCommandsTest featureValues.clear(); featuresMap.put("side-chain binding!", featureValues); ChimeraCommands.addAtomSpecRange(featureValues, - "metal 'ion!", "0", 7, 15, - "A"); + "metal 'ion!", "0", 7, 15, "A"); // feature names are sanitised to change non-alphanumeric to underscore // feature values are sanitised to encode single quote characters - commands = commandGenerator.setAttributes(featuresMap); + commands = testee.setAttributes(featuresMap); assertEquals(commands.size(), 1); String expected3 = "setattr res jv_side_chain_binding_ 'metal 'ion!' #0:7-15.A"; assertTrue(commands.get(0).getCommand().equals(expected3)); @@ -140,26 +143,22 @@ public class ChimeraCommandsTest @Test(groups = { "Functional" }) public void testMakeAttributeName() { - ChimeraCommands testee = new ChimeraCommands(); assertEquals(testee.makeAttributeName(null), "jv_"); assertEquals(testee.makeAttributeName(""), "jv_"); assertEquals(testee.makeAttributeName("helix"), "jv_helix"); assertEquals(testee.makeAttributeName( "Hello World 24"), "jv_Hello_World_24"); - assertEquals( - testee.makeAttributeName( - "!this is-a_very*{odd(name"), + assertEquals(testee.makeAttributeName( + "!this is-a_very*{odd(name"), "jv__this_is_a_very__odd_name"); // name ending in color gets underscore appended - assertEquals(testee.makeAttributeName("helixColor"), - "jv_helixColor_"); + assertEquals(testee.makeAttributeName("helixColor"), "jv_helixColor_"); } @Test(groups = "Functional") public void testGetAtomSpec() { - StructureCommandsI testee = new ChimeraCommands(); AtomSpecModel model = new AtomSpecModel(); assertEquals(testee.getAtomSpec(model, false), ""); model.addRange("1", 2, 4, "A"); @@ -194,7 +193,6 @@ public class ChimeraCommandsTest @Test(groups = { "Functional" }) public void testSuperposeStructures() { - StructureCommandsI testee = new ChimeraCommands(); AtomSpecModel ref = new AtomSpecModel(); ref.addRange("1", 12, 14, "A"); ref.addRange("1", 18, 18, "B"); @@ -209,16 +207,15 @@ public class ChimeraCommandsTest String carbonAlphas = "@CA&~@.B-Z&~@.2-9"; String refSpec = "#1:12-14.A,18.B,22-23.B"; String toAlignSpec = "#2:15-17.B,20-21.B,22.C"; - String expected = String.format( - "match %s%s %s%s; ribbon %s|%s; focus", toAlignSpec, - carbonAlphas, refSpec, carbonAlphas, toAlignSpec, refSpec); + String expected = String.format("match %s%s %s%s; ribbon %s|%s; focus", + toAlignSpec, carbonAlphas, refSpec, carbonAlphas, toAlignSpec, + refSpec); assertEquals(command.get(0).getCommand(), expected); } @Test(groups = "Functional") public void testGetAtomSpec_alphaOnly() { - StructureCommandsI testee = new ChimeraCommands(); AtomSpecModel model = new AtomSpecModel(); assertEquals(testee.getAtomSpec(model, true), ""); model.addRange("1", 2, 4, "A"); @@ -251,27 +248,24 @@ public class ChimeraCommandsTest model.addRange("5", 25, 35, " "); // empty chain code assertEquals(testee.getAtomSpec(model, true), "#0:1-4.B,3-10.C@CA&~@.B-Z&~@.2-9|#1:2-5.A,8.A,5-10.B@CA&~@.B-Z&~@.2-9|#5:25-35.@CA&~@.B-Z&~@.2-9"); - + } @Test(groups = "Functional") public void testGetModelStartNo() { - StructureCommandsI testee = new ChimeraCommands(); assertEquals(testee.getModelStartNo(), 0); } @Test(groups = "Functional") public void testGetResidueSpec() { - ChimeraCommands testee = new ChimeraCommands(); assertEquals(testee.getResidueSpec("ALA"), "::ALA"); } @Test(groups = "Functional") public void testShowBackbone() { - ChimeraCommands testee = new ChimeraCommands(); List cmds = testee.showBackbone(); assertEquals(cmds.size(), 1); assertEquals(cmds.get(0).getCommand(), @@ -281,7 +275,6 @@ public class ChimeraCommandsTest @Test(groups = "Functional") public void testOpenCommandFile() { - ChimeraCommands testee = new ChimeraCommands(); assertEquals(testee.openCommandFile("nowhere").getCommand(), "open cmd:nowhere"); } @@ -289,29 +282,69 @@ public class ChimeraCommandsTest @Test(groups = "Functional") public void testSaveSession() { - ChimeraCommands testee = new ChimeraCommands(); assertEquals(testee.saveSession("somewhere").getCommand(), "save somewhere"); } @Test(groups = "Functional") + public void testColourByChain() + { + assertEquals(testee.colourByChain().getCommand(), "rainbow chain"); + } + + @Test(groups = { "Functional" }) + public void testSetBackgroundColour() + { + StructureCommandI cmd = testee.setBackgroundColour(Color.PINK); + assertEquals(cmd.getCommand(), "set bgColor #ffafaf"); + } + + @Test(groups = { "Functional" }) + public void testLoadFile() + { + StructureCommandI cmd = testee.loadFile("/some/filepath"); + assertEquals(cmd.getCommand(), "open /some/filepath"); + } + + @Test(groups = { "Functional" }) + public void testOpenSession() + { + StructureCommandI cmd = testee.openSession("/some/filepath"); + assertEquals(cmd.getCommand(), "open chimera:/some/filepath"); + } + + @Test(groups = "Functional") + public void testColourByCharge() + { + List cmds = testee.colourByCharge(); + assertEquals(cmds.size(), 1); + assertEquals(cmds.get(0) + .getCommand(), + "color white;color red ::ASP,GLU;color blue ::LYS,ARG;color yellow ::CYS"); + } + + @Test(groups = "Functional") public void testGetColourCommand() { - ChimeraCommands testee = new ChimeraCommands(); assertEquals(testee.colourResidues("something", Color.MAGENTA) .getCommand(), "color #ff00ff something"); } @Test(groups = "Functional") + public void testFocusView() + { + assertEquals(testee.focusView().getCommand(), "focus"); + } + + @Test(groups = "Functional") public void testSetAttribute() { - ChimeraCommands testee = new ChimeraCommands(); AtomSpecModel model = new AtomSpecModel(); model.addRange("1", 89, 92, "A"); model.addRange("2", 12, 20, "B"); model.addRange("2", 8, 9, "B"); - assertEquals(testee.setAttribute("phi", "27.3", model).getCommand(), - "setattr res phi '27.3' #1:89-92.A|#2:8-9.B,12-20.B"); + assertEquals(testee.setAttribute("jv_kd", "27.3", model).getCommand(), + "setattr res jv_kd '27.3' #1:89-92.A|#2:8-9.B,12-20.B"); } }