Search in sources :

Example 26 with FileConnection

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

the class TestExcelExecution method testExecutionLimit2.

@Test
public void testExecutionLimit2() 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 1");
    assertEquals("[[John]]", results.toString());
}
Also used : ArrayList(java.util.ArrayList) FileConnection(org.teiid.translator.FileConnection) Test(org.junit.Test)

Example 27 with FileConnection

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

the class TestFileExecutionFactory method testGetTextFiles.

@Test
public void testGetTextFiles() throws Exception {
    FileExecutionFactory fef = new FileExecutionFactory();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "text", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    fef.getMetadata(mf, null);
    Procedure p = mf.getSchema().getProcedure("getTextFiles");
    FileConnection fc = Mockito.mock(FileConnection.class);
    Mockito.stub(fc.getFile("*.txt")).toReturn(new File(UnitTestUtil.getTestDataPath(), "*.txt"));
    Call call = fef.getLanguageFactory().createCall("getTextFiles", Arrays.asList(new Argument(Direction.IN, new Literal("*.txt", TypeFacility.RUNTIME_TYPES.STRING), TypeFacility.RUNTIME_TYPES.STRING, null)), p);
    ProcedureExecution pe = fef.createProcedureExecution(call, null, null, fc);
    pe.execute();
    int count = 0;
    while (true) {
        List<?> val = pe.next();
        if (val == null) {
            break;
        }
        assertEquals(5, val.size());
        assertTrue(val.get(3) instanceof Timestamp);
        assertEquals(Long.valueOf(0), val.get(4));
        count++;
    }
    assertEquals(2, count);
    call = fef.getLanguageFactory().createCall("getTextFiles", Arrays.asList(new Argument(Direction.IN, new Literal("*1*", TypeFacility.RUNTIME_TYPES.STRING), TypeFacility.RUNTIME_TYPES.STRING, null)), p);
    pe = fef.createProcedureExecution(call, null, null, fc);
    Mockito.stub(fc.getFile("*1*")).toReturn(new File(UnitTestUtil.getTestDataPath(), "*1*"));
    pe.execute();
    count = 0;
    while (true) {
        if (pe.next() == null) {
            break;
        }
        count++;
    }
    assertEquals(1, count);
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) MetadataFactory(org.teiid.metadata.MetadataFactory) ProcedureExecution(org.teiid.translator.ProcedureExecution) Literal(org.teiid.language.Literal) Procedure(org.teiid.metadata.Procedure) File(java.io.File) 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