use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class XQueryIT method testExecuteWrongQuery.
public void testExecuteWrongQuery() throws Exception {
try {
XQConnection connection = new XQConnection();
StaticQueryContext mockContext = mock(StaticQueryContext.class);
when(mockContext.compileQuery(TEST_QUERY)).thenThrow(new XPathException("Test XPathException"));
connection.sqc = mockContext;
IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
fail("Should throw XPathException");
} catch (XPathException e) {
// valid
}
}
use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class XQueryIT method testGetDataRow.
public void testGetDataRow() throws Exception {
XQConnection connection = new XQConnection();
IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
assertNotNull("result set is null", data);
Object[] row = data.getDataRow(1);
assertEquals("Harry Potter", row[0]);
assertEquals("J K. Rowling", row[1]);
assertEquals("2005", row[2]);
assertEquals("29.99", row[3]);
row = data.getDataRow(3);
assertEquals("Learning XML", row[0]);
assertEquals("Erik T. Ray", row[1]);
assertEquals("2003", row[2]);
assertEquals("39.95", row[3]);
row = data.getDataRow(99);
assertNull(row);
}
use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class XQueryIT method testExecuteQuery.
public void testExecuteQuery() throws Exception {
XQConnection connection = new XQConnection();
IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
assertNotNull("result set is null", data);
assertTrue("result set is wrong type", data instanceof XQResultSet);
assertFalse("Should not be scrollable", data.isScrollable());
assertEquals("row count is wrong", 4, data.getRowCount());
assertEquals("column count is wrong", 4, data.getColumnCount());
assertEquals("column header is wrong", "title", data.getMetaData().getColumnHeaders()[0][0]);
assertEquals("column header is wrong", "author", data.getMetaData().getColumnHeaders()[0][1]);
assertEquals("column header is wrong", "year", data.getMetaData().getColumnHeaders()[0][2]);
assertEquals("column header is wrong", "price", data.getMetaData().getColumnHeaders()[0][3]);
// these don't do much but they should not cause errors
data.close();
data.closeConnection();
}
use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class XQueryIT method testGetDataColumn.
public void testGetDataColumn() throws Exception {
XQConnection connection = new XQConnection();
IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
assertNotNull("result set is null", data);
Object[] col = data.getDataColumn(2);
assertEquals("row count is wrong", 4, col.length);
assertEquals("2005", col[0]);
assertEquals("2005", col[1]);
assertEquals("2003", col[2]);
assertEquals("2003", col[3]);
col = data.getDataColumn(99);
assertNull(col);
}
use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class IPreparedComponentIT method testIPreparedComponentXQueryPrepareLater.
public void testIPreparedComponentXQueryPrepareLater() {
startTest();
// $NON-NLS-1$
info("Expected: Successful execution with object available");
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IRuntimeContext context = run("/test/ipreparedcomponents/ipreparedcomponent_xquery_preparelater.xaction");
assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
context.getStatus());
// $NON-NLS-1$
IActionParameter rtn1 = context.getOutputParameter("prepared_component");
assertNotNull(rtn1);
IPreparedComponent preparedComponent1 = (IPreparedComponent) rtn1.getValue();
assertNotNull(preparedComponent1);
IPentahoResultSet resultset1 = preparedComponent1.executePrepared(null);
assertTrue(resultset1.getRowCount() >= 1);
Object val1 = resultset1.getValueAt(0, 0);
// $NON-NLS-1$
IActionParameter rtn2 = context.getOutputParameter("second_prepared_component");
assertNotNull(rtn2);
IPreparedComponent preparedComponent2 = (IPreparedComponent) rtn2.getValue();
assertNotNull(preparedComponent2);
HashMap map = new HashMap();
// $NON-NLS-1$ //$NON-NLS-2$
map.put("POSITIONTITLE", "Engineer");
IPentahoResultSet resultset2 = preparedComponent2.executePrepared(map);
assertTrue(resultset2.getRowCount() >= 1);
assertEquals(resultset1.getRowCount(), resultset2.getRowCount());
Object val2 = resultset2.getValueAt(0, 0);
// $NON-NLS-1$
assertEquals("Values from the first and second query should be equal", val1, val2);
finishTest();
}
Aggregations