Skip to content

Commit

Permalink
test: added apache-poi/xls tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrugz committed Aug 7, 2023
1 parent 0a75ac9 commit b891eb4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
Expand Down Expand Up @@ -825,6 +828,37 @@ public void testGetXmlEmpFilterNotIn2() throws IOException, ParserConfigurationE
baseReturnCountTest("/EMP.xml?fnin:SALARY=1200&fnin:SALARY=1000", 2);
}

@Test
public void testGetXlsEmp() throws IOException, SAXException {
HttpResponse resp = getHttpResponse("/EMP.xls");
Assert.assertEquals(200, resp.getStatusLine().getStatusCode());

HttpEntity entity1 = resp.getEntity();
InputStream instream = entity1.getContent();

Workbook wb = WorkbookFactory.create(instream);
Sheet sheet = wb.getSheetAt(0);
int lastRow = sheet.getLastRowNum();
//System.out.println(">> lastRow: "+lastRow);
Assert.assertEquals(5, lastRow);
}

@Test
public void testQueryAnyXls() throws IOException, SAXException {
String sql = "select * from emp";
String sqlpar = URLEncoder.encode(sql, utf8);
HttpResponse resp = httpPostContentGetResponse("/QueryAny.xls?name=test&sql="+sqlpar, "");

HttpEntity entity1 = resp.getEntity();
InputStream instream = entity1.getContent();

Workbook wb = WorkbookFactory.create(instream);
Sheet sheet = wb.getSheetAt(0);
int lastRow = sheet.getLastRowNum();
//System.out.println(">> lastRow: "+lastRow);
Assert.assertEquals(5, lastRow);
}

//----- limit-related tests

String getSql30rows() throws UnsupportedEncodingException {
Expand Down Expand Up @@ -2372,6 +2406,7 @@ public void testGetQueryWithBindNamedParametersAndFilter() throws Exception {
content);
}

@SuppressWarnings("unchecked")
public static Object getFieldFromNamedObject(List<Object> data, String objName, String objField) {
for(int i=0;i<data.size();i++) {
Map<String, Object> rel = (Map<String, Object>) data.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ sqldump.datadump.turtle.keyappend=#this
queryon.auth.anon-username=anonymous
queryon.auth.anon-realm=myRealm

queryon.xtrasyntaxes=PoiXlsSyntax, PoiXlsxSyntax

#####

queryon.grabclass=JAXBSchemaXMLSerializer
Expand Down

0 comments on commit b891eb4

Please sign in to comment.