You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jd...@apache.org on 2012/11/19 17:55:08 UTC
svn commit: r1411305 -
/lucene/dev/branches/branch_4x/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestVariableResolver.java
Author: jdyer
Date: Mon Nov 19 16:55:08 2012
New Revision: 1411305
URL: http://svn.apache.org/viewvc?rev=1411305&view=rev
Log:
SOLR-4086: remove tabs
Modified:
lucene/dev/branches/branch_4x/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestVariableResolver.java
Modified: lucene/dev/branches/branch_4x/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestVariableResolver.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestVariableResolver.java?rev=1411305&r1=1411304&r2=1411305&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestVariableResolver.java (original)
+++ lucene/dev/branches/branch_4x/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestVariableResolver.java Mon Nov 19 16:55:08 2012
@@ -26,132 +26,141 @@ import java.util.*;
* <p>
* Test for VariableResolver
* </p>
- *
- *
+ *
+ *
* @since solr 1.3
*/
public class TestVariableResolver extends AbstractDataImportHandlerTestCase {
-
+
@Test
public void testSimpleNamespace() {
VariableResolver vri = new VariableResolver();
- Map<String, Object> ns = new HashMap<String, Object>();
+ Map<String,Object> ns = new HashMap<String,Object>();
ns.put("world", "WORLD");
vri.addNamespace("hello", ns);
assertEquals("WORLD", vri.resolve("hello.world"));
}
-
+
@Test
- public void testDefaults(){
+ public void testDefaults() {
// System.out.println(System.setProperty(TestVariableResolver.class.getName(),"hello"));
- System.setProperty(TestVariableResolver.class.getName(),"hello");
- // System.out.println("s.gP()"+ System.getProperty(TestVariableResolver.class.getName()));
-
+ System.setProperty(TestVariableResolver.class.getName(), "hello");
+ // System.out.println("s.gP()"+
+ // System.getProperty(TestVariableResolver.class.getName()));
+
Properties p = new Properties();
- p.put("hello","world");
+ p.put("hello", "world");
VariableResolver vri = new VariableResolver(p);
Object val = vri.resolve(TestVariableResolver.class.getName());
// System.out.println("val = " + val);
assertEquals("hello", val);
- assertEquals("world",vri.resolve("hello"));
+ assertEquals("world", vri.resolve("hello"));
}
-
+
@Test
public void testNestedNamespace() {
VariableResolver vri = new VariableResolver();
- Map<String, Object> ns = new HashMap<String, Object>();
+ Map<String,Object> ns = new HashMap<String,Object>();
ns.put("world", "WORLD");
vri.addNamespace("hello", ns);
- ns = new HashMap<String, Object>();
+ ns = new HashMap<String,Object>();
ns.put("world1", "WORLD1");
vri.addNamespace("hello.my", ns);
assertEquals("WORLD1", vri.resolve("hello.my.world1"));
}
-
+
@Test
public void test3LevelNestedNamespace() {
VariableResolver vri = new VariableResolver();
- Map<String, Object> ns = new HashMap<String, Object>();
+ Map<String,Object> ns = new HashMap<String,Object>();
ns.put("world", "WORLD");
vri.addNamespace("hello", ns);
- ns = new HashMap<String, Object>();
+ ns = new HashMap<String,Object>();
ns.put("world1", "WORLD1");
vri.addNamespace("hello.my.new", ns);
assertEquals("WORLD1", vri.resolve("hello.my.new.world1"));
}
-
+
@Test
public void dateNamespaceWithValue() {
VariableResolver vri = new VariableResolver();
- vri.setEvaluators(new DataImporter().getEvaluators(Collections.<Map<String,String>>emptyList()));
- Map<String, Object> ns = new HashMap<String, Object>();
+ vri.setEvaluators(new DataImporter().getEvaluators(Collections
+ .<Map<String,String>> emptyList()));
+ Map<String,Object> ns = new HashMap<String,Object>();
Date d = new Date();
ns.put("dt", d);
vri.addNamespace("A", ns);
- assertEquals(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d),
- vri.replaceTokens("${dataimporter.functions.formatDate(A.dt,'yyyy-MM-dd HH:mm:ss')}"));
+ assertEquals(
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d),
+ vri.replaceTokens("${dataimporter.functions.formatDate(A.dt,'yyyy-MM-dd HH:mm:ss')}"));
}
-
+
@Test
public void dateNamespaceWithExpr() throws Exception {
VariableResolver vri = new VariableResolver();
- vri.setEvaluators(new DataImporter().getEvaluators(Collections.<Map<String,String>>emptyList()));
+ vri.setEvaluators(new DataImporter().getEvaluators(Collections
+ .<Map<String,String>> emptyList()));
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')}");
- assertEquals(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(dmp.parseMath("/DAY")), s);
+ DateMathParser dmp = new DateMathParser(TimeZone.getDefault(),
+ Locale.getDefault());
+
+ String s = vri
+ .replaceTokens("${dataimporter.functions.formatDate('NOW/DAY','yyyy-MM-dd HH:mm')}");
+ assertEquals(
+ new SimpleDateFormat("yyyy-MM-dd HH:mm").format(dmp.parseMath("/DAY")),
+ s);
}
-
+
@Test
public void testDefaultNamespace() {
VariableResolver vri = new VariableResolver();
- Map<String, Object> ns = new HashMap<String, Object>();
+ Map<String,Object> ns = new HashMap<String,Object>();
ns.put("world", "WORLD");
vri.addNamespace(null, ns);
assertEquals("WORLD", vri.resolve("world"));
}
-
+
@Test
public void testDefaultNamespace1() {
VariableResolver vri = new VariableResolver();
- Map<String, Object> ns = new HashMap<String, Object>();
+ Map<String,Object> ns = new HashMap<String,Object>();
ns.put("world", "WORLD");
vri.addNamespace(null, ns);
assertEquals("WORLD", vri.resolve("world"));
}
-
+
@Test
public void testFunctionNamespace1() throws Exception {
VariableResolver resolver = new VariableResolver();
- 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());
+ 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);
resolver.setEvaluators(new DataImporter().getEvaluators(l));
- ContextImpl context = new ContextImpl(null, resolver, null, Context.FULL_DUMP, Collections.EMPTY_MAP, null, null);
+ ContextImpl context = new ContextImpl(null, resolver, null,
+ Context.FULL_DUMP, Collections.EMPTY_MAP, null, null);
-
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 = resolver
- .replaceTokens("${dataimporter.functions.formatDate('NOW/DAY','yyyy-MM-dd HH:mm')}");
- assertEquals(new SimpleDateFormat("yyyy-MM-dd HH:mm")
- .format(dmp.parseMath("/DAY")), s);
- assertEquals("Hello World", resolver
- .replaceTokens("${dataimporter.functions.test('TEST')}"));
- }
-
- public static class E extends Evaluator{
- @Override
- public String evaluate(String expression, Context context) {
- return "Hello World";
- }
+ DateMathParser dmp = new DateMathParser(TimeZone.getDefault(),
+ Locale.getDefault());
+
+ String s = resolver
+ .replaceTokens("${dataimporter.functions.formatDate('NOW/DAY','yyyy-MM-dd HH:mm')}");
+ assertEquals(
+ new SimpleDateFormat("yyyy-MM-dd HH:mm").format(dmp.parseMath("/DAY")),
+ s);
+ assertEquals("Hello World",
+ resolver.replaceTokens("${dataimporter.functions.test('TEST')}"));
+ }
+
+ public static class E extends Evaluator {
+ @Override
+ public String evaluate(String expression, Context context) {
+ return "Hello World";
+ }
}
-
}