/
AddExistedStoryActionTest.java
246 lines (196 loc) · 6.89 KB
/
AddExistedStoryActionTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
package ntut.csie.ezScrum.web.action.backlog;
import java.io.File;
import ntut.csie.ezScrum.issue.sql.service.core.Configuration;
import ntut.csie.ezScrum.refactoring.manager.ProjectManager;
import ntut.csie.ezScrum.test.CreateData.CreateProductBacklog;
import ntut.csie.ezScrum.test.CreateData.CreateProject;
import ntut.csie.ezScrum.test.CreateData.CreateSprint;
import ntut.csie.ezScrum.test.CreateData.InitialSQL;
import ntut.csie.ezScrum.web.dataObject.ProjectObject;
import ntut.csie.ezScrum.web.dataObject.StoryObject;
import ntut.csie.ezScrum.web.logic.SprintBacklogLogic;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import servletunit.struts.MockStrutsTestCase;
public class AddExistedStoryActionTest extends MockStrutsTestCase {
private CreateProject mCP;
private CreateSprint mCS;
private CreateProductBacklog mCPB;
private Configuration mConfig;
private ProjectObject mProject;
private int mStoriesCount = 5;
public AddExistedStoryActionTest(String testMethod) {
super(testMethod);
}
@Before
public void setUp() throws Exception {
mConfig = new Configuration();
mConfig.setTestMode(true);
mConfig.save();
// 初始化 SQL
InitialSQL ini = new InitialSQL(mConfig);
ini.exe();
// create project
mCP = new CreateProject(1);
mCP.exeCreate();
// create sprint
mCS = new CreateSprint(1, mCP);
mCS.exe();
// create story
mCPB = new CreateProductBacklog(mStoriesCount, mCP);
mCPB.exe();
mProject = mCP.getAllProjects().get(0);
super.setUp();
// 設定讀取的 struts-config 檔案路徑
setContextDirectory(new File(mConfig.getBaseDirPath() + "/WebContent"));
setServletConfigFile("/WEB-INF/struts-config.xml");
setRequestPathInfo("/addExistedStory");
// ============= release ==============
ini = null;
}
@After
public void tearDown() throws Exception {
// 初始化 SQL
InitialSQL ini = new InitialSQL(mConfig);
ini.exe();
// 刪除測試檔案
ProjectManager projectManager = new ProjectManager();
projectManager.deleteAllProject();
mConfig.setTestMode(false);
mConfig.save();
// ============= release ==============
ini = null;
mCP = null;
mCPB = null;
mConfig = null;
projectManager = null;
super.tearDown();
}
/**
* test add 5 stories to sprint#1
*/
@Test
public void testAddExistedStory1() {
long sprintId = mCS.getSprintsId().get(0);
String[] storiesId = new String[mStoriesCount];
for (int i = 0; i < mStoriesCount; i++) {
StoryObject story = mCPB.getStories().get(i);
storiesId[i] = Long.toString(story.getId());
}
// ================== set parameter info ====================
addRequestParameter("releaseID", "");
addRequestParameter("sprintID", String.valueOf(sprintId));
addRequestParameter("selects", storiesId);
// ================ set session info ========================
request.getSession().setAttribute("UserSession",
mConfig.getUserSession());
request.getSession().setAttribute("Project", mProject);
// ================ set session info ========================
// SessionManager 會對URL的參數作分析 ,未帶入此參數無法存入 session
request.setHeader("Referer", "?PID=" + mProject.getName());
// 執行 action
actionPerform();
// 驗證回傳 path
verifyForwardPath(null);
verifyForward(null);
verifyNoActionErrors();
for (StoryObject story : mCPB.getStories()) {
story.reload();
assertEquals(sprintId, story.getSprintId());
}
}
/**
* Add not existed story to sprint#1
*/
@Test
public void testAddExistedStory2() {
long sprintId = mCS.getSprintsId().get(0);
String[] storiesId = {"10"};
// ================== set parameter info ====================
addRequestParameter("releaseID", "");
addRequestParameter("sprintID", String.valueOf(sprintId));
addRequestParameter("selects", storiesId);
// ================ set session info ========================
request.getSession().setAttribute("UserSession",
mConfig.getUserSession());
request.getSession().setAttribute("Project", mProject);
// ================ set session info ========================
// SessionManager 會對URL的參數作分析 ,未帶入此參數無法存入 session
request.setHeader("Referer", "?PID=" + mProject.getName());
// 執行 action
actionPerform();
// 驗證回傳 path
verifyForwardPath(null);
verifyForward(null);
verifyNoActionErrors();
StoryObject story = StoryObject.get(10);
assertNull(story);
assertEquals(0, StoryObject.getStoriesBySprintId(sprintId).size());
}
/**
* Add existed stories to not existed sprint
*/
@Test
public void testAddExistedStory3() {
long sprintId = 2;
String[] storiesId = new String[mStoriesCount];
for (int i = 0; i < mStoriesCount; i++) {
StoryObject story = mCPB.getStories().get(i);
storiesId[i] = Long.toString(story.getId());
}
// ================== set parameter info ====================
addRequestParameter("releaseID", "");
addRequestParameter("sprintID", String.valueOf(sprintId));
addRequestParameter("selects", storiesId);
// ================ set session info ========================
request.getSession().setAttribute("UserSession",
mConfig.getUserSession());
request.getSession().setAttribute("Project", mProject);
// ================ set session info ========================
// SessionManager 會對URL的參數作分析 ,未帶入此參數無法存入 session
request.setHeader("Referer", "?PID=" + mProject.getName());
// 執行 action
actionPerform();
// 驗證回傳 path
verifyForwardPath(null);
verifyForward(null);
verifyNoActionErrors();
SprintBacklogLogic sprintBacklogLogic = new SprintBacklogLogic(mProject, sprintId);
assertNull(sprintBacklogLogic.getSprintBacklogMapper());
for (StoryObject story : mCPB.getStories()) {
assertEquals(-1, story.getSprintId());
}
}
/**
* Add existed stories to not existed sprint
*/
@Test
public void testAddExistedStory4() {
String[] storiesId = new String[mStoriesCount];
for (int i = 0; i < mStoriesCount; i++) {
StoryObject story = mCPB.getStories().get(i);
storiesId[i] = Long.toString(story.getId());
}
// ================== set parameter info ====================
addRequestParameter("releaseID", "");
addRequestParameter("sprintID", "fsdfholsdhfsl");
addRequestParameter("selects", storiesId);
// ================ set session info ========================
request.getSession().setAttribute("UserSession",
mConfig.getUserSession());
request.getSession().setAttribute("Project", mProject);
// ================ set session info ========================
// SessionManager 會對URL的參數作分析 ,未帶入此參數無法存入 session
request.setHeader("Referer", "?PID=" + mProject.getName());
// 執行 action
actionPerform();
// 驗證回傳 path
verifyForwardPath(null);
verifyForward(null);
verifyNoActionErrors();
for (StoryObject story : mCPB.getStories()) {
assertEquals(-1, story.getSprintId());
}
}
}