use of org.teiid.language.Command in project teiid by teiid.
the class TestODataSQLVistor method helpUpdateExecute.
private void helpUpdateExecute(String query, String expected, String expectedMethod, boolean checkPayload) throws Exception {
Command cmd = this.utility.parseCommand(query);
ODataUpdateVisitor visitor = new ODataUpdateVisitor(translator, utility.createRuntimeMetadata());
visitor.visitNode(cmd);
if (!visitor.exceptions.isEmpty()) {
throw visitor.exceptions.get(0);
}
String odataCmd = visitor.buildURL();
if (checkPayload) {
assertNotNull(visitor.getPayload());
}
if (printPayload) {
System.out.println(visitor.getPayload());
}
assertEquals(expected, odataCmd);
assertEquals(expectedMethod, visitor.getMethod());
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestMongoDBUpdateVisitor method helpExecute.
private void helpExecute(String query, String collection, String expected, String match, MergeDetails pushKey, List<MergeDetails> pullKeys) throws Exception {
Command cmd = this.utility.parseCommand(query);
MongoDBUpdateVisitor visitor = new MongoDBUpdateVisitor(this.translator, this.utility.createRuntimeMetadata(), Mockito.mock(DB.class));
visitor.visitNode(cmd);
if (!visitor.exceptions.isEmpty()) {
throw visitor.exceptions.get(0);
}
assertEquals(collection, visitor.mongoDoc.getTargetTable().getName());
if (cmd instanceof Insert) {
assertEquals("wrong insert", expected, visitor.getInsert(this.docs).toString());
} else if (cmd instanceof Update) {
assertEquals("wrong update", expected, visitor.getUpdate(this.docs).toString());
} else if (cmd instanceof Delete) {
}
if (visitor.match != null) {
assertEquals("match wrong", match, visitor.match.toString());
}
MongoDocument doc = visitor.mongoDoc;
if (doc.isMerged()) {
assertEquals("Wrong PushKey", pushKey.toString(), visitor.mongoDoc.getMergeKey().toString());
}
if (!visitor.mongoDoc.getEmbeddedReferences().isEmpty()) {
assertEquals("Wrong PullKeys", visitor.mongoDoc.getEmbeddedReferences().toString(), pullKeys.toString());
}
this.docs = null;
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestSalesForceDirectQueryExecution method testCreateFail.
@Test(expected = TranslatorException.class)
public void testCreateFail() throws Exception {
String input = "exec native('create;id=pk;type=table;attributes=one,two,three', 'one')";
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);
DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
execution.execute();
}
use of org.teiid.language.Command 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.language.Command 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));
}
Aggregations