KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > grammar > wiki > test > TestWikiParser


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.grammar.wiki.test;
6
7 import java.util.HashMap JavaDoc;
8 import net.sf.cglib.util.StringSwitcher;
9 import org.exoplatform.container.PortalContainer;
10 import org.exoplatform.services.grammar.wiki.WikiEngineService;
11 import org.exoplatform.test.BasicTestCase;
12 /**
13  * Thu, May 15, 2003 @
14  * @author: Tuan Nguyen
15  * @version: $Id: TestBBCodeParser.java,v 1.1 2004/10/20 14:19:00 tuan08 Exp $
16  * @since: 0.0
17  * @email: tuan08@yahoo.com
18  */

19 public class TestWikiParser extends BasicTestCase {
20   private WikiEngineService service_ ;
21   public TestWikiParser(String JavaDoc name) {
22     super(name);
23   }
24
25   public void setUp() throws Exception JavaDoc {
26     PortalContainer pcontainer = PortalContainer.getInstance() ;
27     service_ = (WikiEngineService) pcontainer.getComponentInstanceOfType(WikiEngineService.class) ;
28   }
29
30   public void tearDown() throws Exception JavaDoc {
31   }
32   
33   public void testParsingContext() throws Exception JavaDoc {
34     String JavaDoc text = "this is a ssssaa--test strike-- , **bold** ~~test italic~~ ---this is test--~~--" +
35                   "\n 1.1 title **bold** *cdsncjhjdsvjfdvjkj vfdnvfdvj --* **tes bold --strike**" +
36                   "\n 1. this is a test" +
37                   "\n a. this is an __underline__ test" +
38                   "\n i. title ~~italic~~ abd fdnvbjk" +
39                   "\n i. *lllllllllllllllllllllllllv bhdfhvfhdbv" ;
40     System.out.println(service_.toXHTML(text)) ;
41   }
42   
43   public void testSmiley() throws Exception JavaDoc {
44     String JavaDoc text = "smiley :-) :-( :-D :-)))" ;
45     System.out.println(service_.toXHTML(text)) ;
46   }
47   
48   public void testList() throws Exception JavaDoc {
49     String JavaDoc text = "\n * this is a test" +
50                   "\n ** this is a test 2 stars " +
51                   "\n ** this is a test 2 stars" +
52                   "\n *** this is a test 3 stars" +
53                   "\n * this is a test 1 stars " +
54                   "\n ** this is a test 2 stars" +
55                   "\n\n------------------------------------------------" +
56                   "\n ** this is a test 2 stars " +
57                   "\n ** this is a **bold** test 2 stars" +
58                   "\n *** this is a test 3 stars" ;
59     System.out.println(service_.toXHTML(text)) ;
60   }
61   
62   public void testEnumerated() throws Exception JavaDoc {
63     String JavaDoc text = "Test Enumerated" +
64                   "\n 1. this is a test 1 stars " +
65                   "\n 1. this is a test 2 stars" +
66                   "\n 1. this is a test 3 stars" ;
67     System.out.println(service_.toXHTML(text)) ;
68   }
69   
70   public void testAlphabeticalEnumerated() throws Exception JavaDoc {
71     String JavaDoc text = "Test Roman Enumerated" +
72                   "\n a. this is a test 1 stars " +
73                   "\n a. this is a test 2 stars" +
74                   "\n a. this is a test 3 stars" ;
75     System.out.println(service_.toXHTML(text)) ;
76   }
77   
78   public void testRomanEnumerated() throws Exception JavaDoc {
79     String JavaDoc text = "Test Roman Enumerated" +
80                   "\n i. this is a test i. " +
81                   "\n i. this is a test ii. " +
82                   "\n i. this is a test iii." ;
83     System.out.println(service_.toXHTML(text)) ;
84   }
85   
86   public void testTextHandler() throws Exception JavaDoc {
87     String JavaDoc text = "text: {text}this is text{text} end" ;
88     System.out.println(service_.toXHTML(text)) ;
89   }
90   
91   public void testJavaHandler() throws Exception JavaDoc {
92     String JavaDoc text = "text: {java}this is text{java} end" ;
93     System.out.println(service_.toXHTML(text)) ;
94   }
95   
96   public void testLink() throws Exception JavaDoc {
97     String JavaDoc text = "test link [www.yahoo.com] , [yahoo>www.yahoo.com]" ;
98     System.out.println(service_.toXHTML(text)) ;
99   }
100   
101   public void testTitle() throws Exception JavaDoc {
102     String JavaDoc text = "Test Title" +
103                   "\n 1 this is a title 1 " +
104                   "\n 1.1 this is a title 1.1 " ;
105     System.out.println(service_.toXHTML(text)) ;
106   }
107   
108   public void testStwitcher() throws Exception JavaDoc {
109     String JavaDoc[] keys = {"abc", "def" , "xgy" , "agf", "test1", "test2", "test3", "verylonglongtext"} ;
110     int[] nums = {1, 2, 3, 4, 5, 6, 7, 8} ;
111     StringSwitcher switcher = StringSwitcher.create(keys, nums, false) ;
112     assertEquals("abc , expect 1: ", 1, switcher.intValue("abc") ) ;
113     assertEquals("def , expect 2: ", 2, switcher.intValue("def")) ;
114     assertEquals("xyg , expect 3: ", 3, switcher.intValue("xgy")) ;
115     assertEquals("agf , expect 4: ", 4, switcher.intValue("agf")) ;
116     assertEquals("aaaf , expect -1: ", -1, switcher.intValue("aaaf")) ;
117     
118     int ENTRY = 50 ;
119     keys = new String JavaDoc[ENTRY] ;
120     nums = new int[ENTRY] ;
121     HashMap JavaDoc map = new HashMap JavaDoc(100) ;
122     for(int i = 0; i < ENTRY; i++) {
123       keys[i] = "longmethod" + i ;
124       nums[i] = i ;
125       map.put(keys[i], keys[i]) ;
126     }
127     switcher = StringSwitcher.create(keys, nums, false) ;
128     int LOOP = 20000 ;
129     long start = System.currentTimeMillis() ;
130     for (int i = 0; i < LOOP; i++ ) map.get("longmethod21") ;
131     pintMessage("MAP ", start , System.currentTimeMillis()) ;
132     start = System.currentTimeMillis() ;
133     for (int i = 0; i < LOOP; i++ ) switcher.intValue("longmethod21") ;
134     pintMessage("SWITCHER ", start , System.currentTimeMillis()) ;
135   }
136
137   private void pintMessage(String JavaDoc message, long start , long end) {
138     System.out.println(message + " in " + (end -start) + "ms") ;
139   }
140 }
Popular Tags