lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From busc...@apache.org
Subject svn commit: r807499 - in /lucene/java/trunk: ./ contrib/miscellaneous/src/test/org/apache/lucene/queryParser/precedence/ contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/ src/test/org/apache/lucene/document/ src/test/org/apache/lucen...
Date Tue, 25 Aug 2009 06:48:36 GMT
Author: buschmi
Date: Tue Aug 25 06:48:36 2009
New Revision: 807499

URL: http://svn.apache.org/viewvc?rev=807499&view=rev
Log:
LUCENE-1852: Fix localization test failures.

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/contrib/miscellaneous/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
    lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java
    lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java
    lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=807499&r1=807498&r2=807499&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Aug 25 06:48:36 2009
@@ -813,6 +813,9 @@
     MultiSearcher when possible to help excercise more edge cases.
     (Chris Hostetter, Mark Miller)
 
+ 2. LUCENE-1852: Fix localization test failures. 
+    (Robert Muir via Michael Busch)
+
 ======================= Release 2.4.1 2009-03-09 =======================
 
 API Changes

Modified: lucene/java/trunk/contrib/miscellaneous/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/miscellaneous/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java?rev=807499&r1=807498&r2=807499&view=diff
==============================================================================
--- lucene/java/trunk/contrib/miscellaneous/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
(original)
+++ lucene/java/trunk/contrib/miscellaneous/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java
Tue Aug 25 06:48:36 2009
@@ -17,11 +17,9 @@
  * limitations under the License.
  */
 
-import junit.framework.TestCase;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.LowerCaseTokenizer;
 import org.apache.lucene.analysis.SimpleAnalyzer;
-import org.apache.lucene.analysis.Token;
 import org.apache.lucene.analysis.TokenFilter;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.WhitespaceAnalyzer;
@@ -37,13 +35,23 @@
 import org.apache.lucene.search.RangeQuery;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.WildcardQuery;
+import org.apache.lucene.util.LocalizedTestCase;
 
 import java.io.IOException;
 import java.io.Reader;
 import java.text.DateFormat;
+import java.util.Arrays;
 import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.HashSet;
 
-public class TestPrecedenceQueryParser extends TestCase {
+public class TestPrecedenceQueryParser extends LocalizedTestCase {
+  
+  public TestPrecedenceQueryParser(String name) {
+    super(name, new HashSet(Arrays.asList(new String[]{
+      "testDateRange", "testNumber"
+    })));
+  }
 
   public static Analyzer qpAnalyzer = new QPTestAnalyzer();
 
@@ -107,7 +115,8 @@
 
   private int originalMaxClauses;
 
-  public void setUp() {
+  public void setUp() throws Exception {
+    super.setUp();
     originalMaxClauses = BooleanQuery.getMaxClauseCount();
   }
 
@@ -360,6 +369,14 @@
     assertQueryEquals("( bar blar { a TO z}) ", null, "bar blar {a TO z}");
     assertQueryEquals("gack ( bar blar { a TO z}) ", null, "gack (bar blar {a TO z})");
   }
+  
+  private String escapeDateString(String s) {
+    if (s.contains(" ")) {
+      return "\"" + s + "\"";
+    } else {
+      return s;
+    }
+  }
 
   public String getDate(String s) throws Exception {
     DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
@@ -368,7 +385,7 @@
 
   public String getLocalizedDate(int year, int month, int day) {
     DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
-    Calendar calendar = Calendar.getInstance();
+    Calendar calendar = new GregorianCalendar();
     calendar.set(year, month, day);
     return df.format(calendar.getTime());
   }
@@ -376,9 +393,9 @@
   public void testDateRange() throws Exception {
     String startDate = getLocalizedDate(2002, 1, 1);
     String endDate = getLocalizedDate(2002, 1, 4);
-    assertQueryEquals("[ " + startDate + " TO " + endDate + "]", null,
+    assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate)
+ "]", null,
                       "[" + getDate(startDate) + " TO " + getDate(endDate) + "]");
-    assertQueryEquals("{  " + startDate + "    " + endDate + "   }", null,
+    assertQueryEquals("{  " + escapeDateString(startDate) + "    " + escapeDateString(endDate)
+ "   }", null,
                       "{" + getDate(startDate) + " TO " + getDate(endDate) + "}");
   }
 

Modified: lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java?rev=807499&r1=807498&r2=807499&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java
(original)
+++ lucene/java/trunk/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java
Tue Aug 25 06:48:36 2009
@@ -21,8 +21,11 @@
 import java.io.Reader;
 import java.text.Collator;
 import java.text.DateFormat;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
 
@@ -68,7 +71,7 @@
 import org.apache.lucene.search.TermRangeQuery;
 import org.apache.lucene.search.WildcardQuery;
 import org.apache.lucene.store.RAMDirectory;
-import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.LocalizedTestCase;
 
 /**
  * This test case is a copy of the core Lucene query parser test, it was adapted
@@ -76,8 +79,16 @@
  * 
  * Tests QueryParser.
  */
-public class TestQueryParserWrapper extends LuceneTestCase {
+public class TestQueryParserWrapper extends LocalizedTestCase {
 
+  public TestQueryParserWrapper(String name) {
+    super(name, new HashSet(Arrays.asList(new String[]{
+      "testLegacyDateRange", "testDateRange",
+      "testCJK", "testNumber", "testFarsiRangeCollating",
+      "testLocalDateFormat"
+    })));
+  }
+  
   public static Analyzer qpAnalyzer = new QPTestAnalyzer();
 
   public static class QPTestFilter extends TokenFilter {
@@ -618,6 +629,14 @@
 
     is.close();
   }
+  
+  private String escapeDateString(String s) {
+    if (s.contains(" ")) {
+      return "\"" + s + "\"";
+    } else {
+      return s;
+    }
+  }
 
   /** for testing legacy DateField support */
   private String getLegacyDate(String s) throws Exception {
@@ -645,7 +664,7 @@
   private String getLocalizedDate(int year, int month, int day,
       boolean extendLastDate) {
     DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
-    Calendar calendar = Calendar.getInstance();
+    Calendar calendar = new GregorianCalendar();
     calendar.set(year, month, day);
     if (extendLastDate) {
       calendar.set(Calendar.HOUR_OF_DAY, 23);
@@ -660,20 +679,20 @@
   public void testLegacyDateRange() throws Exception {
     String startDate = getLocalizedDate(2002, 1, 1, false);
     String endDate = getLocalizedDate(2002, 1, 4, false);
-    Calendar endDateExpected = Calendar.getInstance();
+    Calendar endDateExpected = new GregorianCalendar();
     endDateExpected.set(2002, 1, 4, 23, 59, 59);
     endDateExpected.set(Calendar.MILLISECOND, 999);
-    assertQueryEquals("[ " + startDate + " TO " + endDate + "]", null, "["
+    assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate)
+ "]", null, "["
         + getLegacyDate(startDate) + " TO "
         + DateField.dateToString(endDateExpected.getTime()) + "]");
-    assertQueryEquals("{  " + startDate + "    " + endDate + "   }", null, "{"
+    assertQueryEquals("{  " + escapeDateString(startDate) + "    " + escapeDateString(endDate)
+ "   }", null, "{"
         + getLegacyDate(startDate) + " TO " + getLegacyDate(endDate) + "}");
   }
 
   public void testDateRange() throws Exception {
     String startDate = getLocalizedDate(2002, 1, 1, false);
     String endDate = getLocalizedDate(2002, 1, 4, false);
-    Calendar endDateExpected = Calendar.getInstance();
+    Calendar endDateExpected = new GregorianCalendar();
     endDateExpected.set(2002, 1, 4, 23, 59, 59);
     endDateExpected.set(Calendar.MILLISECOND, 999);
     final String defaultField = "default";
@@ -715,10 +734,10 @@
   public void assertDateRangeQueryEquals(QueryParserWrapper qp, String field,
       String startDate, String endDate, Date endDateInclusive,
       DateTools.Resolution resolution) throws Exception {
-    assertQueryEquals(qp, field, field + ":[" + startDate + " TO " + endDate
+    assertQueryEquals(qp, field, field + ":[" + escapeDateString(startDate) + " TO " + escapeDateString(endDate)
         + "]", "[" + getDate(startDate, resolution) + " TO "
         + getDate(endDateInclusive, resolution) + "]");
-    assertQueryEquals(qp, field, field + ":{" + startDate + " TO " + endDate
+    assertQueryEquals(qp, field, field + ":{" + escapeDateString(startDate) + " TO " + escapeDateString(endDate)
         + "}", "{" + getDate(startDate, resolution) + " TO "
         + getDate(endDate, resolution) + "}");
   }
@@ -1124,7 +1143,7 @@
       int hour, int minute, int second, IndexWriter iw) throws IOException {
     Document d = new Document();
     d.add(new Field("f", content, Field.Store.YES, Field.Index.ANALYZED));
-    Calendar cal = Calendar.getInstance();
+    Calendar cal = Calendar.getInstance(Locale.ENGLISH);
     cal.set(year, month - 1, day, hour, minute, second);
     d.add(new Field("date", DateField.dateToString(cal.getTime()),
         Field.Store.YES, Field.Index.NOT_ANALYZED));

Modified: lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java?rev=807499&r1=807498&r2=807499&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java Tue Aug 25 06:48:36
2009
@@ -4,9 +4,11 @@
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.TimeZone;
 import java.util.Locale;
 
+import org.apache.lucene.util.LocalizedTestCase;
 import org.apache.lucene.util.LuceneTestCase;
 
 /**
@@ -26,7 +28,7 @@
  * limitations under the License.
  */
 
-public class TestDateTools extends LuceneTestCase {
+public class TestDateTools extends LocalizedTestCase {
 
   public void testStringToDate() throws ParseException {
     
@@ -57,7 +59,7 @@
   
   public void testStringtoTime() throws ParseException {
     long time = DateTools.stringToTime("197001010000");
-    Calendar cal = Calendar.getInstance();
+    Calendar cal = new GregorianCalendar();
     cal.set(1970, 0, 1,    // year=1970, month=january, day=1
         0, 0, 0);          // hour, minute, second
     cal.set(Calendar.MILLISECOND, 0);
@@ -71,7 +73,7 @@
   }
   
   public void testDateAndTimetoString() throws ParseException {
-    Calendar cal = Calendar.getInstance();
+    Calendar cal = new GregorianCalendar();
     cal.setTimeZone(TimeZone.getTimeZone("GMT"));
     cal.set(2004, 1, 3,   // year=2004, month=february(!), day=3
         22, 8, 56);       // hour, minute, second
@@ -135,7 +137,7 @@
   }
   
   public void testRound() {
-    Calendar cal = Calendar.getInstance();
+    Calendar cal = new GregorianCalendar();
     cal.setTimeZone(TimeZone.getTimeZone("GMT"));
     cal.set(2004, 1, 3,   // year=2004, month=february(!), day=3
         22, 8, 56);       // hour, minute, second

Modified: lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java?rev=807499&r1=807498&r2=807499&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java Tue Aug
25 06:48:36 2009
@@ -21,8 +21,10 @@
 import java.io.Reader;
 import java.text.Collator;
 import java.text.DateFormat;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.HashSet;
 import java.util.Locale;
 import java.util.Set;
@@ -58,13 +60,21 @@
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.WildcardQuery;
 import org.apache.lucene.store.RAMDirectory;
-import org.apache.lucene.analysis.BaseTokenStreamTestCase;
+import org.apache.lucene.util.LocalizedTestCase;
 
 /**
  * Tests QueryParser.
  */
-public class TestQueryParser extends BaseTokenStreamTestCase {
+public class TestQueryParser extends LocalizedTestCase {
 
+  public TestQueryParser(String name) {
+    super(name, new HashSet(Arrays.asList(new String[]{
+      "testLegacyDateRange", "testDateRange",
+      "testCJK", "testNumber", "testFarsiRangeCollating",
+      "testLocalDateFormat"
+    })));
+  }
+  
   public static Analyzer qpAnalyzer = new QPTestAnalyzer();
 
   public static class QPTestFilter extends TokenFilter {
@@ -495,6 +505,14 @@
     is.close();
   }
   
+  private String escapeDateString(String s) {
+    if (s.contains(" ")) {
+      return "\"" + s + "\"";
+    } else {
+      return s;
+    }
+  }
+  
   /** for testing legacy DateField support */
   private String getLegacyDate(String s) throws Exception {
     DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
@@ -518,7 +536,7 @@
   
   private String getLocalizedDate(int year, int month, int day, boolean extendLastDate) {
     DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
-    Calendar calendar = Calendar.getInstance();
+    Calendar calendar = new GregorianCalendar();
     calendar.set(year, month, day);
     if (extendLastDate) {
       calendar.set(Calendar.HOUR_OF_DAY, 23);
@@ -533,19 +551,19 @@
   public void testLegacyDateRange() throws Exception {
     String startDate = getLocalizedDate(2002, 1, 1, false);
     String endDate = getLocalizedDate(2002, 1, 4, false);
-    Calendar endDateExpected = Calendar.getInstance();
+    Calendar endDateExpected = new GregorianCalendar();
     endDateExpected.set(2002, 1, 4, 23, 59, 59);
     endDateExpected.set(Calendar.MILLISECOND, 999);
-    assertQueryEquals("[ " + startDate + " TO " + endDate + "]", null,
+    assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate)
+ "]", null,
                       "[" + getLegacyDate(startDate) + " TO " + DateField.dateToString(endDateExpected.getTime())
+ "]");
-    assertQueryEquals("{  " + startDate + "    " + endDate + "   }", null,
+    assertQueryEquals("{  " + escapeDateString(startDate) + "    " + escapeDateString(endDate)
+ "   }", null,
                       "{" + getLegacyDate(startDate) + " TO " + getLegacyDate(endDate) +
"}");
   }
   
   public void testDateRange() throws Exception {
     String startDate = getLocalizedDate(2002, 1, 1, false);
     String endDate = getLocalizedDate(2002, 1, 4, false);
-    Calendar endDateExpected = Calendar.getInstance();
+    Calendar endDateExpected = new GregorianCalendar();
     endDateExpected.set(2002, 1, 4, 23, 59, 59);
     endDateExpected.set(Calendar.MILLISECOND, 999);
     final String defaultField = "default";
@@ -585,9 +603,9 @@
   
   public void assertDateRangeQueryEquals(QueryParser qp, String field, String startDate,
String endDate, 
                                          Date endDateInclusive, DateTools.Resolution resolution)
throws Exception {
-    assertQueryEquals(qp, field, field + ":[" + startDate + " TO " + endDate + "]",
+    assertQueryEquals(qp, field, field + ":[" + escapeDateString(startDate) + " TO " + escapeDateString(endDate)
+ "]",
                "[" + getDate(startDate, resolution) + " TO " + getDate(endDateInclusive,
resolution) + "]");
-    assertQueryEquals(qp, field, field + ":{" + startDate + " TO " + endDate + "}",
+    assertQueryEquals(qp, field, field + ":{" + escapeDateString(startDate) + " TO " + escapeDateString(endDate)
+ "}",
                "{" + getDate(startDate, resolution) + " TO " + getDate(endDate, resolution)
+ "}");
   }
 
@@ -985,7 +1003,7 @@
       int day, int hour, int minute, int second, IndexWriter iw) throws IOException {
     Document d = new Document();
     d.add(new Field("f", content, Field.Store.YES, Field.Index.ANALYZED));
-    Calendar cal = Calendar.getInstance();
+    Calendar cal = Calendar.getInstance(Locale.ENGLISH);
     cal.set(year, month-1, day, hour, minute, second);
     d.add(new Field("date", DateField.dateToString(cal.getTime()), Field.Store.YES, Field.Index.NOT_ANALYZED));
     iw.addDocument(d);



Mime
View raw message