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 | |
---|
35 | import org.mpg.dcts.promot.Configure; |
---|
36 | import org.mpg.dcts.promot.Promot; |
---|
37 | import org.mpg.dcts.promot.browser.PromotTreeNode; |
---|
38 | import org.mpg.dcts.promot.dialogs.ServerFile; |
---|
39 | import org.mpg.dcts.promot.browser.CmdAddSubclass; |
---|
40 | |
---|
41 | import org.junit.After; |
---|
42 | import org.junit.AfterClass; |
---|
43 | import org.junit.Assert; |
---|
44 | import org.junit.Before; |
---|
45 | import org.junit.BeforeClass; |
---|
46 | import org.junit.Test; |
---|
47 | |
---|
48 | import PromotGuiIdl.ExMissingClass; |
---|
49 | import PromotGuiIdl.PromotClassProxy; |
---|
50 | |
---|
51 | |
---|
52 | public class CmdAddSubclassTest { |
---|
53 | private CmdAddSubclass cmd;//tested here, used in setup and tests |
---|
54 | private final String name="new_Test_Class";//name of subclass to create, used in cmd and tests |
---|
55 | |
---|
56 | @Test |
---|
57 | public void testPerformable() { |
---|
58 | Assert.assertTrue(cmd.performable()); |
---|
59 | } |
---|
60 | |
---|
61 | @Test |
---|
62 | public void testDoIt() throws Exception{ |
---|
63 | |
---|
64 | |
---|
65 | try { |
---|
66 | Assert.assertNull(Promot.getPromotClass(name)); |
---|
67 | Assert.fail("missing class exception expected."); |
---|
68 | } catch (ExMissingClass e) { |
---|
69 | //catch tested with fail after getPromotClass |
---|
70 | } |
---|
71 | cmd.doIt(name); |
---|
72 | //get class from cmd/Promot |
---|
73 | PromotClassProxy newClass=Promot.getPromotClass(name); |
---|
74 | Assert.assertNotNull(newClass); |
---|
75 | Assert.assertTrue(newClass.isModified()); |
---|
76 | //clean-up here, necessary for undoIt after doIt |
---|
77 | newClass.delete(); |
---|
78 | } |
---|
79 | |
---|
80 | @Test |
---|
81 | public void testUndoIt() throws Exception { |
---|
82 | //success tested in testDoIt |
---|
83 | cmd.doIt(name); |
---|
84 | //present before |
---|
85 | PromotClassProxy newClass=Promot.getPromotClass(name); |
---|
86 | Assert.assertNotNull(newClass); |
---|
87 | //removed by undo |
---|
88 | cmd.undoIt(); |
---|
89 | try{ |
---|
90 | newClass=null; |
---|
91 | newClass=Promot.getPromotClass(name); |
---|
92 | Assert.fail("class: "+name+" still present."); |
---|
93 | } |
---|
94 | catch(ExMissingClass emc){ |
---|
95 | //catch tested with fail after getPromotClass |
---|
96 | Assert.assertNull(newClass);//redundant as class was not changed |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | @Before |
---|
102 | public void setUp() throws Exception { |
---|
103 | // loading tank-class |
---|
104 | Promot.loadMdlFile(new ServerFile(Configure.PROMOT_SRC+ServerFile.sep+"kb"+ServerFile.sep+"tank"+ServerFile.sep+"LOAD.mdl",false).getCFile()); |
---|
105 | PromotTreeNode tank=Promot.getPromotTreeNode("tank"); |
---|
106 | cmd = new CmdAddSubclass(); |
---|
107 | Assert.assertFalse(cmd.performable()); |
---|
108 | cmd.putValue("ClassName",tank.getName()); |
---|
109 | cmd.putValue("PromotTreeNode", tank); |
---|
110 | cmd.fillValues(); |
---|
111 | } |
---|
112 | |
---|
113 | @After |
---|
114 | public void tearDown() throws Exception { |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | @BeforeClass |
---|
119 | public static void setUpBeforeClass() throws Exception { |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | @AfterClass |
---|
124 | public static void tearDownAfterClass() throws Exception { |
---|
125 | Promot.deleteKb(); |
---|
126 | } |
---|
127 | |
---|
128 | } |
---|