SOLR-5488: Changing Facets testing to use DOM rather than string operations

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1546074 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erick Erickson 2013-11-27 15:24:24 +00:00
parent b821c13488
commit 38643894d1
5 changed files with 433 additions and 560 deletions

View File

@ -17,8 +17,10 @@
package org.apache.solr.analytics.facet; package org.apache.solr.analytics.facet;
import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -35,6 +37,18 @@ import org.apache.solr.request.SolrQueryRequest;
import com.google.common.collect.ObjectArrays; import com.google.common.collect.ObjectArrays;
import org.apache.solr.util.ExternalPaths; import org.apache.solr.util.ExternalPaths;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
@SuppressCodecs({"Lucene3x","Lucene40","Lucene41","Lucene42","Appending","Asserting"}) @SuppressCodecs({"Lucene3x","Lucene40","Lucene41","Lucene42","Appending","Asserting"})
public class AbstractAnalyticsFacetTest extends SolrTestCaseJ4 { public class AbstractAnalyticsFacetTest extends SolrTestCaseJ4 {
@ -42,24 +56,84 @@ public class AbstractAnalyticsFacetTest extends SolrTestCaseJ4 {
protected String latestType = ""; protected String latestType = "";
public String getFacetXML(String response, String requestName, String facetType, String facet) { private static Document doc;
String cat = "\n <lst name=\""+requestName+"\">"; private static XPathFactory xPathFact = XPathFactory.newInstance();
String begin = " <lst name=\""+facetType+"\">\n"; private static String rawResponse;
String end = "\n </lst>";
int beginInt = response.indexOf(begin, response.indexOf(cat))+begin.length(); protected static void setResponse(String response) throws ParserConfigurationException, IOException, SAXException {
int endInt = response.indexOf(end, beginInt); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
String fieldStr = response.substring(beginInt, endInt); factory.setNamespaceAware(true); // never forget this!
begin = " <lst name=\""+facet+"\">"; DocumentBuilder builder = factory.newDocumentBuilder();
end = "\n </lst>"; doc = builder.parse(new InputSource(new ByteArrayInputStream(response.getBytes("UTF-8"))));
beginInt = fieldStr.indexOf(begin); xPathFact = XPathFactory.newInstance();
endInt = fieldStr.indexOf(end, beginInt); rawResponse = response;
String facetStr = "";
if (beginInt>=0) {
facetStr = fieldStr.substring(beginInt+begin.length(),endInt);
} }
return facetStr+" ";
protected String getRawResponse() {
return rawResponse;
} }
protected Node getNode(String xPath) throws XPathExpressionException {
return (Node)xPathFact.newXPath().compile(xPath).evaluate(doc, XPathConstants.NODE);
}
private NodeList getNodes(String n1, String n2, String n3, String element, String n4) throws XPathExpressionException {
// Construct the XPath expression. The form better not change or all these will fail.
StringBuilder sb = new StringBuilder("/response/lst[@name='stats']/lst[@name='").append(n1).append("']");
sb.append("/lst[@name='").append(n2).append("']");
sb.append("/lst[@name='").append(n3).append("']");
sb.append("//").append(element).append("[@name='").append(n4).append("']");
return (NodeList)xPathFact.newXPath().compile(sb.toString()).evaluate(doc, XPathConstants.NODESET);
}
protected ArrayList<String> getStringList(String n1, String n2, String n3, String element, String n4)
throws XPathExpressionException {
ArrayList<String> ret = new ArrayList<String>();
NodeList nodes = getNodes(n1, n2, n3, element, n4);
for (int idx = 0; idx < nodes.getLength(); ++idx) {
ret.add(nodes.item(idx).getTextContent());
}
return ret;
}
protected ArrayList<Integer> getIntegerList(String n1, String n2, String n3, String element, String n4)
throws XPathExpressionException {
ArrayList<Integer> ret = new ArrayList<Integer>();
NodeList nodes = getNodes(n1, n2, n3, element, n4);
for (int idx = 0; idx < nodes.getLength(); ++idx) {
ret.add(Integer.parseInt(nodes.item(idx).getTextContent()));
}
return ret;
}
protected ArrayList<Long> getLongList(String n1, String n2, String n3, String element, String n4)
throws XPathExpressionException {
ArrayList<Long> ret = new ArrayList<Long>();
NodeList nodes = getNodes(n1, n2, n3, element, n4);
for (int idx = 0; idx < nodes.getLength(); ++idx) {
ret.add(Long.parseLong(nodes.item(idx).getTextContent()));
}
return ret;
}
protected ArrayList<Float> getFloatList(String n1, String n2, String n3, String element, String n4)
throws XPathExpressionException {
ArrayList<Float> ret = new ArrayList<Float>();
NodeList nodes = getNodes(n1, n2, n3, element, n4);
for (int idx = 0; idx < nodes.getLength(); ++idx) {
ret.add(Float.parseFloat(nodes.item(idx).getTextContent()));
}
return ret;
}
protected ArrayList<Double> getDoubleList(String n1, String n2, String n3, String element, String n4)
throws XPathExpressionException {
ArrayList<Double> ret = new ArrayList<Double>();
NodeList nodes = getNodes(n1, n2, n3, element, n4);
for (int idx = 0; idx < nodes.getLength(); ++idx) {
ret.add(Double.parseDouble(nodes.item(idx).getTextContent()));
}
return ret;
}
public static void increment(List<Long> list, int idx){ public static void increment(List<Long> list, int idx){
Long i = list.remove(idx); Long i = list.remove(idx);
list.add(idx, i+1); list.add(idx, i+1);
@ -84,41 +158,6 @@ public class AbstractAnalyticsFacetTest extends SolrTestCaseJ4 {
this.latestType = latestType; this.latestType = latestType;
} }
@SuppressWarnings({ "unchecked", "rawtypes" })
public ArrayList xmlToList(String facit, String type, String name) {
ArrayList list;
if (type.equals("double")) {
list = new ArrayList<Double>();
} else if (type.equals("int")) {
list = new ArrayList<Integer>();
} else if (type.equals("long")) {
list = new ArrayList<Long>();
} else if (type.equals("float")) {
list = new ArrayList<Float>();
} else {
list = new ArrayList<String>();
}
String find = "<"+type+" name=\""+name+"\">";
String endS = "</"+type+">";
int findAt = facit.indexOf(find)+find.length();
while (findAt>find.length()) {
int end = facit.indexOf(endS, findAt);
if (type.equals("double")) {
list.add(Double.parseDouble(facit.substring(findAt, end)));
} else if (type.equals("int")) {
list.add(Integer.parseInt(facit.substring(findAt, end)));
} else if (type.equals("long")) {
list.add(Long.parseLong(facit.substring(findAt, end)));
} else if (type.equals("float")) {
list.add(Float.parseFloat(facit.substring(findAt, end)));
} else {
list.add(facit.substring(findAt, end));
}
findAt = facit.indexOf(find, end)+find.length();
}
return list;
}
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
public <T extends Number & Comparable<T>> ArrayList calculateNumberStat(ArrayList<ArrayList<T>> lists, String stat) { public <T extends Number & Comparable<T>> ArrayList calculateNumberStat(ArrayList<ArrayList<T>> lists, String stat) {
ArrayList result; ArrayList result;

View File

@ -45,8 +45,6 @@ public class FieldFacetExtrasTest extends AbstractAnalyticsFacetTest {
static ArrayList<ArrayList<Integer>> intDoubleTestStart; static ArrayList<ArrayList<Integer>> intDoubleTestStart;
static ArrayList<ArrayList<Integer>> intStringTestStart; static ArrayList<ArrayList<Integer>> intStringTestStart;
static String response;
@BeforeClass @BeforeClass
public static void beforeClass() throws Exception { public static void beforeClass() throws Exception {
initCore("solrconfig-basic.xml","schema-analytics.xml"); initCore("solrconfig-basic.xml","schema-analytics.xml");
@ -106,85 +104,72 @@ public class FieldFacetExtrasTest extends AbstractAnalyticsFacetTest {
} }
assertU(commit()); assertU(commit());
response = h.query(request(fileToStringArr(fileName))); setResponse(h.query(request(fileToStringArr(fileName))));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void limitTest() throws Exception { public void limitTest() throws Exception {
String longLimit = getFacetXML(response, "lr", "fieldFacets", "long_ld"); Collection<Double> lon = getDoubleList("lr", "fieldFacets", "long_ld", "double", "mean");
Collection<Double> lon = (ArrayList<Double>)xmlToList(longLimit, "double", "mean"); assertEquals(getRawResponse(), lon.size(),5);
assertEquals(lon.size(),5); Collection<Double> flo = getDoubleList("lr", "fieldFacets", "float_fd", "double", "median");
String floatLimit = getFacetXML(response, "lr", "fieldFacets", "float_fd"); assertEquals(getRawResponse(), flo.size(),3);
Collection<Double> flo = (ArrayList<Double>)xmlToList(floatLimit, "double", "median"); Collection<Long> doub = getLongList("lr", "fieldFacets", "double_dd", "long", "count");
assertEquals(flo.size(),3); assertEquals(getRawResponse(), doub.size(),7);
String doubleLimit = getFacetXML(response, "lr", "fieldFacets", "double_dd"); Collection<Integer> string = getIntegerList("lr", "fieldFacets", "string_sd", "int", "percentile_20");
Collection<Long> doub = (ArrayList<Long>)xmlToList(doubleLimit, "long", "count"); assertEquals(getRawResponse(), string.size(),1);
assertEquals(doub.size(),7);
String stringLimit = getFacetXML(response, "lr", "fieldFacets", "string_sd");
Collection<Integer> string = (ArrayList<Integer>)xmlToList(stringLimit, "int", "percentile_20");
assertEquals(string.size(),1);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void offsetTest() throws Exception { public void offsetTest() throws Exception {
String xml;
Collection<Double> lon; Collection<Double> lon;
List<Double> all = new ArrayList<Double>(); List<Double> all = new ArrayList<Double>();
xml = getFacetXML(response, "off0", "fieldFacets", "long_ld"); lon = getDoubleList("off0", "fieldFacets", "long_ld", "double", "mean");
lon = (ArrayList<Double>)xmlToList(xml, "double", "mean"); assertEquals(getRawResponse(), lon.size(),2);
assertEquals(lon.size(),2);
assertArrayEquals(new Double[]{ 1.5, 2.0 }, lon.toArray(new Double[0])); assertArrayEquals(new Double[]{ 1.5, 2.0 }, lon.toArray(new Double[0]));
all.addAll(lon); all.addAll(lon);
xml = getFacetXML(response, "off1", "fieldFacets", "long_ld"); lon = getDoubleList("off1", "fieldFacets", "long_ld", "double", "mean");
lon = (ArrayList<Double>)xmlToList(xml, "double", "mean"); assertEquals(getRawResponse(), lon.size(),2);
assertEquals(lon.size(),2);
assertArrayEquals(new Double[]{ 3.0, 4.0 }, lon.toArray(new Double[0])); assertArrayEquals(new Double[]{ 3.0, 4.0 }, lon.toArray(new Double[0]));
all.addAll(lon); all.addAll(lon);
xml = getFacetXML(response, "off2", "fieldFacets", "long_ld"); lon = getDoubleList("off2", "fieldFacets", "long_ld", "double", "mean");
lon = (ArrayList<Double>)xmlToList(xml, "double", "mean"); assertEquals(getRawResponse(), lon.size(),3);
assertEquals(lon.size(),3);
assertArrayEquals(new Double[]{ 5.0, 5.75, 6.0 }, lon.toArray(new Double[0])); assertArrayEquals(new Double[]{ 5.0, 5.75, 6.0 }, lon.toArray(new Double[0]));
all.addAll(lon); all.addAll(lon);
xml = getFacetXML(response, "offAll", "fieldFacets", "long_ld"); lon = getDoubleList("offAll", "fieldFacets", "long_ld", "double", "mean");
lon = (ArrayList<Double>)xmlToList(xml, "double", "mean"); assertEquals(getRawResponse(), lon.size(),7);
assertEquals(lon.size(),7);
assertArrayEquals(all.toArray(new Double[0]), lon.toArray(new Double[0])); assertArrayEquals(all.toArray(new Double[0]), lon.toArray(new Double[0]));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void sortTest() throws Exception { public void sortTest() throws Exception {
String longSort = getFacetXML(response, "sr", "fieldFacets", "long_ld"); Collection<Double> lon = getDoubleList("sr", "fieldFacets", "long_ld", "double", "mean");
Collection<Double> lon = (ArrayList<Double>)xmlToList(longSort, "double", "mean");
ArrayList<Double> longTest = calculateNumberStat(intLongTestStart, "mean"); ArrayList<Double> longTest = calculateNumberStat(intLongTestStart, "mean");
Collections.sort(longTest); Collections.sort(longTest);
assertEquals(longTest,lon); assertEquals(getRawResponse(), longTest,lon);
String floatSort = getFacetXML(response, "sr", "fieldFacets", "float_fd"); Collection<Double> flo = getDoubleList("sr", "fieldFacets", "float_fd", "double", "median");
Collection<Double> flo = (ArrayList<Double>)xmlToList(floatSort, "double", "median");
ArrayList<Double> floatTest = calculateNumberStat(intFloatTestStart, "median"); ArrayList<Double> floatTest = calculateNumberStat(intFloatTestStart, "median");
Collections.sort(floatTest,Collections.reverseOrder()); Collections.sort(floatTest,Collections.reverseOrder());
assertEquals(floatTest,flo); assertEquals(getRawResponse(), floatTest,flo);
String doubleSort = getFacetXML(response, "sr", "fieldFacets", "double_dd"); Collection<Long> doub = getLongList("sr", "fieldFacets", "double_dd", "long", "count");
Collection<Long> doub = (ArrayList<Long>)xmlToList(doubleSort, "long", "count");
ArrayList<Long> doubleTest = (ArrayList<Long>)calculateStat(intDoubleTestStart, "count"); ArrayList<Long> doubleTest = (ArrayList<Long>)calculateStat(intDoubleTestStart, "count");
Collections.sort(doubleTest); Collections.sort(doubleTest);
assertEquals(doubleTest,doub); assertEquals(getRawResponse(), doubleTest,doub);
String stringSort = getFacetXML(response, "sr", "fieldFacets", "string_sd"); Collection<Integer> string = getIntegerList("sr", "fieldFacets", "string_sd", "int", "percentile_20");
Collection<Integer> string = (ArrayList<Integer>)xmlToList(stringSort, "int", "percentile_20");
ArrayList<Integer> stringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_20"); ArrayList<Integer> stringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_20");
Collections.sort(stringTest,Collections.reverseOrder()); Collections.sort(stringTest,Collections.reverseOrder());
assertEquals(stringTest,string); assertEquals(getRawResponse(), stringTest,string);
} }
} }

View File

@ -102,30 +102,26 @@ public class QueryFacetTest extends AbstractAnalyticsFacetTest {
assertU(commit()); assertU(commit());
//Query ascending tests //Query ascending tests
String response = h.query(request(fileToStringArr(fileName))); setResponse(h.query(request(fileToStringArr(fileName))));
//Int One //Int One
String int1Query = getFacetXML(response, "ir", "queryFacets", "float1"); ArrayList<Double> int1 = getDoubleList("ir", "queryFacets", "float1", "double", "sum");
ArrayList<Double> int1 = (ArrayList<Double>)xmlToList(int1Query, "double", "sum");
ArrayList<Double> int1Test = calculateNumberStat(int1TestStart, "sum"); ArrayList<Double> int1Test = calculateNumberStat(int1TestStart, "sum");
assertEquals(int1,int1Test); assertEquals(getRawResponse(), int1, int1Test);
//Int Two //Int Two
String int2Query = getFacetXML(response, "ir", "queryFacets", "float2"); ArrayList<Integer> int2 = getIntegerList("ir", "queryFacets", "float2", "int", "percentile_8");
ArrayList<Integer> int2 = (ArrayList<Integer>)xmlToList(int2Query, "int", "percentile_8");
ArrayList<Integer> int2Test = (ArrayList<Integer>)calculateStat(int2TestStart, "perc_8"); ArrayList<Integer> int2Test = (ArrayList<Integer>)calculateStat(int2TestStart, "perc_8");
assertEquals(int2,int2Test); assertEquals(getRawResponse(), int2, int2Test);
//Long //Long
String long1Query = getFacetXML(response, "lr", "queryFacets", "string"); ArrayList<Double> long1 = getDoubleList("lr", "queryFacets", "string", "double", "median");
ArrayList<Double> long1 = (ArrayList<Double>)xmlToList(long1Query, "double", "median");
ArrayList<Double> long1Test = calculateNumberStat(longTestStart, "median"); ArrayList<Double> long1Test = calculateNumberStat(longTestStart, "median");
assertEquals(long1,long1Test); assertEquals(getRawResponse(),long1,long1Test);
//Float //Float
String float1Query = getFacetXML(response, "fr", "queryFacets", "lad"); ArrayList<Double> float1 = getDoubleList("fr", "queryFacets", "lad", "double", "mean");
ArrayList<Double> float1 = (ArrayList<Double>)xmlToList(float1Query, "double", "mean");
ArrayList<Double> float1Test = calculateNumberStat(floatTestStart, "mean"); ArrayList<Double> float1Test = calculateNumberStat(floatTestStart, "mean");
assertEquals(float1,float1Test); assertEquals(getRawResponse(), float1, float1Test);
} }
} }

View File

@ -47,8 +47,6 @@ public class RangeFacetTest extends AbstractAnalyticsFacetTest {
static ArrayList<ArrayList<Float>> floatDoubleTestStart; static ArrayList<ArrayList<Float>> floatDoubleTestStart;
static ArrayList<ArrayList<Float>> floatDateTestStart; static ArrayList<ArrayList<Float>> floatDateTestStart;
static String response;
@BeforeClass @BeforeClass
public static void beforeClass() throws Exception { public static void beforeClass() throws Exception {
initCore("solrconfig-basic.xml","schema-analytics.xml"); initCore("solrconfig-basic.xml","schema-analytics.xml");
@ -117,7 +115,7 @@ public class RangeFacetTest extends AbstractAnalyticsFacetTest {
assertU(commit()); assertU(commit());
response = h.query(request(fileToStringArr(fileName))); setResponse(h.query(request(fileToStringArr(fileName))));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -125,42 +123,36 @@ public class RangeFacetTest extends AbstractAnalyticsFacetTest {
public void rangeTest() throws Exception { public void rangeTest() throws Exception {
//Int Long //Int Long
String intLongRange = getFacetXML(response, "ri", "rangeFacets", "long_ld"); ArrayList<Long> intLong = getLongList("ri", "rangeFacets", "long_ld", "long", "count");
ArrayList<Double> intLong = (ArrayList<Double>)xmlToList(intLongRange, "long", "count");
ArrayList<Long> intLongTest = calculateStat(transformLists(intLongTestStart, 5, 30, 5 ArrayList<Long> intLongTest = calculateStat(transformLists(intLongTestStart, 5, 30, 5
, false, true, false, false, false), "count"); , false, true, false, false, false), "count");
assertEquals(intLong,intLongTest); assertEquals(getRawResponse(), intLong,intLongTest);
//Int Double //Int Double
String intDoubleRange = getFacetXML(response, "ri", "rangeFacets", "double_dd"); ArrayList<Double> intDouble = getDoubleList("ri", "rangeFacets", "double_dd", "double", "mean");
ArrayList<Double> intDouble = (ArrayList<Double>)xmlToList(intDoubleRange, "double", "mean");
ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7 ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7
, false, false, true, false, true), "mean"); , false, false, true, false, true), "mean");
assertEquals(intDouble,intDoubleTest); assertEquals(getRawResponse(), intDouble,intDoubleTest);
//Int Date //Int Date
String intDateRange = getFacetXML(response, "ri", "rangeFacets", "date_dtd"); ArrayList<Long> intDate = getLongList("ri", "rangeFacets", "date_dtd", "long", "count");
ArrayList<Long> intDate = (ArrayList<Long>)xmlToList(intDateRange, "long", "count");
ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7 ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7
, false, true, false, true, true), "count"); , false, true, false, true, true), "count");
assertEquals(intDate,intDateTest); assertEquals(getRawResponse(), intDate,intDateTest);
//Float Long //Float Long
String floatLongRange = getFacetXML(response, "rf", "rangeFacets", "long_ld"); ArrayList<Double> floatLong = getDoubleList("rf", "rangeFacets", "long_ld", "double", "median");
ArrayList<Double> floatLong = (ArrayList<Double>)xmlToList(floatLongRange, "double", "median");
ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4 ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4
, false, true, true, true, true), "median"); , false, true, true, true, true), "median");
assertEquals(floatLong,floatLongTest); assertEquals(getRawResponse(), floatLong,floatLongTest);
//Float Double //Float Double
String floatDoubleRange = getFacetXML(response, "rf", "rangeFacets", "double_dd"); ArrayList<Long> floatDouble = getLongList("rf", "rangeFacets", "double_dd", "long", "count");
ArrayList<Long> floatDouble = (ArrayList<Long>)xmlToList(floatDoubleRange, "long", "count");
ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11 ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11
, false, false, false, true, false), "count"); , false, false, false, true, false), "count");
assertEquals(floatDouble,floatDoubleTest); assertEquals(getRawResponse(), floatDouble,floatDoubleTest);
//Float Date //Float Date
String floatDateRange = getFacetXML(response, "rf", "rangeFacets", "date_dtd"); ArrayList<Double> floatDate = getDoubleList("rf", "rangeFacets", "date_dtd", "double", "sumOfSquares");
ArrayList<Double> floatDate = (ArrayList<Double>)xmlToList(floatDateRange, "double", "sumOfSquares");
ArrayList<Double> floatDateTest = calculateNumberStat(transformLists(floatDateTestStart, 4, 46, 5 ArrayList<Double> floatDateTest = calculateNumberStat(transformLists(floatDateTestStart, 4, 46, 5
, false, false, true, true, false), "sumOfSquares"); , false, false, true, true, false), "sumOfSquares");
assertEquals(floatDate,floatDateTest); assertEquals(getRawResponse(), floatDate,floatDateTest);
} }
@ -168,84 +160,72 @@ public class RangeFacetTest extends AbstractAnalyticsFacetTest {
@Test @Test
public void hardendRangeTest() throws Exception { public void hardendRangeTest() throws Exception {
//Int Long //Int Long
String intLongRange = getFacetXML(response, "hi", "rangeFacets", "long_ld"); ArrayList<Double> intLong = getDoubleList("hi", "rangeFacets", "long_ld", "double", "sum");
ArrayList<Double> intLong = (ArrayList<Double>)xmlToList(intLongRange, "double", "sum");
ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, 5 ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, 5
, true, true, false, false, false), "sum"); , true, true, false, false, false), "sum");
assertEquals(intLong,intLongTest); assertEquals(getRawResponse(), intLong,intLongTest);
//Int Double //Int Double
String intDoubleRange = getFacetXML(response, "hi", "rangeFacets", "double_dd"); ArrayList<Double> intDouble = getDoubleList("hi", "rangeFacets", "double_dd", "double", "mean");
ArrayList<Double> intDouble = (ArrayList<Double>)xmlToList(intDoubleRange, "double", "mean");
ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7 ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7
, true, false, true, false, true), "mean"); , true, false, true, false, true), "mean");
assertEquals(intDouble,intDoubleTest); assertEquals(getRawResponse(), intDouble,intDoubleTest);
//Int Date //Int Date
String intDateRange = getFacetXML(response, "hi", "rangeFacets", "date_dtd"); ArrayList<Long> intDate = getLongList("hi", "rangeFacets", "date_dtd", "long", "count");
ArrayList<Long> intDate = (ArrayList<Long>)xmlToList(intDateRange, "long", "count");
ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7 ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7
, true, true, false, true, true), "count"); , true, true, false, true, true), "count");
assertEquals(intDate,intDateTest); assertEquals(getRawResponse(), intDate,intDateTest);
//Float Long //Float Long
String floatLongRange = getFacetXML(response, "hf", "rangeFacets", "long_ld"); ArrayList<Double> floatLong = getDoubleList("hf", "rangeFacets", "long_ld", "double", "median");
ArrayList<Double> floatLong = (ArrayList<Double>)xmlToList(floatLongRange, "double", "median");
ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4 ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4
, true, true, true, true, true), "median"); , true, true, true, true, true), "median");
assertEquals(floatLong,floatLongTest); assertEquals(getRawResponse(), floatLong,floatLongTest);
//Float Double //Float Double
String floatDoubleRange = getFacetXML(response, "hf", "rangeFacets", "double_dd"); ArrayList<Long> floatDouble = getLongList("hf", "rangeFacets", "double_dd", "long", "count");
ArrayList<Long> floatDouble = (ArrayList<Long>)xmlToList(floatDoubleRange, "long", "count");
ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11 ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11
, true, false, false, true, false), "count"); , true, false, false, true, false), "count");
assertEquals(floatDouble,floatDoubleTest); assertEquals(getRawResponse(), floatDouble,floatDoubleTest);
//Float Date //Float Date
String floatDateRange = getFacetXML(response, "hf", "rangeFacets", "date_dtd"); ArrayList<Double> floatDate = getDoubleList("hf", "rangeFacets", "date_dtd", "double", "sumOfSquares");
ArrayList<Double> floatDate = (ArrayList<Double>)xmlToList(floatDateRange, "double", "sumOfSquares");
ArrayList<Double> floatDateTest = calculateNumberStat(transformLists(floatDateTestStart, 4, 46, 5 ArrayList<Double> floatDateTest = calculateNumberStat(transformLists(floatDateTestStart, 4, 46, 5
, true, false, true, true, false), "sumOfSquares"); , true, false, true, true, false), "sumOfSquares");
assertEquals(floatDate,floatDateTest); assertEquals(getRawResponse(), floatDate,floatDateTest);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void multiGapTest() throws Exception { public void multiGapTest() throws Exception {
//Int Long //Int Long
String intLongRange = getFacetXML(response, "mi", "rangeFacets", "long_ld"); ArrayList<Double> intLong = getDoubleList("mi", "rangeFacets", "long_ld", "double", "sum");
ArrayList<Double> intLong = (ArrayList<Double>)xmlToList(intLongRange, "double", "sum");
ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, "4,2,6,3" ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, "4,2,6,3"
, false, true, false, false, false), "sum"); , false, true, false, false, false), "sum");
assertEquals(intLong,intLongTest); assertEquals(getRawResponse(), intLong,intLongTest);
//Int Double //Int Double
String intDoubleRange = getFacetXML(response, "mi", "rangeFacets", "double_dd"); ArrayList<Double> intDouble = getDoubleList("mi", "rangeFacets", "double_dd", "double", "mean");
ArrayList<Double> intDouble = (ArrayList<Double>)xmlToList(intDoubleRange, "double", "mean");
ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, "3,1,7" ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, "3,1,7"
, false, false, true, false, true), "mean"); , false, false, true, false, true), "mean");
assertEquals(intDouble,intDoubleTest); assertEquals(getRawResponse(), intDouble,intDoubleTest);
//Int Date //Int Date
String intDateRange = getFacetXML(response, "mi", "rangeFacets", "date_dtd"); ArrayList<Long> intDate = getLongList("mi", "rangeFacets", "date_dtd", "long", "count");
ArrayList<Long> intDate = (ArrayList<Long>)xmlToList(intDateRange, "long", "count");
ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, "2,7" ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, "2,7"
, false, true, false, true, true), "count"); , false, true, false, true, true), "count");
assertEquals(intDate,intDateTest); assertEquals(getRawResponse(), intDate,intDateTest);
//Float Long //Float Long
String floatLongRange = getFacetXML(response, "mf", "rangeFacets", "long_ld"); ArrayList<Double> floatLong = getDoubleList("mf", "rangeFacets", "long_ld", "double", "median");
ArrayList<Double> floatLong = (ArrayList<Double>)xmlToList(floatLongRange, "double", "median");
ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, "1,4" ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, "1,4"
, false, true, true, true, true), "median");; , false, true, true, true, true), "median");;
assertEquals(floatLong,floatLongTest); assertEquals(getRawResponse(), floatLong,floatLongTest);
//Float Double //Float Double
String floatDoubleRange = getFacetXML(response, "mf", "rangeFacets", "double_dd"); ArrayList<Long> floatDouble = getLongList("mf", "rangeFacets", "double_dd", "long", "count");
ArrayList<Long> floatDouble = (ArrayList<Long>)xmlToList(floatDoubleRange, "long", "count");
ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, "2,3,11" ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, "2,3,11"
, false, false, false, true, false), "count"); , false, false, false, true, false), "count");
assertEquals(floatDouble,floatDoubleTest); assertEquals(getRawResponse(), floatDouble,floatDoubleTest);
//Float Date //Float Date
String floatDateRange = getFacetXML(response, "mf", "rangeFacets", "date_dtd"); ArrayList<Double> floatDate = getDoubleList("mf", "rangeFacets", "date_dtd", "double", "sumOfSquares");
ArrayList<Double> floatDate = (ArrayList<Double>)xmlToList(floatDateRange, "double", "sumOfSquares");
ArrayList<Double> floatDateTest = calculateNumberStat(transformLists(floatDateTestStart, 4, 46, "4,5" ArrayList<Double> floatDateTest = calculateNumberStat(transformLists(floatDateTestStart, 4, 46, "4,5"
, false, false, true, true, false), "sumOfSquares"); , false, false, true, true, false), "sumOfSquares");
assertEquals(floatDate,floatDateTest); assertEquals(getRawResponse(), floatDate,floatDateTest);
} }
private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, int gap private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, int gap