use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestSalesForceDirectQueryExecution method testCreate.
@Test
public void testCreate() throws Exception {
String input = "exec native('create;id=pk;type=table;attributes=one,two,three', 'one', 2, 3.0)";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
ArgumentCaptor<DataPayload> payloadArgument = ArgumentCaptor.forClass(DataPayload.class);
Mockito.stub(connection.create(payloadArgument.capture())).toReturn(23);
DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
execution.execute();
Mockito.verify(connection).create(payloadArgument.capture());
assertEquals("pk", payloadArgument.getValue().getID());
assertEquals("table", payloadArgument.getValue().getType());
assertEquals(3, payloadArgument.getValue().getMessageElements().size());
assertArrayEquals(new Object[] { 23 }, (Object[]) execution.next().get(0));
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestSalesForceDirectQueryExecution method testUpdate.
@Test
public void testUpdate() throws Exception {
String input = "exec native('update;id=pk;type=table;attributes=one,two,three', 'one', 2, 3.0)";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
ArgumentCaptor<List> payloadArgument = ArgumentCaptor.forClass(List.class);
Mockito.stub(connection.update(payloadArgument.capture())).toReturn(23);
DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
execution.execute();
Mockito.verify(connection).update(payloadArgument.capture());
assertEquals(1, payloadArgument.getValue().size());
assertEquals("pk", ((DataPayload) payloadArgument.getValue().get(0)).getID());
assertEquals("table", ((DataPayload) payloadArgument.getValue().get(0)).getType());
assertEquals(3, ((DataPayload) payloadArgument.getValue().get(0)).getMessageElements().size());
assertArrayEquals(new Object[] { 23 }, (Object[]) execution.next().get(0));
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestVisitors method helpTest.
private void helpTest(String sql, String expected) throws Exception {
Command command = translationUtility.parseCommand(sql);
SalesForceExecutionFactory factory = new SalesForceExecutionFactory();
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
ArgumentCaptor<String> queryArgument = ArgumentCaptor.forClass(String.class);
QueryResult qr = Mockito.mock(QueryResult.class);
Mockito.stub(connection.query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean())).toReturn(qr);
Execution execution = factory.createExecution(command, ec, rm, connection);
execution.execute();
Mockito.verify(connection, Mockito.times(1)).query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean());
assertEquals(expected, queryArgument.getValue().trim());
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestConnectorWorkItem method testLobs.
@Test
public void testLobs() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
final List<Object> result = Arrays.asList(AutoGenDataService.CLOB_VAL);
final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
return new ResultSetExecution() {
private boolean returned;
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (returned) {
return null;
}
returned = true;
return result;
}
};
}
};
ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector") {
public ExecutionFactory getExecutionFactory() {
return ef;
}
public Object getConnectionFactory() {
return null;
}
};
cm.start();
ef.setCopyLobs(true);
AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
// $NON-NLS-1$
requestMsg.setCommand(helpGetCommand("SELECT CLOB_COLUMN FROM LOB_TESTING_ONE", EXAMPLE_BQT));
requestMsg.setBufferManager(bm);
ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
AtomicResultsMessage message = cwi.more();
List[] resutls = message.getResults();
List<?> tuple = resutls[0];
ClobType clob = (ClobType) tuple.get(0);
assertEquals(StorageMode.MEMORY, InputStreamFactory.getStorageMode(clob));
assertTrue(message.supportsImplicitClose());
result.set(0, AutoGenDataService.CLOB_VAL);
ef.setCopyLobs(false);
cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
message = cwi.more();
resutls = message.getResults();
tuple = resutls[0];
clob = (ClobType) tuple.get(0);
assertEquals(StorageMode.OTHER, InputStreamFactory.getStorageMode(clob));
assertFalse(message.supportsImplicitClose());
result.set(0, new ClobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(new byte[0]);
}
@Override
public StorageMode getStorageMode() {
// TODO: introduce an explicit streaming
return StorageMode.FREE;
}
}, -1));
requestMsg.setCopyStreamingLobs(true);
cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
message = cwi.more();
resutls = message.getResults();
tuple = resutls[0];
clob = (ClobType) tuple.get(0);
// switched from FREE to PERSISTENT
assertEquals(StorageMode.PERSISTENT, InputStreamFactory.getStorageMode(clob));
assertFalse(message.supportsImplicitClose());
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestBaseDelegatingExecutionFactory method testExecution.
@Test
public void testExecution() throws TranslatorException {
BaseDelegatingExecutionFactory<Void, Void> ef = new BaseDelegatingExecutionFactory<Void, Void>() {
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Void connection) throws TranslatorException {
return null;
}
};
ef.setDelegate(new ExecutionFactory<Void, Void>() {
@Override
public Execution createExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Void connection) throws TranslatorException {
throw new AssertionError();
}
});
ef.createExecution(new Select(null, false, null, null, null, null, null), null, null, null);
}
Aggregations