use of org.teiid.language.Command in project teiid by teiid.
the class TestLDAPDirectQueryExecution method testWithoutMarker.
@Test(expected = TranslatorException.class)
public void testWithoutMarker() throws Exception {
String input = "exec native('context-name=corporate;filter=(objectClass=*);count-limit=5;timout=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);
Execution execution = TRANSLATOR.createExecution(command, ec, rm, connection);
assertTrue(!(execution instanceof LDAPDirectSearchQueryExecution));
execution.execute();
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestQueryExecution method testUnwrapExtract.
@Test
public void testUnwrapExtract() throws Exception {
TranslationUtility util = new TranslationUtility(RealMetadataFactory.fromDDL("CREATE FOREIGN TABLE GROUP_PEOPLE (\"member\" string options (\"teiid_ldap:unwrap\" true, \"teiid_ldap:rdn_type\" 'uid', \"teiid_ldap:dn_prefix\" 'ou=users')) 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);
BasicAttributes attributes = new BasicAttributes(true);
BasicAttribute attrib = new BasicAttribute("member");
attributes.put(attrib);
attrib.add("uid=foo,ou=users");
// does not match rdn type
attrib.add("user=bar,ou=users");
// does not dn prefix
attrib.add("uid=bar");
final SearchResult sr = new SearchResult("x", null, attributes);
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);
assertNull(execution.next());
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestMongoDBDirectQueryExecution method testDirect.
@Test
public void testDirect() 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);
AggregationOutput output = Mockito.mock(AggregationOutput.class);
Mockito.stub(output.results()).toReturn(new ArrayList<DBObject>());
Mockito.stub(dbCollection.aggregate(Mockito.any(DBObject.class), Mockito.any(DBObject.class))).toReturn(output);
Argument arg = new Argument(Direction.IN, null, String.class, null);
arg.setArgumentValue(new Literal("MyTable;{$match:{\"id\":\"$1\"}};{$project:{\"_m0\":\"$user\"}}", String.class));
Argument arg2 = new Argument(Direction.IN, null, String.class, null);
arg2.setArgumentValue(new Literal("foo", String.class));
ResultSetExecution execution = this.translator.createDirectExecution(Arrays.asList(arg, arg2), cmd, context, this.utility.createRuntimeMetadata(), connection);
execution.execute();
List<DBObject> pipeline = TestMongoDBQueryExecution.buildArray(new BasicDBObject("$match", new BasicDBObject("id", "foo")), new BasicDBObject("$project", new BasicDBObject("_m0", "$user")));
Mockito.verify(dbCollection).aggregate(Mockito.eq(pipeline), Mockito.any(AggregationOptions.class));
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestSQLConversionVisitor method helpTest.
private void helpTest(String sql, String expected) throws TranslatorException {
Command command = translationUtility.parseCommand(sql);
PhoenixExecutionFactory ef = new PhoenixExecutionFactory();
ef.start();
SQLConversionVisitor vistor = ef.getSQLConversionVisitor();
vistor.append(command);
assertEquals(expected, vistor.toString());
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestSQLConversionVisitor method helpTest.
private void helpTest(String sql, String expected) throws TranslatorException {
Command command = translationUtility.parseCommand(sql);
SQLConversionVisitor vistor = TRANSLATOR.getSQLConversionVisitor();
vistor.append(command);
// System.out.println(vistor.toString());
assertEquals(expected, vistor.toString());
}
Aggregations