KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > modules > workflow > WorkFlowTest


1 /*
2  * Created on May 19, 2006
3  */

4 package com.openedit.modules.workflow;
5
6 import java.util.List JavaDoc;
7
8 import com.openedit.BaseTestCase;
9 import com.openedit.WebPageRequest;
10 import com.openedit.modules.html.EditorSession;
11 import com.openedit.modules.html.HtmlEditorModule;
12 import com.openedit.page.Page;
13 import com.openedit.users.User;
14
15 public class WorkFlowTest extends BaseTestCase
16 {
17     public void testEditDraft() throws Exception JavaDoc
18     {
19         WebPageRequest req = getFixture().createPageRequest("/index.html");
20         User user = getFixture().getUserManager().getUser("usesdraft");
21         req.setUser(user);
22         HtmlEditorModule mod = (HtmlEditorModule)getModule("HtmlEditor");
23
24         req.setRequestParameter("editPath", "/index.html");
25         mod.loadView(req);
26         
27         EditorSession ses = (EditorSession)req.getPageValue("editorSession");
28         
29         assertEquals( "/index.draft.html",ses.getEditPath());
30         req.setRequestParameter("editPath", ses.getEditPath());
31         req.setRequestParameter("saveas", ses.getEditPath());
32         req.setRequestParameter("content", "New Draft Content");
33         mod.save(req);
34         
35         //check that there is a file name .draft
36
Page page = getPage("/index.draft.html");
37         assertTrue("draft missing", page.exists() );
38         
39         //TODO: Add draft notice and approve button to the edit toolbar
40

41         //TODO: Make a page that lists all the drafts with links to them and version message information
42
//TODO: Add way to go add permission to self if the user is approver. Add toolbar button
43

44         //TODO: Add diff view, nah use the versions screen
45
//TODO: Add deny? Nah
46
}
47     public void testListDrafts() throws Exception JavaDoc
48     {
49         WebPageRequest req = getFixture().createPageRequest();
50         
51         WorkFlowModule mod = (WorkFlowModule)getModule("WorkFlow");
52         List JavaDoc drafts = mod.listDrafts(req);
53         
54
55         assertTrue("Missing list " + drafts.size(), drafts.size() > 0);
56         
57     }
58     
59     public void testApprove() throws Exception JavaDoc
60     {
61         WebPageRequest req = getFixture().createPageRequest("/index.draft.html");
62         
63         WorkFlowModule mod = (WorkFlowModule)getModule("WorkFlow");
64         req.setRequestParameter("editPath", "/index.draft.html");
65         req.setRequestParameter("origURL", "/index.html");
66         mod.approve(req);
67         
68         assertTrue("Did not redirect", req.hasRedirected() );
69     }
70
71     public void testChangeDraftMode() throws Exception JavaDoc
72     {
73         WebPageRequest req = getFixture().createPageRequest();
74         
75         WorkFlowModule mod = (WorkFlowModule)getModule("WorkFlow");
76         assertFalse("Was in draft mode", req.getUser().hasProperty("oe.edit.draftmode"));
77         mod.flipDraftMode(req);
78         assertTrue("Was Not in draft mode", req.getUser().hasProperty("oe.edit.draftmode"));
79         
80     }
81     
82     public void testChangeStatus() throws Exception JavaDoc
83     {
84 // Page levelsO = getFixture().getPageManager().getPage("/openedit/settings.xml");
85
// Page levels = getFixture().getPageManager().getPage("/openedit/workflow/settings.xml");
86
// getFixture().getPageManager().copyPage(levelsO, levels);
87

88         Page live = getFixture().getPageManager().getPage("/index.html");
89         Page draft = getFixture().getPageManager().getPage("/index.draft.html");
90         getFixture().getPageManager().copyPage(live, draft);
91
92         
93         User level1user = getFixture().getUserManager().getUser("level1user");
94         WebPageRequest req = getFixture().createPageRequest();
95         req.setUser(level1user);
96         req.setRequestParameter("editPath", "/index.draft.html");
97         req.setRequestParameter("origURL", "/index.html");
98         WorkFlowModule mod = (WorkFlowModule)getModule("WorkFlow");
99         mod.approve(req);
100
101         assertTrue( draft.exists() );
102         boolean nope = mod.getWorkFlow().canApprove(level1user, draft);
103         assertFalse( nope);
104
105         boolean yup = mod.getWorkFlow().canApprove(getFixture().getUserManager().getUser("admin"), draft);
106         assertTrue(yup);
107         //What will happen is the draft file will stay there while the status flag gets fliped to the
108
//next higher level or approved if no higher levels exist
109

110         
111         //Log in with some user with no level permissions
112
//Create a file called /openedit/workflow/levels.xml with three levels 1, 2, 3
113
//Edit a page to create a draft as the first level from the level list
114
}
115 }
116
Popular Tags