1 package com.atlassian.plugins.codegen.modules.jira;
2
3 import com.atlassian.plugins.codegen.AbstractModuleCreatorTestCase;
4
5 import org.junit.Before;
6 import org.junit.Test;
7
8 import static org.junit.Assert.assertEquals;
9 import static org.junit.Assert.assertNotNull;
10
11
12
13
14 public class WebworkTest extends AbstractModuleCreatorTestCase<WebworkProperties>
15 {
16 protected ActionProperties action;
17 protected View successView;
18 protected ActionProperties action2;
19
20 public WebworkTest()
21 {
22 super("webwork1", new WebworkModuleCreator());
23 }
24
25 @Before
26 public void setupProps() throws Exception
27 {
28 setProps(new WebworkProperties("My Webwork"));
29
30 action = new ActionProperties(PACKAGE_NAME + ".ActionOne");
31 successView = new View("success", "templates/success.vm");
32 action.addView(successView);
33
34 props.addAction(action);
35
36 action2 = new ActionProperties(PACKAGE_NAME + ".ActionTwo");
37 }
38
39 @Test
40 public void singleActionClassFileIsGenerated() throws Exception
41 {
42 getSourceFile(PACKAGE_NAME, "ActionOne");
43 }
44
45 @Test
46 public void singleActionTestClassFileIsGenerated() throws Exception
47 {
48 getTestSourceFile(TEST_PACKAGE_NAME, "ActionOneTest");
49 }
50
51 @Test
52 public void secondActionClassFileIsGenerated() throws Exception
53 {
54 props.addAction(action2);
55
56 getSourceFile(PACKAGE_NAME, "ActionTwo");
57 }
58
59 @Test
60 public void secondActionTestClassFileIsGenerated() throws Exception
61 {
62 props.addAction(action2);
63
64 getTestSourceFile(TEST_PACKAGE_NAME, "ActionTwoTest");
65 }
66
67 @Test
68 public void actionHasName() throws Exception
69 {
70 assertEquals(action.getClassId().getFullName(), getGeneratedModule().selectSingleNode("actions/action/@name").getText());
71 }
72
73 @Test
74 public void actionHasAlias() throws Exception
75 {
76 assertEquals(action.getClassId().getName(), getGeneratedModule().selectSingleNode("actions/action/@alias").getText());
77 }
78
79 @Test
80 public void actionHasView() throws Exception
81 {
82 assertNotNull(getGeneratedModule().selectSingleNode("actions/action/view"));
83 }
84
85 @Test
86 public void viewHasName() throws Exception
87 {
88 assertEquals("success", getGeneratedModule().selectSingleNode("actions/action/view/@name").getText());
89 }
90
91 @Test
92 public void viewHasTemplatePath() throws Exception
93 {
94 assertEquals("templates/success.vm", getGeneratedModule().selectSingleNode("actions/action/view").getText());
95 }
96
97 @Test
98 public void viewFileIsGenerated() throws Exception
99 {
100 getResourceFile("templates", "success.vm");
101 }
102
103 @Test
104 public void secondViewIsAdded() throws Exception
105 {
106 View errorView = new View("error", "templates/error.vm");
107 action.addView(errorView);
108
109 assertEquals(2, getGeneratedModule().selectNodes("actions/action/view").size());
110 }
111
112 @Test
113 public void secondViewFileIsGenerated() throws Exception
114 {
115 View errorView = new View("error", "templates/error.vm");
116 action.addView(errorView);
117
118 getResourceFile("templates", "error.vm");
119 }
120 }