Search in sources :

Example 6 with MarshallableResultSet

use of org.pentaho.commons.connection.marshal.MarshallableResultSet in project data-access by pentaho.

the class MetadataServiceTest method testDoXmlQuery.

@Test
public void testDoXmlQuery() {
    String xmlQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><mql><domain_id>" + DOMAIN_ID + "</domain_id><model_id" + ">" + LOGICAL_MODEL_ID + "</model_id><options><disable_distinct>false</disable_distinct><limit>-1</limit></options" + "><parameters><parameter defaultValue=\"" + VALUE + "\" name=\"" + COLUMN_NAME + "\" " + "type=\"STRING\"/></parameters><selections><selection><view>" + CATEGORY_ID + "</view><column>" + COLUMN_ID + "</column" + "><aggregation>NONE</aggregation></selection></selections><constraints><constraint><operator>AND</operator" + "><condition>[" + CATEGORY_NAME + "." + COLUMN_NAME + "] = " + VALUE + "</condition></constraint></constraints><orders/></mql>";
    when(metadataService.doXmlQuery(anyString(), any(Integer.class))).thenCallRealMethod();
    MarshallableResultSet marshallableResultSet = getMarshallableResultSet();
    when(metadataService.getMarshallableResultSet()).thenReturn(marshallableResultSet);
    MarshallableResultSet marshallableResultSetReturned = metadataService.doXmlQuery(xmlQuery, ROWS);
    MarshallableRow[] rows = marshallableResultSetReturned.getRows();
    String[] cell = rows[0].getCell();
    MarshallableColumnNames columnNames = marshallableResultSetReturned.getColumnNames();
    String[] columnName = columnNames.getColumnName();
    // Check the result rows lenght
    Assert.assertTrue(rows.length <= ROWS);
    // Check the result row value
    Assert.assertTrue(cell[0].equals(RESULT));
    // Check the result column name
    Assert.assertTrue(columnName[0].equals(COLUMN_NAME));
}
Also used : MarshallableResultSet(org.pentaho.commons.connection.marshal.MarshallableResultSet) MarshallableRow(org.pentaho.commons.connection.marshal.MarshallableRow) MarshallableColumnNames(org.pentaho.commons.connection.marshal.MarshallableColumnNames) Matchers.anyString(org.mockito.Matchers.anyString) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) Test(org.junit.Test)

Example 7 with MarshallableResultSet

use of org.pentaho.commons.connection.marshal.MarshallableResultSet in project data-access by pentaho.

the class MetadataServiceTest method testDoXmlQueryToCdaJson.

@Test
public void testDoXmlQueryToCdaJson() {
    String expectedQueryJson = "{\"metadata\":[{\"colName\":\"" + COLUMN_NAME + "\",\"colType\":\"" + DataType.STRING + "\",\"colIndex\":0," + "\"colLabel\":\"" + COLUMN_NAME + "\"}],\"resultset\":[[null],[null],[null],[null],[null],[null],[null],[null]," + "[null],[null]]}";
    String xmlQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><mql><domain_id>" + DOMAIN_ID + "</domain_id><model_id" + ">" + LOGICAL_MODEL_ID + "</model_id><options><disable_distinct>false</disable_distinct><limit>-1</limit></options" + "><parameters><parameter defaultValue=\"" + VALUE + "\" name=\"" + COLUMN_NAME + "\" " + "type=\"STRING\"/></parameters><selections><selection><view>" + CATEGORY_ID + "</view><column>" + COLUMN_ID + "</column" + "><aggregation>NONE</aggregation></selection></selections><constraints><constraint><operator>AND</operator" + "><condition>[" + CATEGORY_NAME + "." + COLUMN_NAME + "] = " + VALUE + "</condition></constraint></constraints><orders/></mql>";
    try {
        when(metadataService.doXmlQuery(anyString(), any(Integer.class))).thenCallRealMethod();
        when(metadataService.doXmlQueryToCdaJson(anyString(), anyInt())).thenCallRealMethod();
        when(metadataServiceUtil.createCdaJson(any(IPentahoResultSet.class), anyString())).thenCallRealMethod();
        when(metadataServiceUtil.getDomainObject(anyString())).thenCallRealMethod();
        MarshallableResultSet marshallableResultSet = getMarshallableResultSet();
        when(metadataService.getMarshallableResultSet()).thenReturn(marshallableResultSet);
        String queryJson = metadataService.doXmlQueryToCdaJson(xmlQuery, ROWS);
        Assert.assertEquals(expectedQueryJson, queryJson);
    } catch (Exception ex) {
        fail();
    }
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) MarshallableResultSet(org.pentaho.commons.connection.marshal.MarshallableResultSet) Matchers.anyString(org.mockito.Matchers.anyString) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) Test(org.junit.Test)

Example 8 with MarshallableResultSet

use of org.pentaho.commons.connection.marshal.MarshallableResultSet in project data-access by pentaho.

the class MetadataService method doXmlQueryToJson.

/**
 * Executes a XML query and returns a JSON serialization of the result set
 *
 * @param rowLimit
 * @return
 */
public String doXmlQueryToJson(String xml, int rowLimit) {
    MarshallableResultSet resultSet = doXmlQuery(xml, rowLimit);
    if (resultSet == null) {
        return null;
    }
    JSONSerializer serializer = new JSONSerializer();
    String json = serializer.deepSerialize(resultSet);
    return json;
}
Also used : MarshallableResultSet(org.pentaho.commons.connection.marshal.MarshallableResultSet) JSONSerializer(flexjson.JSONSerializer)

Example 9 with MarshallableResultSet

use of org.pentaho.commons.connection.marshal.MarshallableResultSet in project data-access by pentaho.

the class MetadataServiceTest method getMarshallableResultSet.

private MarshallableResultSet getMarshallableResultSet() {
    // Build the IPentahoResultSet
    Object[][] result = new Object[1][COLUMNS];
    result[0][0] = COLUMN_NAME;
    Object[] values = new Object[1];
    values[0] = RESULT;
    LocalizedString localizedString = mock(LocalizedString.class);
    when(localizedString.getString(anyString())).thenReturn(COLUMN_NAME);
    IPentahoMetaData iPentahoMetaData = mock(IPentahoMetaData.class);
    when(iPentahoMetaData.getColumnHeaders()).thenReturn(result);
    when(iPentahoMetaData.getAttribute(anyInt(), anyInt(), eq(IPhysicalColumn.DATATYPE_PROPERTY))).thenReturn(DataType.STRING);
    when(iPentahoMetaData.getAttribute(anyInt(), anyInt(), eq(Concept.NAME_PROPERTY))).thenReturn(localizedString);
    IPentahoResultSet iPentahoResultSet = mock(IPentahoResultSet.class);
    when(iPentahoResultSet.getRowCount()).thenReturn(ROWS);
    when(iPentahoResultSet.getColumnCount()).thenReturn(COLUMNS);
    when(iPentahoResultSet.getMetaData()).thenReturn(iPentahoMetaData);
    when(iPentahoResultSet.next()).thenReturn(values).thenReturn(null);
    when(metadataService.executeQuery(anyString(), any(Integer.class))).thenReturn(iPentahoResultSet);
    // Build the MarshallableResultSet
    MarshallableResultSet marshallableResultSet = mock(MarshallableResultSet.class);
    doCallRealMethod().when(marshallableResultSet).setResultSet(any(IPentahoResultSet.class));
    when(marshallableResultSet.getRows()).thenCallRealMethod();
    when(marshallableResultSet.getColumnNames()).thenCallRealMethod();
    return marshallableResultSet;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) MarshallableResultSet(org.pentaho.commons.connection.marshal.MarshallableResultSet) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString)

Aggregations

MarshallableResultSet (org.pentaho.commons.connection.marshal.MarshallableResultSet)9 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)5 MarshallableRow (org.pentaho.commons.connection.marshal.MarshallableRow)4 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)4 Test (org.junit.Test)3 Matchers.anyString (org.mockito.Matchers.anyString)3 IPentahoMetaData (org.pentaho.commons.connection.IPentahoMetaData)3 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MarshallableColumnNames (org.pentaho.commons.connection.marshal.MarshallableColumnNames)2 MemoryMetaData (org.pentaho.commons.connection.memory.MemoryMetaData)2 SerializedResultSet (org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet)2 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)2 SQLConnection (org.pentaho.platform.plugin.services.connections.sql.SQLConnection)2 SQLMetaData (org.pentaho.platform.plugin.services.connections.sql.SQLMetaData)2 JSONSerializer (flexjson.JSONSerializer)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ModelerException (org.pentaho.agilebi.modeler.ModelerException)1