Search in sources :

Example 86 with IPentahoResultSet

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

Example 87 with IPentahoResultSet

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

Example 88 with IPentahoResultSet

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();
}
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 89 with IPentahoResultSet

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

Example 90 with IPentahoResultSet

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();
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) HashMap(java.util.HashMap) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent)

Aggregations

IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)113 Test (org.junit.Test)26 Node (org.dom4j.Node)18 ArrayList (java.util.ArrayList)17 IPentahoMetaData (org.pentaho.commons.connection.IPentahoMetaData)12 Iterator (java.util.Iterator)10 List (java.util.List)10 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)10 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)10 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)10 OutputStream (java.io.OutputStream)9 ResultSetCompareAction (org.pentaho.actionsequence.dom.actions.ResultSetCompareAction)8 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)8 XQConnection (org.pentaho.platform.plugin.services.connections.xquery.XQConnection)8 SQLException (java.sql.SQLException)7 HashMap (java.util.HashMap)6 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)6 Map (java.util.Map)5 Set (java.util.Set)5 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)5