Search in sources :

Example 21 with FileConnection

use of org.teiid.translator.FileConnection in project teiid by teiid.

the class TestExcelExecution method testExecutionLimit.

@Test
public void testExecutionLimit() throws Exception {
    FileConnection connection = Mockito.mock(FileConnection.class);
    Mockito.stub(connection.getFile("names.xls")).toReturn(UnitTestUtil.getTestDataFile("names.xls"));
    ArrayList results = helpExecute(commonDDL, connection, "select FirstName from Sheet1 LIMIT 3,1");
    assertEquals("[[Sarah]]", results.toString());
}
Also used : ArrayList(java.util.ArrayList) FileConnection(org.teiid.translator.FileConnection) Test(org.junit.Test)

Example 22 with FileConnection

use of org.teiid.translator.FileConnection in project teiid by teiid.

the class TestExcelExecution method testExecutionNoFile.

@Test(expected = TranslatorException.class)
public void testExecutionNoFile() throws Exception {
    FileConnection connection = Mockito.mock(FileConnection.class);
    Mockito.stub(connection.getFile("names.xls")).toReturn(new File("does not exist"));
    helpExecute(commonDDL, connection, "select FirstName from Sheet1 WHERE ROW_ID != 16");
}
Also used : File(java.io.File) FileConnection(org.teiid.translator.FileConnection) Test(org.junit.Test)

Example 23 with FileConnection

use of org.teiid.translator.FileConnection in project teiid by teiid.

the class TestExcelExecution method testExecutionColumnsWithNullCell.

@Test
public void testExecutionColumnsWithNullCell() throws Exception {
    String ddl = "CREATE FOREIGN TABLE Sheet1 (\n" + "	column1 string OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '1'),\n" + "	column2 string OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '2')\n" + ") OPTIONS (\"teiid_excel:FILE\" '3219.xlsx');";
    FileConnection connection = Mockito.mock(FileConnection.class);
    Mockito.stub(connection.getFile("3219.xlsx")).toReturn(UnitTestUtil.getTestDataFile("3219.xlsx"));
    ArrayList results = helpExecute(ddl, connection, "select * from Sheet1");
    assertEquals(results.size(), 7);
}
Also used : ArrayList(java.util.ArrayList) FileConnection(org.teiid.translator.FileConnection) Test(org.junit.Test)

Example 24 with FileConnection

use of org.teiid.translator.FileConnection in project teiid by teiid.

the class TestExcelExecution method testExecutionWithDataNumberXLS.

@Test
public void testExecutionWithDataNumberXLS() throws Exception {
    String ddl = "CREATE FOREIGN TABLE Sheet1 (\n" + "	ROW_ID integer OPTIONS (SEARCHABLE 'All_Except_Like', \"teiid_excel:CELL_NUMBER\" 'ROW_ID'),\n" + "	column1 string OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '7'),\n" + "	column2 string OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '8'),\n" + "	column3 string OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '9'),\n" + "	CONSTRAINT PK0 PRIMARY KEY(ROW_ID)\n" + ") OPTIONS (\"teiid_excel:FILE\" 'names.xls', \"teiid_excel:FIRST_DATA_ROW_NUMBER\" '18');";
    FileConnection connection = Mockito.mock(FileConnection.class);
    Mockito.stub(connection.getFile("names.xls")).toReturn(UnitTestUtil.getTestDataFile("names.xls"));
    ArrayList results = helpExecute(ddl, connection, "select * from Sheet1");
    assertEquals("[[18, Rocky, Dog, 3.0], [19, Total, null, 110.0]]", results.toString());
    results = helpExecute(ddl, connection, "select * from Sheet1", true);
    assertEquals("[[18, Rocky, Dog, 3], [19, Total, null, 110]]", results.toString());
}
Also used : ArrayList(java.util.ArrayList) FileConnection(org.teiid.translator.FileConnection) Test(org.junit.Test)

Example 25 with FileConnection

use of org.teiid.translator.FileConnection in project teiid by teiid.

the class TestExcelExecution method testExecutionWithDataNumberXLSX.

@Test
public void testExecutionWithDataNumberXLSX() throws Exception {
    String ddl = "CREATE FOREIGN TABLE Sheet1 (\n" + "	ROW_ID integer OPTIONS (SEARCHABLE 'All_Except_Like', \"teiid_excel:CELL_NUMBER\" 'ROW_ID'),\n" + "	column1 string OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '1'),\n" + "	column2 string OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '2'),\n" + "	column3 string OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '3'),\n" + "	CONSTRAINT PK0 PRIMARY KEY(ROW_ID)\n" + ") OPTIONS (\"teiid_excel:FILE\" 'names.xlsx', \"teiid_excel:FIRST_DATA_ROW_NUMBER\" '6');";
    FileConnection connection = Mockito.mock(FileConnection.class);
    Mockito.stub(connection.getFile("names.xlsx")).toReturn(UnitTestUtil.getTestDataFile("names.xlsx"));
    ArrayList results = helpExecute(ddl, connection, "select * from Sheet1");
    assertEquals("[[6, Rocky, Dog, 3.0]]", results.toString());
}
Also used : ArrayList(java.util.ArrayList) FileConnection(org.teiid.translator.FileConnection) Test(org.junit.Test)

Aggregations

FileConnection (org.teiid.translator.FileConnection)27 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)21 File (java.io.File)6 BasicConnectionFactory (org.teiid.resource.spi.BasicConnectionFactory)3 MetadataFactory (org.teiid.metadata.MetadataFactory)2 ProcedureExecution (org.teiid.translator.ProcedureExecution)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Blob (java.sql.Blob)1 Clob (java.sql.Clob)1 SQLException (java.sql.SQLException)1 SQLXML (java.sql.SQLXML)1 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 Properties (java.util.Properties)1 ResourceException (javax.resource.ResourceException)1 VirtualFile (org.jboss.vfs.VirtualFile)1 ReaderInputStream (org.teiid.core.util.ReaderInputStream)1 VirtualFileConnection (org.teiid.file.VirtualFileConnection)1