Search in sources :

Example 1 with ColumnInfo

use of org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo in project data-access by pentaho.

the class CsvUtilsTest method ColumnOfIntegerType_HasCorrectLength.

@Test
public void ColumnOfIntegerType_HasCorrectLength() {
    ColumnInfo columnInfo = new ColumnInfo();
    List<String> data = asList("1", "2");
    utils.assumeColumnDetails(columnInfo, data);
    assertEquals(DataType.NUMERIC, columnInfo.getDataType());
    assertEquals(DEFAULT_INTEGER_SIZE, columnInfo.getLength());
}
Also used : ColumnInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo) Test(org.junit.Test)

Example 2 with ColumnInfo

use of org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo in project data-access by pentaho.

the class CsvUtilsTest method generateFields_EscapesColumnsNames.

@Test
public void generateFields_EscapesColumnsNames() throws Exception {
    String[] headers = { "col.1", "col  2 */+" };
    for (String header : headers) {
        assertFalse(Util.validateId(header));
    }
    prepareFile(headers);
    ColumnInfo[] columns = generateFields(1, null, 1).getColumns();
    for (int i = 0; i < columns.length; i++) {
        ColumnInfo column = columns[i];
        assertEquals("Keeps original title", headers[i], column.getTitle());
        assertTrue("Escapes id", Util.validateId(column.getId()));
    }
}
Also used : ColumnInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo) Test(org.junit.Test)

Example 3 with ColumnInfo

use of org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo in project data-access by pentaho.

the class CsvUtilsTest method setUp.

@Before
public void setUp() throws Exception {
    defaultLocale = Locale.getDefault();
    Locale.setDefault(new Locale("en", "US"));
    utils = new CsvUtils();
    columnInfo = new ColumnInfo();
    tempFile = File.createTempFile("CsvUtilsTest", ".tmp");
    tempFile.deleteOnExit();
}
Also used : Locale(java.util.Locale) ColumnInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo) Before(org.junit.Before)

Example 4 with ColumnInfo

use of org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo in project data-access by pentaho.

the class CsvUtilsTest method generateFields_OneHeaderLine_OneDataLine.

@Test
public void generateFields_OneHeaderLine_OneDataLine() throws Exception {
    prepareFile(new String[] { "col1", "col2" }, new String[] { "1", "2" });
    ModelInfo info = generateFields(2, null, 1);
    ColumnInfo[] columns = info.getColumns();
    assertEquals(2, columns.length);
    assertEquals("col1", columns[0].getId());
    assertEquals("col2", columns[1].getId());
    DataRow[] data = info.getData();
    assertEquals(1, data.length);
    assertEquals(2, data[0].getCells().length);
    assertEquals("1", data[0].getCells()[0]);
    assertEquals("2", data[0].getCells()[1]);
}
Also used : ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo) ColumnInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo) DataRow(org.pentaho.platform.dataaccess.datasource.wizard.models.DataRow) Test(org.junit.Test)

Example 5 with ColumnInfo

use of org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo in project data-access by pentaho.

the class ModelerServiceIT method columnsConvertedCorrectly_FromColumnInfos.

@Test
public void columnsConvertedCorrectly_FromColumnInfos() throws Exception {
    final String columnId = "id";
    final String columnTitle = "title";
    ColumnInfo[] columnInfos = new ColumnInfo[] { createColumnInfo(columnId, columnTitle) };
    Column[] columns = modelerService.toColumns(columnInfos);
    assertEquals(1, columns.length);
    Column column = columns[0];
    assertEquals(columnId, column.getId());
    assertEquals(columnTitle, column.getName());
}
Also used : Column(org.pentaho.metadata.model.thin.Column) ColumnInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

ColumnInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo)16 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 StepMeta (org.pentaho.di.trans.step.StepMeta)3 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)3 List (java.util.List)2 CalculatorMetaFunction (org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction)2 Column (org.pentaho.metadata.model.thin.Column)2 CsvFileInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.CsvFileInfo)2 DataRow (org.pentaho.platform.dataaccess.datasource.wizard.models.DataRow)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 DecimalFormat (java.text.DecimalFormat)1 Locale (java.util.Locale)1 Vector (java.util.Vector)1 Before (org.junit.Before)1