use of org.teiid.translator.google.api.GoogleSpreadsheetConnection in project teiid by teiid.
the class TestMetadataProcessor method testRemoveColumns.
@Test
public void testRemoveColumns() throws Exception {
GoogleSpreadsheetConnection conn = Mockito.mock(GoogleSpreadsheetConnection.class);
SpreadsheetInfo people = new SpreadsheetInfo("People");
Worksheet worksheet = people.createWorksheet("PeopleList");
worksheet.setHeaderEnabled(true);
for (int i = 1; i <= 3; i++) {
Column newCol = new Column();
newCol.setAlphaName(Util.convertColumnIDtoString(i));
newCol.setLabel("c" + i);
if (i == 1) {
newCol.setDataType(SpreadsheetColumnType.DATETIME);
}
worksheet.addColumn(newCol.getAlphaName(), newCol);
}
Column newCol = new Column();
newCol.setAlphaName("empty");
worksheet.addColumn(null, newCol);
Mockito.stub(conn.getSpreadsheetInfo()).toReturn(people);
MetadataFactory factory = new MetadataFactory("", 1, "", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), "");
GoogleMetadataProcessor processor = new GoogleMetadataProcessor();
processor.process(factory, conn);
Table t = factory.getSchema().getTables().get("PeopleList");
assertTrue(t.supportsUpdate());
assertEquals(3, t.getColumns().size());
assertTrue(t.getColumns().get(0).isUpdatable());
processor.setAllTypesUpdatable(false);
factory = new MetadataFactory("", 1, "", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), "");
processor.process(factory, conn);
t = factory.getSchema().getTables().get("PeopleList");
assertFalse(t.getColumns().get(0).isUpdatable());
}
use of org.teiid.translator.google.api.GoogleSpreadsheetConnection in project teiid by teiid.
the class TestNativeSpreadsheet method testDirect.
@Test
public void testDirect() throws TranslatorException {
SpreadsheetExecutionFactory sef = new SpreadsheetExecutionFactory();
sef.setSupportsDirectQueryProcedure(true);
String input = "call native('worksheet=x;query=$1 foo;limit=2', 'a')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
GoogleSpreadsheetConnection connection = Mockito.mock(GoogleSpreadsheetConnection.class);
RowsResult result = Mockito.mock(RowsResult.class);
Mockito.stub(result.iterator()).toReturn(Arrays.asList(new SheetRow()).iterator());
Mockito.stub(connection.executeQuery("x", "'a' foo", null, 2, 0)).toReturn(result);
ResultSetExecution execution = (ResultSetExecution) sef.createExecution(command, ec, rm, connection);
execution.execute();
List<?> vals = execution.next();
assertTrue(vals.get(0) instanceof Object[]);
}
use of org.teiid.translator.google.api.GoogleSpreadsheetConnection in project teiid by teiid.
the class TestSQLtoSpreadsheetQuery method dummySpreadsheetMetadata.
private QueryMetadataInterface dummySpreadsheetMetadata() throws Exception {
GoogleSpreadsheetConnection conn = Mockito.mock(GoogleSpreadsheetConnection.class);
Mockito.stub(conn.getSpreadsheetInfo()).toReturn(people);
MetadataFactory factory = new MetadataFactory("", 1, "", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), "");
GoogleMetadataProcessor processor = new GoogleMetadataProcessor();
processor.process(factory, conn);
return new TransformationMetadata(null, new CompositeMetadataStore(factory.asMetadataStore()), null, RealMetadataFactory.SFM.getSystemFunctions(), null);
}
use of org.teiid.translator.google.api.GoogleSpreadsheetConnection in project teiid by teiid.
the class TestSQLtoSpreadsheetQuery method testInsertExecution.
@Test
public void testInsertExecution() throws Exception {
String sql = "insert into PeopleList(A,B,C) values ('String,String', 'val', 15.5)";
Insert insert = (Insert) getCommand(sql);
GoogleSpreadsheetConnection gsc = Mockito.mock(GoogleSpreadsheetConnection.class);
Mockito.stub(gsc.getSpreadsheetInfo()).toReturn(people);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
SpreadsheetUpdateExecution sue = new SpreadsheetUpdateExecution(insert, gsc, ec, rm);
sue.execute();
LinkedHashMap<String, Object> vals = new LinkedHashMap<String, Object>();
vals.put("A", "String,String");
vals.put("B", "val");
vals.put("C", 15.5);
Mockito.verify(gsc).executeRowInsert("PeopleList", vals);
}
Aggregations