1 /**
2 * Copyright 2005-2006 the original author or authors.
3 *
4 * Licensed under the Gnu General Pubic License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/gpl-license.php
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the Gnu General Public License for more details.
14 */
15 package org.figure8.join.businessobjects.commons;
16
17 import junit.framework.Test;
18 import junit.framework.TestCase;
19 import junit.framework.TestSuite;
20 /**
21 * JUnit test case for testing Step domain object
22 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
23 * @version $Revision: 1.3 $
24 */
25 public class StepTest extends TestCase{
26
27
28
29 /** Default constructor. Build a test case using a name. */
30 public StepTest(String testName){
31 super(testName);
32 }
33
34
35
36
37 /**
38 * Make this class a TestSuite.
39 * @return A TestSuite containing this TestCase.
40 */
41 public static Test suite(){
42 TestSuite suite = new TestSuite(StepTest.class);
43 return suite;
44 }
45
46
47
48
49 /** Test the chaining of step for defining a process */
50 public void testStepChaining(){
51
52 Step step1 = new Step("foo", 1);
53 Step step2 = new Step("bar", 2);
54 Step step3 = new Step("foobar", 3);
55 step2.setPreviousStep(step1);
56 step3.setPreviousStep(step2);
57
58 assertTrue("Step 2 has correct previous step", step2.getPreviousStep() == step1);
59 assertTrue("Step 3 has correct previous step", step3.getPreviousStep() == step2);
60 assertTrue("Step 1 has correct next step", step1.getNextStep() == step2);
61 assertTrue("Step 2 has correct next step", step2.getNextStep() == step3);
62 }
63
64 /** Test the insertion of step into chain */
65 public void testStepInsertion(){
66
67 Step step1 = new Step("foo", 1);
68 Step step2 = new Step("bar", 2);
69 Step step3 = new Step("foobar", 3);
70 step2.setPreviousStep(step1);
71 step3.setPreviousStep(step2);
72
73 Step step4 = new Step("newbar", 2);
74 step2.shiftPosition();
75 step4.setPreviousStep(step2.getPreviousStep());
76 step2.setPreviousStep(step4);
77
78 assertEquals("Step 2 has correct position", 3, step2.getPosition());
79 assertEquals("Step 3 has correct position", 4, step3.getPosition());
80 assertTrue("Step 4 has correct previous step", step4.getPreviousStep() == step1);
81 assertTrue("Step 2 has correct previous step", step2.getPreviousStep() == step4);
82 assertTrue("Step 3 has correct previous step", step3.getPreviousStep() == step2);
83 assertTrue("Step 1 has correct next step", step1.getNextStep() == step4);
84 assertTrue("Step 4 has correct next step", step4.getNextStep() == step2);
85 assertTrue("Step 2 has correct next step", step2.getNextStep() == step3);
86 }
87 }