1 | /******************************************************************************* |
---|
2 | * ProMoT |
---|
3 | * --------------------------------------------------------------------------- |
---|
4 | * Copyright (c) 1997-2012 ProMoT Development Team |
---|
5 | * Max Planck Institute Magdeburg, Germany |
---|
6 | * http://www.mpi-magdeburg.mpg.de/projects/promot |
---|
7 | * |
---|
8 | * This is free software; you can redistribute it and/or modify it |
---|
9 | * under the terms of the GNU General Public License as published |
---|
10 | * by the Free Software Foundation; either version 2 of the License, or |
---|
11 | * any later version. |
---|
12 | * |
---|
13 | * THIS SOFTWARE IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, |
---|
14 | * BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE WARRANTY OF |
---|
15 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. |
---|
16 | * IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE |
---|
17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
23 | * SUCH DAMAGE. |
---|
24 | * |
---|
25 | * You should have received a copy of the GNU General Public License |
---|
26 | * along with this library; if not, write to the Free Software Foundation, |
---|
27 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
28 | * |
---|
29 | * --------------------------------------------------------------------------- |
---|
30 | * $Id$ |
---|
31 | ******************************************************************************/ |
---|
32 | package org.mpg.dcts.promot.test; |
---|
33 | |
---|
34 | import org.junit.After; |
---|
35 | import org.junit.Assert; |
---|
36 | import org.junit.Before; |
---|
37 | import org.junit.Test; |
---|
38 | import org.mpg.dcts.promot.Configure; |
---|
39 | import org.mpg.dcts.promot.Promot; |
---|
40 | import org.mpg.dcts.promot.PromotUI; |
---|
41 | import org.mpg.dcts.promot.browser.PromotTreeNode; |
---|
42 | import org.mpg.dcts.promot.dialogs.ServerFile; |
---|
43 | import org.mpg.dcts.promot.vizedit.PaletteWindow; |
---|
44 | import org.mpg.dcts.promot.vizedit.cmds.CmdFlipNode; |
---|
45 | import org.mpg.dcts.promot.vizedit.graph.ModuleGraphModel; |
---|
46 | import org.mpg.dcts.promot.vizedit.graph.ModuleNode; |
---|
47 | |
---|
48 | import PromotGuiIdl.ExLisp; |
---|
49 | import PromotGuiIdl.ExMissingPart; |
---|
50 | |
---|
51 | /** |
---|
52 | * |
---|
53 | * @author kolczyk |
---|
54 | */ |
---|
55 | public class FlippingTest { |
---|
56 | |
---|
57 | private PromotTreeNode cell = null; |
---|
58 | private CmdFlipNode cmdSetH, cmdSetV; |
---|
59 | private PaletteWindow pw; |
---|
60 | private Boolean prevValChecker; |
---|
61 | private ModuleGraphModel mgm; |
---|
62 | |
---|
63 | @Before |
---|
64 | public void setUp() throws Exception { |
---|
65 | Promot.loadMdlFile(new ServerFile( |
---|
66 | Configure.PROMOT_SRC+ServerFile.sep+"kb"+ServerFile.sep+"SignalTransd"+ServerFile.sep+"structure"+ServerFile.sep+"struct-ana-library.mdl",false).getCFile()); |
---|
67 | Promot.loadMdlFile(new ServerFile( |
---|
68 | Configure.PROMOT_SRC+ServerFile.sep+"kb"+ServerFile.sep+"testsuite"+ServerFile.sep+"mdl"+ServerFile.sep+"graphicalInformationTest.mdl",false).getCFile()); |
---|
69 | cell=Promot.getPromotTreeNode("cell"); |
---|
70 | prevValChecker = (Boolean) PromotUI.getDefault("ModuleGraphChecker.enable", new Boolean(false)); |
---|
71 | PromotUI.setDefault("ModuleGraphChecker.enable", new Boolean(false)); |
---|
72 | pw = new PaletteWindow(cell,cell.getLock(100, null)); |
---|
73 | mgm = (ModuleGraphModel) pw.getEditor().getGraphModel(); |
---|
74 | |
---|
75 | cmdSetH = new CmdFlipNode(CmdFlipNode.HORIZONTALLY); |
---|
76 | cmdSetH.putValue("ModuleNode", mgm.getModule("a2")); |
---|
77 | Assert.assertTrue(cmdSetH.performable()); |
---|
78 | |
---|
79 | //flipping vertically in case of rotated nodes means flipping horizontally |
---|
80 | cmdSetV = new CmdFlipNode(CmdFlipNode.VERTICALLY); |
---|
81 | cmdSetV.putValue("ModuleNode", mgm.getModule("k2")); |
---|
82 | Assert.assertTrue(cmdSetV.performable()); |
---|
83 | } |
---|
84 | |
---|
85 | @After |
---|
86 | public void tearDown() throws Exception { |
---|
87 | if(pw!=null) |
---|
88 | pw.doDispose(); |
---|
89 | Promot.deleteKb(); |
---|
90 | PromotUI.setDefault("ModuleGraphChecker.enable", prevValChecker); |
---|
91 | } |
---|
92 | |
---|
93 | @Test |
---|
94 | public void testGetFlipValues() throws ExLisp, ExMissingPart{ |
---|
95 | ModuleNode a1 = mgm.getModule("a1"); //"10" |
---|
96 | ModuleNode a1_not_ph1_k1 = mgm.getModule("a1_not_ph1_k1" ); //"01" |
---|
97 | ModuleNode a1_ph2 = mgm.getModule("a1_ph2"); //"11" |
---|
98 | Assert.assertEquals(new Integer(1), a1.getflipH()); |
---|
99 | Assert.assertEquals(new Integer(0), a1.getflipV()); |
---|
100 | Assert.assertEquals(new Integer(0), a1_not_ph1_k1.getflipH()); |
---|
101 | Assert.assertEquals(new Integer(1), a1_not_ph1_k1.getflipV()); |
---|
102 | Assert.assertEquals(new Integer(1), a1_ph2.getflipH()); |
---|
103 | Assert.assertEquals(new Integer(1), a1_ph2.getflipV()); |
---|
104 | } |
---|
105 | |
---|
106 | @Test |
---|
107 | public void testSetFlipValues() throws ExLisp, ExMissingPart{ |
---|
108 | cmdSetH.doIt(); |
---|
109 | Assert.assertEquals(new Integer(1), mgm.getModule("a2").getflipH()); |
---|
110 | Assert.assertEquals(new Integer(0), mgm.getModule("a2").getflipV()); |
---|
111 | |
---|
112 | cmdSetV.doIt(); |
---|
113 | Assert.assertEquals(new Integer(1), mgm.getModule("k2").getflipH()); |
---|
114 | Assert.assertEquals(new Integer(0), mgm.getModule("k2").getflipV()); |
---|
115 | |
---|
116 | cmdSetH.undoIt(); |
---|
117 | Assert.assertEquals(new Integer(0), mgm.getModule("a2").getflipH()); |
---|
118 | Assert.assertEquals(new Integer(0), mgm.getModule("a2").getflipV()); |
---|
119 | |
---|
120 | cmdSetV.undoIt(); |
---|
121 | Assert.assertEquals(new Integer(0), mgm.getModule("k2").getflipH()); |
---|
122 | Assert.assertEquals(new Integer(0), mgm.getModule("k2").getflipV()); |
---|
123 | } |
---|
124 | } |
---|