use of org.teiid.language.Command in project teiid by teiid.
the class TestLDAPDirectQueryExecution method testSearch.
@Test
public void testSearch() throws Exception {
String input = "exec native('search;context-name=corporate;filter=(objectClass=*);count-limit=5;timeout=6;search-scope=ONELEVEL_SCOPE;attributes=uid,cn')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
LdapContext connection = Mockito.mock(LdapContext.class);
LdapContext ctx = Mockito.mock(LdapContext.class);
Mockito.stub(connection.lookup("corporate")).toReturn(ctx);
LDAPDirectSearchQueryExecution execution = (LDAPDirectSearchQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
execution.execute();
LDAPSearchDetails details = execution.getDelegate().getSearchDetails();
assertEquals("corporate", details.getContextName());
assertEquals("(objectClass=*)", details.getContextFilter());
assertEquals(5, details.getCountLimit());
assertEquals(6, details.getTimeLimit());
assertEquals(1, details.getSearchScope());
assertEquals(2, details.getElementList().size());
assertEquals("uid", details.getElementList().get(0).getName());
assertEquals("cn", details.getElementList().get(1).getName());
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestLDAPDirectQueryExecution method testCreate.
@Test
public void testCreate() throws Exception {
String input = "exec native('create;uid=doe,ou=people,o=teiid.org;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);
LdapContext connection = Mockito.mock(LdapContext.class);
LdapContext ctx = Mockito.mock(LdapContext.class);
Mockito.stub(connection.lookup("")).toReturn(ctx);
LDAPDirectCreateUpdateDeleteQueryExecution execution = (LDAPDirectCreateUpdateDeleteQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
execution.execute();
ArgumentCaptor<String> nameArgument = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<BasicAttributes> createItemArgument = ArgumentCaptor.forClass(BasicAttributes.class);
Mockito.verify(ctx).createSubcontext(nameArgument.capture(), createItemArgument.capture());
assertEquals("uid=doe,ou=people,o=teiid.org", nameArgument.getValue());
assertEquals("one", createItemArgument.getValue().get("one").getID());
assertEquals("one", createItemArgument.getValue().get("one").get());
assertEquals("two", createItemArgument.getValue().get("two").getID());
assertEquals("2", createItemArgument.getValue().get("two").get());
assertEquals("three", createItemArgument.getValue().get("three").getID());
assertEquals("3.0", createItemArgument.getValue().get("three").get());
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestQueryExecution method testUnwrap.
@Test
public void testUnwrap() throws Exception {
TranslationUtility util = new TranslationUtility(RealMetadataFactory.fromDDL("CREATE FOREIGN TABLE GROUP_PEOPLE (objectClass string options (\"teiid_ldap:unwrap\" true)) OPTIONS(nameinsource 'ou=Infrastructure,ou=Support,o=DEMOCORP,c=AU', updatable true);", "x", "y"));
Command command = util.parseCommand("select * from group_people");
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
LdapContext connection = Mockito.mock(LdapContext.class);
LdapContext ctx = Mockito.mock(LdapContext.class);
Mockito.stub(connection.lookup("ou=Infrastructure,ou=Support,o=DEMOCORP,c=AU")).toReturn(ctx);
Attributes attribs = Mockito.mock(Attributes.class);
Attribute attrib = Mockito.mock(Attribute.class);
Mockito.stub(attrib.size()).toReturn(2);
NamingEnumeration attribValues = new SimpleNamingEnumeration(Arrays.asList("foo", "bar").iterator());
Mockito.stub(attrib.getAll()).toReturn(attribValues);
Mockito.stub(attribs.get("objectClass")).toReturn(attrib);
final SearchResult sr = new SearchResult("x", null, attribs);
NamingEnumeration<SearchResult> enumeration = new SimpleNamingEnumeration(Arrays.asList(sr).iterator());
Mockito.stub(ctx.search((String) Mockito.any(), (String) Mockito.any(), (SearchControls) Mockito.any())).toReturn(enumeration);
LDAPExecutionFactory lef = new LDAPExecutionFactory();
lef.start();
LDAPSyncQueryExecution execution = (LDAPSyncQueryExecution) lef.createExecution(command, ec, rm, connection);
execution.execute();
List<?> result = execution.next();
assertEquals(Arrays.asList("foo"), result);
result = execution.next();
assertEquals(Arrays.asList("bar"), result);
assertNull(execution.next());
// missing attribute handling
Mockito.stub(attribs.get("objectClass")).toReturn(null);
enumeration = new SimpleNamingEnumeration(Arrays.asList(sr).iterator());
Mockito.stub(ctx.search((String) Mockito.any(), (String) Mockito.any(), (SearchControls) Mockito.any())).toReturn(enumeration);
execution = (LDAPSyncQueryExecution) lef.createExecution(command, ec, rm, connection);
execution.execute();
result = execution.next();
assertEquals(Collections.singletonList(null), result);
assertNull(execution.next());
// empty attribute handling
attribValues = new SimpleNamingEnumeration(new ArrayList<Object>().iterator());
Mockito.stub(attrib.size()).toReturn(0);
Mockito.stub(attrib.getAll()).toReturn(attribValues);
Mockito.stub(attribs.get("objectClass")).toReturn(attrib);
enumeration = new SimpleNamingEnumeration(Arrays.asList(sr).iterator());
Mockito.stub(ctx.search((String) Mockito.any(), (String) Mockito.any(), (SearchControls) Mockito.any())).toReturn(enumeration);
execution = (LDAPSyncQueryExecution) lef.createExecution(command, ec, rm, connection);
execution.execute();
result = execution.next();
assertEquals(Collections.singletonList(null), result);
assertNull(execution.next());
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestEmbeddedMongoExecution method executeCmd.
private Execution executeCmd(String sql) throws Exception {
Command cmd = utility.parseCommand(sql);
CommandContext cc = Mockito.mock(CommandContext.class);
Mockito.stub(cc.isReturnAutoGeneratedKeys()).toReturn(false);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
Mockito.stub(ec.getCommandContext()).toReturn(cc);
Execution exec = translator.createExecution(cmd, ec, utility.createRuntimeMetadata(), this.connection);
exec.execute();
return exec;
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestMongoDBDirectQueryExecution method testShellDirect.
@Test
public void testShellDirect() throws Exception {
Command cmd = this.utility.parseCommand("SELECT * FROM Customers");
MongoDBConnection connection = Mockito.mock(MongoDBConnection.class);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
DBCollection dbCollection = Mockito.mock(DBCollection.class);
DB db = Mockito.mock(DB.class);
Mockito.stub(db.getCollection("MyTable")).toReturn(dbCollection);
Mockito.stub(db.collectionExists(Mockito.anyString())).toReturn(true);
Mockito.stub(connection.getDatabase()).toReturn(db);
Argument arg = new Argument(Direction.IN, null, String.class, null);
arg.setArgumentValue(new Literal("$ShellCmd;MyTable;remove;{ qty: { $gt: 20 }}", String.class));
ResultSetExecution execution = this.translator.createDirectExecution(Arrays.asList(arg), cmd, context, this.utility.createRuntimeMetadata(), connection);
execution.execute();
Mockito.verify(dbCollection).remove(QueryBuilder.start("qty").greaterThan(20).get());
}
Aggregations