Search in sources :

Example 1 with XQConnection

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");
    }
}
Also used : StaticQueryContext(net.sf.saxon.query.StaticQueryContext) XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection) XPathException(net.sf.saxon.trans.XPathException) ILogger(org.pentaho.platform.api.engine.ILogger) Properties(java.util.Properties) XPathException(net.sf.saxon.trans.XPathException)

Example 2 with XQConnection

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);
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection) XQResultSet(org.pentaho.platform.plugin.services.connections.xquery.XQResultSet)

Example 3 with XQConnection

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");
    }
}
Also used : XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection) XPathException(net.sf.saxon.trans.XPathException)

Example 4 with XQConnection

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);
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection) XQResultSet(org.pentaho.platform.plugin.services.connections.xquery.XQResultSet) IPeekable(org.pentaho.commons.connection.IPeekable)

Example 5 with XQConnection

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));
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection)

Aggregations

XQConnection (org.pentaho.platform.plugin.services.connections.xquery.XQConnection)10 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)8 XPathException (net.sf.saxon.trans.XPathException)4 XQResultSet (org.pentaho.platform.plugin.services.connections.xquery.XQResultSet)3 StaticQueryContext (net.sf.saxon.query.StaticQueryContext)2 Properties (java.util.Properties)1 IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)1 XQueryAction (org.pentaho.actionsequence.dom.actions.XQueryAction)1 IPeekable (org.pentaho.commons.connection.IPeekable)1 ILogger (org.pentaho.platform.api.engine.ILogger)1