use of org.pentaho.platform.plugin.services.connections.xquery.XQConnection in project pentaho-platform by pentaho.
the class XQueryIT method testXQConnectionConnect.
public void testXQConnectionConnect() {
try {
XQConnection connection = new XQConnection();
ILogger mockLogger = mock(ILogger.class);
connection.setLogger(mockLogger);
Properties properties = null;
boolean isConnected = connection.connect(properties);
assertTrue(isConnected);
properties = new Properties();
isConnected = connection.connect(properties);
assertTrue(isConnected);
properties.setProperty(IPentahoConnection.QUERY_KEY, StringUtils.EMPTY);
isConnected = connection.connect(properties);
assertTrue(isConnected);
properties.setProperty(IPentahoConnection.QUERY_KEY, TEST_QUERY);
isConnected = connection.connect(properties);
assertTrue(isConnected);
StaticQueryContext mockContext = mock(StaticQueryContext.class);
when(mockContext.compileQuery(TEST_QUERY)).thenThrow(new XPathException("Test XPathException"));
connection.sqc = mockContext;
isConnected = connection.connect(properties);
assertFalse(isConnected);
} catch (Exception e) {
e.printStackTrace();
fail("Should not throw Exception");
}
}
use of org.pentaho.platform.plugin.services.connections.xquery.XQConnection in project pentaho-platform by pentaho.
the class XQueryIT method testRowLimit.
public void testRowLimit() throws Exception {
XQConnection connection = new XQConnection();
connection.setMaxRows(2);
IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
assertNotNull("result set is null", data);
assertTrue("result set is wrong type", data instanceof XQResultSet);
assertEquals("row count is wrong", 2, data.getRowCount());
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]);
Object[] row = data.next();
assertEquals("Everyday Italian", row[0]);
assertEquals("Giada De Laurentiis", row[1]);
assertEquals("2005", row[2]);
assertEquals("30.00", row[3]);
row = data.next();
assertEquals("Harry Potter", row[0]);
assertEquals("J K. Rowling", row[1]);
assertEquals("2005", row[2]);
assertEquals("29.99", row[3]);
row = data.next();
assertNull(row);
}
use of org.pentaho.platform.plugin.services.connections.xquery.XQConnection in project pentaho-platform by pentaho.
the class XQueryIT method testXQConnectionExequtePreparedQuery.
public void testXQConnectionExequtePreparedQuery() {
try {
XQConnection connection = new XQConnection();
connection.prepareAndExecuteQuery(TEST_QUERY, ListUtils.EMPTY_LIST);
fail("Should throw UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
// valid
} catch (Exception e) {
fail("Should throw UnsupportedOperationException");
}
}
use of org.pentaho.platform.plugin.services.connections.xquery.XQConnection in project pentaho-platform by pentaho.
the class XQueryIT method testPeek.
public void testPeek() 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);
assertEquals("row count is wrong", 4, data.getRowCount());
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]);
assertTrue("result set is not peekable", data instanceof IPeekable);
IPeekable peekable = (IPeekable) data;
Object[] row = peekable.peek();
assertEquals("Everyday Italian", row[0]);
assertEquals("Giada De Laurentiis", row[1]);
assertEquals("2005", row[2]);
assertEquals("30.00", row[3]);
row = peekable.peek();
assertEquals("Everyday Italian", row[0]);
row = peekable.peek();
assertEquals("Everyday Italian", row[0]);
row = peekable.peek();
assertEquals("Everyday Italian", row[0]);
row = data.next();
assertEquals("Everyday Italian", row[0]);
assertEquals("Giada De Laurentiis", row[1]);
assertEquals("2005", row[2]);
assertEquals("30.00", row[3]);
row = peekable.peek();
assertEquals("Harry Potter", row[0]);
assertEquals("J K. Rowling", row[1]);
assertEquals("2005", row[2]);
assertEquals("29.99", row[3]);
row = peekable.peek();
assertEquals("Harry Potter", row[0]);
assertEquals("J K. Rowling", row[1]);
assertEquals("2005", row[2]);
assertEquals("29.99", row[3]);
row = data.next();
assertEquals("Harry Potter", row[0]);
assertEquals("J K. Rowling", row[1]);
assertEquals("2005", row[2]);
assertEquals("29.99", row[3]);
row = peekable.peek();
assertNotNull(row);
row = data.next();
assertNotNull(row);
row = peekable.peek();
assertNotNull(row);
row = data.next();
assertNotNull(row);
row = peekable.peek();
assertNull(row);
row = data.next();
assertNull(row);
row = peekable.peek();
assertNull(row);
}
use of org.pentaho.platform.plugin.services.connections.xquery.XQConnection in project pentaho-platform by pentaho.
the class XQueryIT method testValueAt.
public void testValueAt() throws Exception {
XQConnection connection = new XQConnection();
IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
assertNotNull("result set is null", data);
assertEquals("2005", data.getValueAt(0, 2));
assertEquals("Everyday Italian", data.getValueAt(0, 0));
assertEquals("J K. Rowling", data.getValueAt(1, 1));
assertEquals("29.99", data.getValueAt(1, 3));
assertNull(data.getValueAt(-1, -1));
assertNull(data.getValueAt(99, 0));
assertNull(data.getValueAt(0, 99));
}
Aggregations