01: package ru.emdev.EmForge.tests.comments;
02:
03: import static org.junit.Assert.assertEquals;
04: import static org.junit.Assert.fail;
05:
06: import java.util.Date;
07:
08: import org.apache.commons.logging.Log;
09: import org.apache.commons.logging.LogFactory;
10: import org.emforge.CommentService;
11: import org.emforge.EmForgeException;
12: import org.emforge.tests.BaseUnitTest;
13: import org.junit.Before;
14: import org.junit.Test;
15: import org.springframework.beans.factory.annotation.Autowired;
16:
17: import com.ecyrd.jspwiki.WikiContext;
18: import com.ecyrd.jspwiki.WikiEngine;
19: import com.ecyrd.jspwiki.WikiException;
20: import com.ecyrd.jspwiki.WikiPage;
21:
22: /** Tests for Comment Service
23: *
24: * @author akakunin
25: *
26: */
27: public class CommentTest extends BaseUnitTest {
28: protected final Log logger = LogFactory.getLog(getClass());
29:
30: @Autowired
31: private CommentService commentService;
32: @Autowired
33: private WikiEngine m_wikiEngine;
34:
35: @Before
36: public void onSetUpInTransaction() throws Exception {
37: authenticateUser("admin", "admin");
38: }
39:
40: @Test
41: public void testNonExistingPageComment() throws EmForgeException {
42: String testWikiPageName = "not existing wiki page";
43: try {
44: commentService.addComment(testWikiPageName, "Some text");
45: } catch (IllegalArgumentException iae) {
46: // it is ok - exception is generated
47: return;
48: }
49:
50: fail("Exception should be generated");
51: }
52:
53: /*
54: * skip until we can deploy new processDefs
55: */
56: public void testExistingProcessComment() {
57:
58: }
59:
60: /*
61: * skip until we can deploy new processDefs
62: */
63: public void testExistingTaskComment() {
64:
65: }
66:
67: @Test
68: public void testExistingWikiPageComment() throws EmForgeException {
69: WikiContext wikiContext = null;
70: String i_newPageName = "Main01";
71: String i_text = "Test text";
72: WikiPage newpage = null;
73:
74: if (m_wikiEngine.getPage(i_newPageName) == null) {
75: newpage = new WikiPage(m_wikiEngine, i_newPageName);
76: wikiContext = new WikiContext(m_wikiEngine, newpage);
77:
78: wikiContext.getPage().setAuthor("admin");
79: wikiContext.getPage().setLastModified(new Date());
80:
81: try {
82: m_wikiEngine.saveText(wikiContext, i_text);
83: } catch (WikiException e) {
84: logger.error(e);
85: }
86: } else {
87: logger
88: .info("Cannot create new page because the page with name"
89: + i_newPageName + "already exists");
90: }
91: final String message = "message";
92: commentService.addComment(i_newPageName, "message");
93: assertEquals(message,
94: commentService.getComments(i_newPageName)[0]
95: .getMessage());
96: }
97:
98: }
|