1 17 package org.alfresco.util; 18 19 import junit.framework.TestCase; 20 21 26 public class SearchLanguageConversionTest extends TestCase 27 { 28 31 private static final String BAD_STRING = 32 "\\ | ! \" £ " + 33 "$ % ^ & * ( " + 34 ") _ { } [ ] " + 35 "@ # ~ ' : ; " + 36 ", . < > + ? " + 37 "/ \\\\ \\* \\? \\_"; 38 39 public void testEscapeXPathLike() 40 { 41 String good = SearchLanguageConversion.escapeForXPathLike(BAD_STRING); 42 assertEquals("Escaping for xpath failed", 43 "\\\\ | ! \" £ " + 44 "$ \\% ^ & * ( " + 45 ") \\_ { } [ ] " + 46 "@ # ~ ' : ; " + 47 ", . < > + ? " + 48 "/ \\\\\\\\ \\\\* \\\\? \\\\\\_", 49 good); 50 } 51 52 public void testEscapeRegex() 53 { 54 String good = SearchLanguageConversion.escapeForRegex(BAD_STRING); 55 assertEquals("Escaping for regex failed", 56 "\\\\ \\| ! \" £ " + 57 "\\$ % \\^ & \\* \\( " + 58 "\\) _ \\{ \\} [ ] " + 59 "@ # ~ ' : ; " + 60 ", \\. < > \\+ \\? " + 61 "/ \\\\\\\\ \\\\\\* \\\\\\? \\\\_", 62 good); 63 } 64 65 public void testEscapeLucene() 66 { 67 String good = SearchLanguageConversion.escapeForLucene(BAD_STRING); 68 assertEquals("Escaping for regex failed", 69 "\\\\ | \\! \\\" £ " + 70 "$ % \\^ & \\* \\( " + 71 "\\) _ \\{ \\} \\[ \\] " + 72 "@ # \\~ ' \\: ; " + 73 ", . < > \\+ \\? " + 74 "/ \\\\\\\\ \\\\\\* \\\\\\? \\\\_", 75 good); 76 } 77 78 public void testConvertXPathLikeToRegex() 79 { 80 String good = SearchLanguageConversion.convertXPathLikeToRegex(BAD_STRING); 81 assertEquals("XPath like to regex failed", 82 "(?s)\\ \\| ! \" £ " + 83 "\\$ .* \\^ & \\* \\( " + 84 "\\) . \\{ \\} [ ] " + 85 "@ # ~ ' : ; " + 86 ", \\. < > \\+ \\? " + 87 "/ \\\\ \\* \\? \\_", 88 good); 89 } 90 91 public void testConvertXPathLikeToLucene() 92 { 93 String good = SearchLanguageConversion.convertXPathLikeToLucene(BAD_STRING); 94 assertEquals("XPath like to regex failed", 95 "\\ | \\! \\\" £ " + 96 "$ * \\^ & \\* \\( " + 97 "\\) ? \\{ \\} \\[ \\] " + 98 "@ # \\~ ' \\: ; " + 99 ", . < > \\+ \\? " + 100 "/ \\\\ \\* \\? \\_", 101 good); 102 } 103 } 104 | Popular Tags |