/** Test method for {@link EvaluatorBag#getDateFormatEvaluator()}. */
  @Test
  public void testGetDateFormatEvaluator() {
    Evaluator dateFormatEval = EvaluatorBag.getDateFormatEvaluator();
    ContextImpl context =
        new ContextImpl(null, resolver, null, Context.FULL_DUMP, Collections.EMPTY_MAP, null, null);
    Context.CURRENT_CONTEXT.set(context);
    try {
      Calendar calendar = new GregorianCalendar();
      calendar.add(Calendar.DAY_OF_YEAR, -2);

      assertEquals(
          new SimpleDateFormat("yyyy-MM-dd HH:mm").format(calendar.getTime()),
          dateFormatEval.evaluate("'NOW-2DAYS','yyyy-MM-dd HH:mm'", Context.CURRENT_CONTEXT.get()));

      calendar = new GregorianCalendar();
      Date date = calendar.getTime();

      Map<String, Object> map = new HashMap<String, Object>();
      map.put("key", date);
      resolver.addNamespace("A", map);

      assertEquals(
          new SimpleDateFormat("yyyy-MM-dd HH:mm").format(date),
          dateFormatEval.evaluate("A.key, 'yyyy-MM-dd HH:mm'", Context.CURRENT_CONTEXT.get()));
    } finally {
      Context.CURRENT_CONTEXT.remove();
    }
  }
 @Test
 public void parseParams() {
   Map m = new HashMap();
   m.put("b", "B");
   VariableResolverImpl vr = new VariableResolverImpl();
   vr.addNamespace("a", m);
   List l = EvaluatorBag.parseParams(" 1 , a.b, 'hello!', 'ds,o,u\'za',", vr);
   Assert.assertEquals(new Double(1), l.get(0));
   Assert.assertEquals("B", ((EvaluatorBag.VariableWrapper) l.get(1)).resolve());
   Assert.assertEquals("hello!", l.get(2));
   Assert.assertEquals("ds,o,u'za", l.get(3));
 }
Esempio n. 3
0
 public DocBuilder(
     DataImporter dataImporter, SolrWriter writer, DataImporter.RequestParams reqParams) {
   INSTANCE.set(this);
   this.dataImporter = dataImporter;
   this.writer = writer;
   DataImporter.QUERY_COUNT.set(importStatistics.queryCount);
   requestParameters = reqParams;
   verboseDebug = requestParameters.debug && requestParameters.verbose;
   functionsNamespace =
       EvaluatorBag.getFunctionsNamespace(this.dataImporter.getConfig().functions, this);
   persistedProperties = writer.readIndexerProperties();
 }
 @Test
 public void testEscapeSolrQueryFunction() {
   final VariableResolverImpl resolver = new VariableResolverImpl();
   ContextImpl context =
       new ContextImpl(null, resolver, null, Context.FULL_DUMP, Collections.EMPTY_MAP, null, null);
   Context.CURRENT_CONTEXT.set(context);
   try {
     Map m = new HashMap();
     m.put("query", "c:t");
     resolver.addNamespace(
         "dataimporter.functions",
         EvaluatorBag.getFunctionsNamespace(Collections.EMPTY_LIST, null));
     resolver.addNamespace("e", m);
     String s = resolver.replaceTokens("${dataimporter.functions.escapeQueryChars(e.query)}");
     org.junit.Assert.assertEquals("c\\:t", s);
   } finally {
     Context.CURRENT_CONTEXT.remove();
   }
 }
 /** Test method for {@link EvaluatorBag#getUrlEvaluator()}. */
 @Test
 public void testGetUrlEvaluator() throws Exception {
   Evaluator urlEvaluator = EvaluatorBag.getUrlEvaluator();
   runTests(urlTests, urlEvaluator);
 }
 /** Test method for {@link EvaluatorBag#getSqlEscapingEvaluator()}. */
 @Test
 public void testGetSqlEscapingEvaluator() {
   Evaluator sqlEscaper = EvaluatorBag.getSqlEscapingEvaluator();
   runTests(sqlTests, sqlEscaper);
 }