lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject svn commit: r822889 - /lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java
Date Wed, 07 Oct 2009 20:08:54 GMT
Author: shalin
Date: Wed Oct  7 20:08:53 2009
New Revision: 822889

URL: http://svn.apache.org/viewvc?rev=822889&view=rev
Log:
Use NOW/DAY instead of NOW to avoid false failures

Modified:
    lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java

Modified: lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java?rev=822889&r1=822888&r2=822889&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java
(original)
+++ lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java
Wed Oct  7 20:08:53 2009
@@ -18,6 +18,7 @@
 
 import org.junit.Assert;
 import org.junit.Test;
+import org.apache.solr.util.DateMathParser;
 
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -68,8 +69,7 @@
   @Test
   public void dateNamespaceWithValue() {
     VariableResolverImpl vri = new VariableResolverImpl();
-    ContextImpl context = new ContextImpl(null,vri, null, Context.FULL_DUMP, Collections.EMPTY_MAP,
null,null);
-    vri.context = context;
+    vri.context = new ContextImpl(null,vri, null, Context.FULL_DUMP, Collections.EMPTY_MAP,
null,null);
     vri.addNamespace("dataimporter.functions", EvaluatorBag
             .getFunctionsNamespace(Collections.EMPTY_LIST, null));
     Map<String, Object> ns = new HashMap<String, Object>();
@@ -81,16 +81,18 @@
   }
 
   @Test
-  public void dateNamespaceWithExpr() {
+  public void dateNamespaceWithExpr() throws Exception {
     VariableResolverImpl vri = new VariableResolverImpl();
-    ContextImpl context = new ContextImpl(null,vri, null, Context.FULL_DUMP, Collections.EMPTY_MAP,
null,null);
-    vri.context = context;
+    vri.context = new ContextImpl(null,vri, null, Context.FULL_DUMP, Collections.EMPTY_MAP,
null,null);
     vri.addNamespace("dataimporter.functions", EvaluatorBag
             .getFunctionsNamespace(Collections.EMPTY_LIST,null));
-    String s = vri
-            .replaceTokens("${dataimporter.functions.formatDate('NOW','yyyy-MM-dd HH:mm')}");
-    Assert.assertEquals(new SimpleDateFormat("yyyy-MM-dd HH:mm")
-            .format(new Date()), s);
+
+    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+    format.setTimeZone(TimeZone.getTimeZone("UTC"));
+    DateMathParser dmp = new DateMathParser(TimeZone.getDefault(), Locale.getDefault());
+
+    String s = vri.replaceTokens("${dataimporter.functions.formatDate('NOW/DAY','yyyy-MM-dd
HH:mm')}");
+    Assert.assertEquals(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(dmp.parseMath("/DAY")),
s);
   }
 
   @Test
@@ -112,21 +114,25 @@
   }
 
   @Test
-  public void testFunctionNamespace1() {
+  public void testFunctionNamespace1() throws Exception {
     final VariableResolverImpl resolver = new VariableResolverImpl();
-    ContextImpl context = new ContextImpl(null,resolver, null, Context.FULL_DUMP, Collections.EMPTY_MAP,
null,null);
-    resolver.context = context;
+    resolver.context = new ContextImpl(null,resolver, null, Context.FULL_DUMP, Collections.EMPTY_MAP,
null,null);
     final List<Map<String ,String >> l = new ArrayList<Map<String, String>>();
     Map<String ,String > m = new HashMap<String, String>();
     m.put("name","test");
     m.put("class",E.class.getName());
     l.add(m);
+
+    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+    format.setTimeZone(TimeZone.getTimeZone("UTC"));
+    DateMathParser dmp = new DateMathParser(TimeZone.getDefault(), Locale.getDefault());
+
     resolver.addNamespace("dataimporter.functions", EvaluatorBag
             .getFunctionsNamespace(l,null));
     String s = resolver
-            .replaceTokens("${dataimporter.functions.formatDate('NOW','yyyy-MM-dd HH:mm')}");
+            .replaceTokens("${dataimporter.functions.formatDate('NOW/DAY','yyyy-MM-dd HH:mm')}");
     Assert.assertEquals(new SimpleDateFormat("yyyy-MM-dd HH:mm")
-            .format(new Date()), s);
+            .format(dmp.parseMath("/DAY")), s);
     Assert.assertEquals("Hello World", resolver
             .replaceTokens("${dataimporter.functions.test('TEST')}"));
   }



Mime
View raw message