1 package com.atlassian.config.wizard;
2
3 import junit.framework.Assert;
4 import junit.framework.TestCase;
5
6
7
8 public class WizardTestCase extends TestCase
9 {
10 private int saves;
11
12 public void setUp()
13 {
14 saves = 0;
15 }
16
17 public void testSimpleWizardSetup() throws Exception
18 {
19 SetupWizard wizard = new SetupWizard();
20
21
22 TestSetupStep step1 = new TestSetupStep("Step 1", "Setp1-action");
23 TestSetupStep step2 = new TestSetupStep("Step 2", "Setp2-action");
24 wizard.addStep(step1);
25 wizard.addStep(step2);
26 wizard.setSaveStrategy(new SaveStrategy()
27 {
28 public void save(SetupWizard setupWizard)
29 {
30 saves++;
31 }
32 });
33 wizard.start();
34
35 assertNotNull(wizard.getCurrentStep());
36 Assert.assertEquals("Step 1", wizard.getCurrentStep().getName());
37 wizard.next();
38
39 assertNotNull(wizard.getCurrentStep());
40 Assert.assertEquals("Step 2", wizard.getCurrentStep().getName());
41
42 wizard.finish();
43
44 assertEquals(1, step1.getStart());
45 assertEquals(1, step1.getNext());
46 assertEquals(3, saves);
47 }
48
49 public class TestSetupStep extends DefaultSetupStep
50 {
51 int next = 0;
52 int start = 0;
53
54 public TestSetupStep(String name, String actionName)
55 {
56 super();
57 setName(name);
58 setActionName(actionName);
59 }
60
61 public void onNext()
62 {
63 next++;
64 }
65
66 public void onStart()
67 {
68 start++;
69 }
70
71 public int getNext()
72 {
73 return next;
74 }
75
76 public int getStart()
77 {
78 return start;
79 }
80 }
81 }