KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > rendering > plugins > SmileysTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. For additional information regarding
15  * copyright in this work, please see the NOTICE file in the top level
16  * directory of this distribution.
17  */

18
19 package org.apache.roller.ui.rendering.plugins;
20
21 import junit.framework.Test;
22 import junit.framework.TestSuite;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.roller.TestUtils;
26 import org.apache.roller.pojos.UserData;
27 import org.apache.roller.pojos.WebsiteData;
28 import org.apache.roller.ui.authoring.struts.actions.WeblogEntryActionTest;
29 import org.apache.roller.ui.ServletTestBase;
30
31
32 /**
33  * Test smileys plugin.
34  */

35 public class SmileysTest extends ServletTestBase {
36     
37     private static Log log = LogFactory.getLog(WeblogEntryActionTest.class);
38     
39     private WebsiteData testWeblog = null;
40     private UserData testUser = null;
41     
42     
43     public SmileysTest() {
44         super();
45     }
46     
47     
48     public static Test suite() {
49         return new TestSuite(SmileysTest.class);
50     }
51     
52     
53     /**
54      * All tests in this suite require a user and a weblog.
55      */

56     public void setUp() throws Exception JavaDoc {
57         super.setUp();
58         try {
59             testUser = TestUtils.setupUser("bkmrkTestUser");
60             testWeblog = TestUtils.setupWeblog("bkmrkTestWeblog", testUser);
61             TestUtils.endSession(true);
62         } catch (Exception JavaDoc ex) {
63             log.error(ex);
64             throw new Exception JavaDoc("Test setup failed", ex);
65         }
66     }
67     
68     
69     public void tearDown() throws Exception JavaDoc {
70         super.tearDown();
71         try {
72             TestUtils.teardownWeblog(testWeblog.getId());
73             TestUtils.teardownUser(testUser.getId());
74             TestUtils.endSession(true);
75         } catch (Exception JavaDoc ex) {
76             log.error(ex);
77             throw new Exception JavaDoc("Test teardown failed", ex);
78         }
79     }
80     
81     
82     public void testSmileEmoticon() throws Exception JavaDoc {
83         doFilters();
84         
85         SmileysPlugin plugin = new SmileysPlugin();
86         plugin.init(testWeblog);
87         assertTrue( SmileysPlugin.smileyPatterns.length > 0 );
88         
89         String JavaDoc test = "put on a happy :-) face";
90         String JavaDoc expected =
91                 "put on a happy <img SRC=\"http://localhost:8080/roller/images/smileys/smile.gif" +
92                 "\" class=\"smiley\" alt=\":-)\" title=\":-)\" /> face";
93         String JavaDoc result = plugin.render(null, test);
94         assertEquals(expected, result);
95     }
96     
97 }
98
Popular Tags