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));
}
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();
}
}
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;
}
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;
}
Aggregations