Search in sources :

Example 1 with MarshallableColumnNames

use of org.pentaho.commons.connection.marshal.MarshallableColumnNames in project pentaho-platform by pentaho.

the class ResultSetTest method validate.

private void validate(MarshallableResultSet result) {
    MarshallableColumnNames colNames = result.getColumnNames();
    assertNotNull(colNames);
    String[] cols = colNames.getColumnName();
    assertNotNull(cols);
    assertEquals(2, cols.length);
    assertEquals("col1", cols[0]);
    assertEquals("col2", cols[1]);
    MarshallableColumnTypes colTypes = result.getColumnTypes();
    assertNotNull(colTypes);
    String[] types = colTypes.getColumnType();
    assertNotNull(types);
    assertEquals(2, types.length);
    assertEquals("string", types[0]);
    assertEquals("integer", types[1]);
    MarshallableRow[] rows = result.getRows();
    assertNotNull(rows);
    assertEquals(3, rows.length);
    MarshallableRow row = rows[0];
    assertNotNull(row);
    String[] cells = row.getCell();
    assertEquals(2, cells.length);
    assertEquals("a", cells[0]);
    assertEquals("1", cells[1]);
    row = rows[1];
    assertNotNull(row);
    cells = row.getCell();
    assertEquals(2, cells.length);
    assertEquals("b", cells[0]);
    assertEquals("2", cells[1]);
    row = rows[2];
    assertNotNull(row);
    cells = row.getCell();
    assertEquals(2, cells.length);
    assertEquals("c", cells[0]);
    assertEquals("3", cells[1]);
}
Also used : MarshallableRow(org.pentaho.commons.connection.marshal.MarshallableRow) MarshallableColumnNames(org.pentaho.commons.connection.marshal.MarshallableColumnNames) MarshallableColumnTypes(org.pentaho.commons.connection.marshal.MarshallableColumnTypes)

Example 2 with MarshallableColumnNames

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

the class MetadataServiceTest method testDoQuery.

@Test
public void testDoQuery() {
    when(metadataService.doQuery(any(Query.class), anyInt())).thenCallRealMethod();
    when(metadataService.doXmlQuery(anyString(), any(Integer.class))).thenCallRealMethod();
    when(metadataServiceUtil.convertQuery(any(Query.class))).thenCallRealMethod();
    when(metadataServiceUtil.getCategory(anyString(), any(LogicalModel.class))).thenCallRealMethod();
    MarshallableResultSet marshallableResultSet = getMarshallableResultSet();
    when(metadataService.getMarshallableResultSet()).thenReturn(marshallableResultSet);
    Query query = buildQuery();
    MarshallableResultSet marshallableResultSetReturned = metadataService.doQuery(query, 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 : LogicalModel(org.pentaho.metadata.model.LogicalModel) MarshallableResultSet(org.pentaho.commons.connection.marshal.MarshallableResultSet) MarshallableRow(org.pentaho.commons.connection.marshal.MarshallableRow) Query(org.pentaho.platform.dataaccess.metadata.model.impl.Query) 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 3 with MarshallableColumnNames

use of org.pentaho.commons.connection.marshal.MarshallableColumnNames 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)

Aggregations

MarshallableColumnNames (org.pentaho.commons.connection.marshal.MarshallableColumnNames)3 MarshallableRow (org.pentaho.commons.connection.marshal.MarshallableRow)3 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 MarshallableResultSet (org.pentaho.commons.connection.marshal.MarshallableResultSet)2 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)2 MarshallableColumnTypes (org.pentaho.commons.connection.marshal.MarshallableColumnTypes)1 LogicalModel (org.pentaho.metadata.model.LogicalModel)1 Query (org.pentaho.platform.dataaccess.metadata.model.impl.Query)1