1 13 package info.magnolia.cms.taglibs.util; 14 15 import junit.framework.TestCase; 16 17 import org.apache.commons.lang.RandomStringUtils; 18 import org.apache.commons.lang.math.RandomUtils; 19 import org.apache.jackrabbit.core.query.xpath.TokenMgrError; 20 import org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder; 21 import org.apache.jackrabbit.name.NamespaceResolver; 22 import org.apache.log4j.Logger; 23 24 25 29 public class SimpleSearchTagTest extends TestCase { 30 31 34 private static Logger log = Logger.getLogger(SimpleSearchTagTest.class); 35 36 39 public void testGenerateXPathQuery() { 40 41 SimpleSearchTag tag = new SimpleSearchTag(); 42 tag.setQuery("AND test query AND path OR and OR join AND AND test AND OR"); 43 44 String xpath = tag.generateXPathQuery(); 45 log.debug(xpath); 46 47 try { 48 NamespaceResolver resolver = null; XPathQueryBuilder.createQuery(xpath, resolver); 50 } 51 catch (TokenMgrError e) { 52 fail("Invalid query: [" + xpath + "] " + e.getMessage()); 53 } 54 catch (Throwable e) { 55 } 57 } 58 59 62 public void testGenerateXPathQuerySmokeTest() { 63 64 SimpleSearchTag tag = new SimpleSearchTag(); 65 66 for (int j = 0; j < 100; j++) { 67 68 StringBuffer inputstring = new StringBuffer (100); 69 for (int u = 0; u < 10; u++) { 70 inputstring.append(RandomStringUtils.random(RandomUtils.nextInt(10))); 71 inputstring.append(" "); 72 inputstring.append(RandomStringUtils.randomAlphanumeric(RandomUtils.nextInt(10))); 73 inputstring.append(" "); 74 } 75 tag.setQuery(inputstring.toString()); 76 String xpath = tag.generateXPathQuery(); 77 log.debug(xpath); 78 79 try { 80 NamespaceResolver resolver = null; XPathQueryBuilder.createQuery(xpath, resolver); 82 } 83 catch (TokenMgrError e) { 84 fail("Invalid query: [" 85 + xpath 86 + "] " 87 + e.getMessage() 88 + ". Input query was: [" 89 + inputstring.toString() 90 + "]"); 91 } 92 catch (Throwable e) { 93 } 96 } 97 } 98 99 } 100 | Popular Tags |