Skip to content

Commit

Permalink
TIKA-2959: create localized test results because of tests failing in …
Browse files Browse the repository at this point in the history
…Germany
  • Loading branch information
THausherr committed Oct 5, 2019
1 parent 346d12f commit 903e62b
Showing 1 changed file with 43 additions and 11 deletions.
Expand Up @@ -20,19 +20,27 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.text.DateFormatSymbols;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;

import org.apache.tika.TikaTest;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Ensure that our various Table-based formats produce consistent,
* broadly similar output.
* This is mostly focused on the XHTML output
*/
public class TabularFormatsTest extends TikaTest {
private static final Logger LOG = LoggerFactory.getLogger(TabularFormatsTest.class);

protected static final String[] columnNames = new String[] {
"recnum","square","desc","pctdone","pctincr",
"date","datetime","time"
Expand All @@ -43,6 +51,30 @@ public class TabularFormatsTest extends TikaTest {
"Percent Increment","date","datetime","time"
};

// to prevent this build test from failing outside the english speaking world, we need to have
// both local and english month names (testCSV uses english names, the other tests local names)
private static final String[] SHORT_MONTHS_EXPR;
static {
String[] shortMonthsEnglish = new DateFormatSymbols(Locale.ENGLISH).getShortMonths();
String[] shortMonthsLocal = new DateFormatSymbols(Locale.getDefault()).getShortMonths();
List<String> shortMonthsExpr = new ArrayList();
for (int i = 0; i < 12; ++i)
{
String expr = shortMonthsEnglish[i].toUpperCase(Locale.ENGLISH) +
"|" +
shortMonthsEnglish[i];
if (!shortMonthsEnglish[i].equals(shortMonthsLocal[i])) {
expr += "|" +
shortMonthsLocal[i].toUpperCase(Locale.getDefault()) +
"|" +
shortMonthsLocal[i];
}
LOG.info(expr);
shortMonthsExpr.add(expr);
}
SHORT_MONTHS_EXPR = shortMonthsExpr.toArray(new String[0]);
};

/**
* Expected values, by <em>column</em>
*/
Expand Down Expand Up @@ -77,17 +109,17 @@ public class TabularFormatsTest extends TikaTest {
Pattern.compile("19-05-1987"),
},
new Pattern[] {
Pattern.compile("01(JAN|Jan)(60|1960)[:\\s]00:00:01(.00)?"),
Pattern.compile("01(JAN|Jan)(60|1960)[:\\s]00:00:10(.00)?"),
Pattern.compile("01(JAN|Jan)(60|1960)[:\\s]00:01:40(.00)?"),
Pattern.compile("01(JAN|Jan)(60|1960)[:\\s]00:16:40(.00)?"),
Pattern.compile("01(JAN|Jan)(60|1960)[:\\s]02:46:40(.00)?"),
Pattern.compile("02(JAN|Jan)(60|1960)[:\\s]03:46:40(.00)?"),
Pattern.compile("12(JAN|Jan)(60|1960)[:\\s]13:46:40(.00)?"),
Pattern.compile("25(APR|Apr)(60|1960)[:\\s]17:46:40(.00)?"),
Pattern.compile("03(MAR|Mar)(63|1963)[:\\s]09:46:40(.00)?"),
Pattern.compile("09(SEP|Sep)(91|1991)[:\\s]01:46:40(.00)?"),
Pattern.compile("19(NOV|Nov)(76|2276)[:\\s]17:46:40(.00)?")
Pattern.compile("01(" + SHORT_MONTHS_EXPR[0] + ")(60|1960)[:\\s]00:00:01(.00)?"),
Pattern.compile("01(" + SHORT_MONTHS_EXPR[0] + ")(60|1960)[:\\s]00:00:10(.00)?"),
Pattern.compile("01(" + SHORT_MONTHS_EXPR[0] + ")(60|1960)[:\\s]00:01:40(.00)?"),
Pattern.compile("01(" + SHORT_MONTHS_EXPR[0] + ")(60|1960)[:\\s]00:16:40(.00)?"),
Pattern.compile("01(" + SHORT_MONTHS_EXPR[0] + ")(60|1960)[:\\s]02:46:40(.00)?"),
Pattern.compile("02(" + SHORT_MONTHS_EXPR[0] + ")(60|1960)[:\\s]03:46:40(.00)?"),
Pattern.compile("12(" + SHORT_MONTHS_EXPR[0] + ")(60|1960)[:\\s]13:46:40(.00)?"),
Pattern.compile("25(" + SHORT_MONTHS_EXPR[3] + ")(60|1960)[:\\s]17:46:40(.00)?"),
Pattern.compile("03(" + SHORT_MONTHS_EXPR[2] + ")(63|1963)[:\\s]09:46:40(.00)?"),
Pattern.compile("09(" + SHORT_MONTHS_EXPR[8] + ")(91|1991)[:\\s]01:46:40(.00)?"),
Pattern.compile("19(" + SHORT_MONTHS_EXPR[10] + ")(76|2276)[:\\s]17:46:40(.00)?")
},
new Pattern[] {
Pattern.compile("0?0:00:01(.\\d\\d)?"),
Expand Down

0 comments on commit 903e62b

Please sign in to comment.