1 5 package org.exoplatform.services.grammar.wiki.test; 6 7 import java.util.HashMap ; 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 19 public class TestWikiParser extends BasicTestCase { 20 private WikiEngineService service_ ; 21 public TestWikiParser(String name) { 22 super(name); 23 } 24 25 public void setUp() throws Exception { 26 PortalContainer pcontainer = PortalContainer.getInstance() ; 27 service_ = (WikiEngineService) pcontainer.getComponentInstanceOfType(WikiEngineService.class) ; 28 } 29 30 public void tearDown() throws Exception { 31 } 32 33 public void testParsingContext() throws Exception { 34 String 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 { 44 String text = "smiley :-) :-( :-D :-)))" ; 45 System.out.println(service_.toXHTML(text)) ; 46 } 47 48 public void testList() throws Exception { 49 String 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 { 63 String 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 { 71 String 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 { 79 String 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 { 87 String text = "text: {text}this is text{text} end" ; 88 System.out.println(service_.toXHTML(text)) ; 89 } 90 91 public void testJavaHandler() throws Exception { 92 String text = "text: {java}this is text{java} end" ; 93 System.out.println(service_.toXHTML(text)) ; 94 } 95 96 public void testLink() throws Exception { 97 String 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 { 102 String 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 { 109 String [] 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 [ENTRY] ; 120 nums = new int[ENTRY] ; 121 HashMap map = new HashMap (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 message, long start , long end) { 138 System.out.println(message + " in " + (end -start) + "ms") ; 139 } 140 } | Popular Tags |